ABAP is the programming language used in SAP application development. One useful early concept is the internal table: a temporary, in-memory collection of rows that an ABAP program can process. In this guide, you will define the shape of one row, fill a small internal table, and count the rows that need review.

Scope note: This is an original learning example, not SAP software, SAP training material, or an executable system. It uses modern ABAP syntax and an ABAP Cloud-style example context. ABAP syntax availability depends on your system’s release and language version; check your own development environment before reusing code.

1. Picture a row and a table

Imagine a short list of fictional purchase requests:

Request Item Status
PR-1042 Safety helmets In review
PR-1043 Spare filters Approved
PR-1044 Barcode scanners In review

Each row has the same three fields. This table is a human-readable sketch, not ABAP’s square-bracket/object syntax. In ABAP, a structure describes the fields in one row, and an internal table holds multiple rows with that structure. The table exists temporarily in the program’s working memory; it is not, by itself, a database table.

2. Define the row and table types

TYPES: BEGIN OF ty_request,
         request_id TYPE string,
         item       TYPE string,
         status     TYPE string,
       END OF ty_request.

TYPES ty_requests TYPE STANDARD TABLE OF ty_request WITH EMPTY KEY.

ty_request describes one row. ty_requests names a standard internal table whose rows use that structure. The WITH EMPTY KEY clause makes explicit that this example does not need a primary table key.

3. Fill it with VALUE

DATA(requests) = VALUE ty_requests(
  ( request_id = 'PR-1042' item = 'Safety helmets'    status = 'In review' )
  ( request_id = 'PR-1043' item = 'Spare filters'     status = 'Approved' )
  ( request_id = 'PR-1044' item = 'Barcode scanners'  status = 'In review' )
).

This is the actual ABAP representation of the three rows sketched above. ABAP does not use JSON-style square brackets and object braces here: VALUE constructs the internal table, each inner pair of parentheses adds one row, and the named assignments set its fields. DATA(requests) is an inline declaration: the variable gets its type from ty_requests on the right.

4. Three practical ways to count matching rows

The task is the same in each example: count requests whose status is In review. These are useful, common choices—not every ABAP technique or syntax variation.

Option A: LOOP AT — the clearest place to start

DATA(review_count) = 0.

LOOP AT requests INTO DATA(request).
  IF request-status = 'In review'.
    review_count = review_count + 1.
  ENDIF.
ENDLOOP.

LOOP AT visits each row. INTO DATA(request) gives the current row a name; IF checks its status; the counter increases when it matches. This step-by-step form is usually easiest for a beginner to read and to inspect in a debugger.

Expected result: after the loop, review_count is 2. You can inspect the variable in your ABAP development environment’s debugger or use the output mechanism supported by that environment. This snippet is a method-body example, not a complete standalone program.

Option B: REDUCE — fold rows into one result

REDUCE is designed to calculate one result across an iteration. Here, count is the running total; the WHERE condition skips rows that do not match.

DATA(review_count) = REDUCE i(
  INIT count = 0
  FOR request IN requests
  WHERE ( status = 'In review' )
  NEXT count = count + 1
).

This also produces 2. It is compact, but the accumulator and NEXT step can take longer to understand at first. Use it when the reduction is small and the expression remains easy for your team to read.

Option C: FOR with VALUE — build a matching table, then count it

FOR inside a VALUE expression creates a new internal table. It is useful when the selected rows are themselves needed, not just their count.

DATA(review_requests) = VALUE ty_requests(
  FOR request IN requests
  WHERE ( status = 'In review' )
  ( request )
).

DATA(review_count) = lines( review_requests ).

review_requests contains the two matching rows, so lines( review_requests ) returns 2. This is a two-step choice: first transform/filter into a table, then count. If you only need a number, REDUCE expresses that goal more directly.

Which one should you choose?

Need Practical choice
Learn the flow, add several actions, or step through each row while debugging LOOP AT
Produce one summary value with a short, clear accumulation REDUCE
Create a filtered or transformed internal table for later work FOR inside VALUE

Start with LOOP AT while learning or when the logic benefits from explicit steps. Prefer REDUCE for a concise, readable single result; use FOR when the result should be a new table. Concision is not automatically clearer: SAP’s examples note that iteration expressions cannot be stepped through like a LOOP statement in the debugger.

Version note: These modern constructor and iteration expressions are not available in every older ABAP release or language version. The SAP sample repository focuses mainly on ABAP for Cloud Development on its main branch and documents release-specific branches for classic ABAP. Verify syntax in the documentation for your own system before using it.

5. Try it yourself

Use the coding exercise below to write the counting logic. Choose LOOP AT, REDUCE, or FOR + VALUE, then complete the ABAP code to count the two requests whose status is In review. The local checker looks for the key syntax pattern for your chosen approach; it does not compile or execute ABAP.

A quick mental check

  1. If all three rows have status In review, what value should each counting option produce?
  2. Which option gives you a new table you could process again?
  3. Does an internal table automatically save its contents to a database?
Show the answers
  1. 3.
  2. Option C, because it constructs review_requests.
  3. No. An internal table is a program’s in-memory data collection. Saving business data requires separate application logic and an appropriate data source.

Practice: write the counting code

The editor uses fictional sample data prepared as requests, matching the rows shown above. Write the ABAP counting expression or loop yourself. Use Check code for structural feedback, or reveal the model solutions when you want a reference. This browser exercise never runs ABAP and never connects to an SAP system.

Sources and further reading

This independently written guide was last reviewed on 1 November 2026. SAP product and language behavior may change; verify release-specific details in the documentation for your system. ERP Field Notes is independent and is not affiliated with or endorsed by SAP SE.

Developer coding exercise · ABAP

Count the requests in review

Code practice

The internal table requests is already filled with the three sample rows above. Write ABAP code that sets review_count to the number of rows with status: In review.

ABAP input already prepared
DATA(requests) = VALUE ty_requests(
  ( request_id = 'PR-1042' item = 'Safety helmets'    status = 'In review' )
  ( request_id = 'PR-1043' item = 'Spare filters'     status = 'Approved' )
  ( request_id = 'PR-1044' item = 'Barcode scanners'  status = 'In review' )
).

Expected result: review_count = 2

You can edit or replace the starter comment. Identifier names such as request and lwa_request may differ, but each use must match its declaration. Changing approaches resets the editor.

The checker checks required code structure and consistent declared identifier use. It does not execute or compile ABAP; verify syntax and results in an ABAP development environment.