Variante 1 (FOR … WHILE)
DATA(it_strings) = VALUE stringtab( ).
it_strings = VALUE #(
* For i = 1 To 10
FOR i = 1 WHILE i < 11
(
|{ i }|
)
).
cl_demo_output=>display( it_strings ).
Variante 2 (FOR … WHILE mit Schrittweite)
DATA(it_strings) = VALUE stringtab( ).
it_strings = VALUE #(
* For i = 1 To 10 Step 2
FOR i = 1 THEN i + 2 WHILE i < 11
(
|{ i }|
)
).
cl_demo_output=>display( it_strings ).
Variante 3 (NESTED FOR)
SELECT * FROM sflight INTO TABLE @DATA(it_sflight).
SELECT * FROM spfli INTO TABLE @DATA(it_spfli).
DATA(it_strings) = VALUE stringtab(
* alle Einträge aus sflight ab 01.01.2013
FOR <f> IN it_sflight INDEX INTO idxf WHERE ( fldate >= '20130101' )
* alle Einträge aus spfli mit den Schlüsseln wie in der Ergebnismenge des vorherigen FOR
FOR <c> IN it_spfli INDEX INTO idxc WHERE ( carrid = <f>-carrid AND connid = <f>-connid )
(
* Ausgabe als Stringtab
|{ idxf } \| { idxc } \| { <c>-carrid } \| { <c>-connid } \| { <c>-airpfrom }|
)
).
cl_demo_output=>display( it_strings ).
Variante 4 (FOR GROUPS, FOR … IN GROUP)
TYPES: BEGIN OF ty_mat,
matnr TYPE matnr,
mtart TYPE mtart,
price TYPE kbetr,
END OF ty_mat.
TYPES: ty_it_mat TYPE HASHED TABLE OF ty_mat WITH UNIQUE KEY matnr
WITH NON-UNIQUE SORTED KEY key_mtart COMPONENTS mtart.
TYPES: BEGIN OF ty_mat_sum,
mtart TYPE mtart,
count TYPE i,
price TYPE kbetr,
END OF ty_mat_sum.
TYPES: ty_it_mat_sum TYPE HASHED TABLE OF ty_mat_sum WITH UNIQUE KEY mtart.
* Tabelle mit Materialien
DATA(it_mat) = VALUE ty_it_mat(
( matnr = '1' mtart = 'ROH' price = '1.56' )
( matnr = '2' mtart = 'ROH' price = '2.00' )
( matnr = '3' mtart = 'NLAG' price = '3.10' )
( matnr = '4' mtart = 'NLAG' price = '0.40' )
( matnr = '5' mtart = 'NLAG' price = '4.10' )
( matnr = '6' mtart = 'HALB' price = '1.00' )
( matnr = '7' mtart = 'HALB' price = '0.10' )
).
* Tabelle gruppiert nach Materialarten ohne 'HALB' und summierten Preisen
DATA(it_mat_sum) = VALUE ty_it_mat_sum(
FOR GROUPS grp OF <mtart> IN it_mat WHERE ( mtart NE 'HALB' ) GROUP BY ( mtart = <mtart>-mtart size = GROUP SIZE )
(
mtart = grp-mtart " Materialart der Gruppe
count = grp-size " Anz. Elemente der Gruppe
price = REDUCE #( " Summe über die Elemente der akt. Gruppe bilden
INIT p = '0.00'
FOR <m> IN GROUP grp WHERE ( mtart = grp-mtart )
NEXT p = p + <m>-price
)
)
).
cl_demo_output=>display( it_mat_sum ).
Links