SAP LOOP AT DBTAB ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• LOOP AT dbtab ABAP Statement

LOOP AT dbtab
Short Reference

ABAP_SYNTAX_OBS
LOOP AT ${ dbtab $| *dbtab $} $[VERSION vers$].
...
ENDLOOP.

ABAP Addition
... VERSION vers

What does it do?
The statements LOOP and ENDLOOP define a loop around a statement block, which is forbidden in classes. dbtab expects a database table or DDIC table view that starts with T and has a maximum length of five characters. For the database table or view dbtab, a table work area or an additional table work area must be declared using the statement TABLES. All components of the table work area that match the primary key fields of the database table or view dbtab must be character-like.
In each loop pass, the statement LOOP reads a row from the database table or view dbtab and assigns its content either to the table work area, or if *dbtab is specified, to the additional table work area. The rows to be read are determined by the content of the components of the table work area that match the primary key fields of the database table or view dbtab. Before the first loop pass, the content of these components is taken left-aligned as the search key and the database table or view is searched generically for suitable entries. The search key handles blanks as if they match all values.
If a database table or view is specified that does not start with T , the first letter is implicitly replaced by T. The loop is not executed if the database table or view does not exist.
System Fields sy-subrcMeaning 12The database table or view was not found.
BEGIN_SECTION SAP_INTERNAL_HINT
sy-subrc is set to 16, if access to the database specified by VERSION is not allowed by the dynamic package check.
END_SECTION SAP_INTERNAL_HINT



Latest notes:

This form of the LOOP-loop is not allowed in classes. It must be replaced by the SELECT statement.