SAP LOOP AT ITAB RESULT ABAP Statements

Get Example source ABAP code based on a different SAP table
  



LOOP AT itab - result

Short Reference
• INTO LOOP AT itab
• CASTING LOOP AT itab
• ASSIGNING LOOP AT itab
• REFERENCE INTO LOOP AT itab
• TRANSPORTING NO FIELDS LOOP AT itab


ABAP Syntax ... { INTO wa }

| { ASSIGNING <(><<)>fs> [CASTING] }
| { REFERENCE INTO dref }
| { TRANSPORTING NO FIELDS } ... .

What does it do? There are four alternatives for the output behavior: The addition INTO is used to assign the content of the current row to a work area wa.
The addition ASSIGNING is used to assign the current row to a field symbol <(><<)>fs>. No other memory area can be assigned to the field symbol within the loop and the assignment cannot be undone using UNASSIGN.
The addition REFERENCE INTO is used to create a reference to the current row in a reference table. No other reference can be assigned to the reference variable within the loop and the reference variable cannot be initialized using CLEAR.
The addition TRANSPORTING NO FIELDS specifies that only the relevant system fields are filled. This addition is possible only if the addition WHERE is used in the conditions cond at the same time.

If the internal table itab is specified as an existing data object, the syntax and meaning of the specified output behavior is the same as in the statement READ TABLE (with the exception that no further transport_options can be specified after INTO wa) and the same restrictions apply to modifications to key fields of the primary and secondary table keys.

In particular, inline declarations for the work area, the field symbol, or the reference variable using the declaration operators DATA and FIELD-SYMBOL are possible.

If the internal table is specified as the return value of a functional method, a constructor expression, or a table expression, the additions ASSIGNING and REFERENCE INTO can also be specified for LOOP (this is not the case with READ TABLE). The internal table is only available while the loop is being processed, which means that all field symbols and reference variables that point to rows in the internal table become invalid when the loop is exited.

Latest notes:For LOOP, an obsolete short form exists (outside of classes) where INTO wa can be omitted if the internal table has a header line itab with the same name. INTO itab is then added to the statement. If the current row is deleted within the loop when the additions ASSIGNING or REFERENCE are used, the field symbol or reference variable are then unassigned or unbound in the current loop pass.

Return to menu