Ansicht
Dokumentation

ABAPLOOP_AT_ITAB_GROUP_BY_BINDING - LOOP AT ITAB GROUP BY BINDING

ABAPLOOP_AT_ITAB_GROUP_BY_BINDING - LOOP AT ITAB GROUP BY BINDING

Addresses (Business Address Services)   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.
SAP E-Book

LOOP AT itab, group_result

... ${ $}
  $| ${INTO group$}$|${ASSIGNING group>$}$|${REFERENCE INTO group_ref$} ...


Alternatives:

1. ... ${ $}

2. ... ${INTO group$}$|${ASSIGNING group>$}$|${REFERENCE INTO group_ref$}

Effect

Defines the output behavior of the group loop in a grouping of an internal table in a LOOP. The output behavior defines the following:

  • A data object or field symbol whose content is accessed in the group loop and which can also be passed to called procedures.
  • A name for the group which can only be used within the current group loop and loops nested in the statement LOOP AT GROUP or in an expression FOR ... IN GROUP for specifying a group.

Alternative 1

... ${ $}


Effect

Representative binding. If nothing is specified for the output behavior group_result, the output behavior is determined for the table lines using the addition result. In each loop pass, the first line of the current group is assigned as a representative of its group to the data object or field symbol defined there. The representative is bound to the current group and the group can be addressed using the name of the representative in the statement LOOP AT GROUP or the expression FOR ... IN GROUP.

If the representative binding is used,

  • the addition WITHOUT MEMBERS is not possible, since there would be no assignment of the representative to its group in this case,
  • no additional components for GROUP SIZE and GROUP INDEX can be created for a structured group key, since it is impossible to access these components in this case.

Outside of the group loop, the representative is not bound to the group and cannot be used to specify it in member loops. This applies in particular to procedures called from the group loop.

Note

If a representative is bound to the current group, the associated group key cannot be addressed in the group loop.

Example

The group key in the following example is a structure with two components key1 and key2 to which the columns key1 and key2 are assigned to each line of the internal table itab in the grouping. This produces three groups with the group key values (a, a), (a, b), and (b, a). Accordingly, the group loop is passed three times and the first, second, and sixth line are assigned to the field symbol wa> as representatives. See also the executable example of output behavior.

Alternative 2

... ${INTO group$}$|${ASSIGNINGgroup>$}$|${REFERENCE INTO group_ref$}


Effect

Group key binding. If an explicit output behavior group_result is specified, the group key of the current key is assigned to the data object or field symbol specified after INTO, ASSIGNING, or REFERENCE INTO in every loop pass. Here, the same syntax and semantics apply as in the output behavior result. The data type of the specified data object or field symbol must match the data type of the group key. If the group key is constructed as a new structure in the group key expression, the target type must be a structure whose components have the same name and in the same order as in the group key.

The specified data object or field symbol is bound to the current group and the group can be addressed using its name in the statement LOOP AT GROUP or the expression FOR ... IN GROUP. Outside of the group loop, the data object or field symbol is not bound to the group and cannot be used to specify it in member loops. This applies in particular to procedures that are called from the group loop. At the end of the group loop, the grouping is canceled and a specified data object is initialized or a field symbol no longer has a group key assigned to it.

The data object or field symbol of the output behavior defined in result for the table lines can still be addressed in the group loop but it is either initial after the LOOP statement or does not point to a line.

Notes

  • To specify a type-compliant data object or field symbol as the target for the group key, it is best to use an inline declaration, which is always possible here.
  • The output behavior result for the table lines is still required when group_result is specified explicitly for the construction of the group key group_key.
  • Unlike in result, no addition CASTING for table lines can be specified after ASSIGNING.

Example

Like in the previous example, however the groups are not assigned to an implicit representative here and to the explicitly defined target area for the group key instead. In each of the three loop passes, the reference variable group_key declared inline points to the respective structured group key (a, a), (a, b), and (b, a). See also the executable example of output behavior.








ROGBILLS - Synchronize billing plans   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.

Length: 7932 Date: 20240329 Time: 033733     sap01-206 ( 147 ms )