SAP LOOP- ABAP Statements

Get Example source ABAP code based on a different SAP table
  


Standard SAP Help for LOOP

LOOP - Extract

Short Reference
• LOOP - extract ABAP Statement

ABAP Syntax(Obsolete)LOOP.
...
ENDLOOP.

What does it do? The LOOP and ENDLOOP statements define a loop around a statement block. The loop is passed for each row from the extract dataset until it is exited using one of the statements from the section Exit Loops. In each loop pass, the LOOP statement assigns the contents of the components from the current row of the extract dataset to the data objects that make up the field group of the row. If the extract dataset is not sorted, the order in which the rows are read is the same in which they were appended using the EXTRACT statement. If the extract dataset is sorted using SORT , the read order is the same as the sort order.

A LOOP loop also ends the process of structuring the extract dataset. If you execute an EXTRACT statement after a LOOP statement, an unhandleable exception is raised. In addition, you cannot process the extract dataset using either LOOP or SORT within a LOOP block. You cannot nest LOOP blocks that read the extract dataset.

System Fields sy-subrcMeaning 0The loop was run at least once. 4The loop was not run at all.

Latest notes:Do not confuse the statement LOOP on the extract dataset with the statement LOOP AT for internal tables. In global classes, no field groups can be defined or edited. In methods of local classes of programs other than class pools, the sta tement LOOP can be used for field groups defined in these methods. Extracts are obsolete. Internal tables are recommended instead.



Example ABAP Coding
See Extracts, Processing




Runtime Exceptions
Non-catchable Exceptions
Reason for error:
Nested loop at an extracted dataset.
Runtime error:
LOOP_WITHIN_LOOP

Return to menu