4 weeks ago
I'd like to use ABAP 7.40 instead of the old AT NEW and AT END OF statements, because the latter are prone to errors if LOOP AT...INTO is used as some fields can be changed to all *, or because the components of the control break must be positioned to the left to the internal table otherwise the result is wrong.
Here is the original code to convert to ABAP 7.40:
TYPES:
BEGIN OF ty_itab_line,
carrid TYPE sbook-carrid,
connid TYPE sbook-connid,
fldate TYPE sbook-fldate,
bookid TYPE sbook-bookid,
END OF ty_itab_line.
TYPES tt_itab TYPE STANDARD TABLE OF ty_itab_line WITH EMPTY KEY.
DATA(itab) = VALUE tt_itab( carrid = 'LH'
connid = '0370'
fldate = sy-datum
( bookid = 1 )
( bookid = 2 ) ).
DATA(log) = VALUE string_table( ).
SORT itab BY carrid connid fldate.
LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).
AT NEW connid.
INSERT |Flight { <line>-carrid }{ <line>-connid } { <line>-fldate }| INTO TABLE log.
DATA(number_of_bookings) = 0.
ENDAT.
INSERT | - Booking { <line>-bookid }| INTO TABLE log.
number_of_bookings = number_of_bookings + 1.
AT END OF carrid.
INSERT | - Number of bookings for flight { <line>-carrid }{ <line>-connid
} { <line>-fldate }: { number_of_bookings }| INTO TABLE log.
ENDAT.
ENDLOOP.Thanks.
Sandra
4 weeks ago - last edited 4 weeks ago
The workaround is to use LOOP AT...GROUP BY instead of the AT control level statements (since ABAP 7.40):
TYPES:
BEGIN OF ty_itab_line,
carrid TYPE sbook-carrid,
connid TYPE sbook-connid,
fldate TYPE sbook-fldate,
bookid TYPE sbook-bookid,
END OF ty_itab_line.
TYPES tt_itab TYPE STANDARD TABLE OF ty_itab_line WITH EMPTY KEY.
DATA(itab) = VALUE tt_itab( carrid = 'LH'
connid = '0370'
fldate = sy-datum
( bookid = 1 )
( bookid = 2 ) ).
DATA(log) = VALUE string_table( ).
SORT itab BY carrid connid fldate.
LOOP AT itab
ASSIGNING FIELD-SYMBOL(<line>)
GROUP BY ( carrid = <line>-carrid
connid = <line>-connid
fldate = <line>-fldate )
ASSIGNING FIELD-SYMBOL(<group_key>).
INSERT |Flight { <group_key>-carrid }{ <group_key>-connid } { <group_key>-fldate }| INTO TABLE log.
DATA(number_of_bookings) = 0.
LOOP AT GROUP <group_key> ASSIGNING <line>.
INSERT | - Booking { <line>-bookid }| INTO TABLE log.
number_of_bookings = number_of_bookings + 1.
ENDLOOP.
INSERT | - Number of bookings for flight { <group_key>-carrid }{ <group_key>-connid
} { <group_key>-fldate }: { number_of_bookings }| INTO TABLE log.
ENDLOOP.Happy grouping!
4 weeks ago - last edited 4 weeks ago
The workaround is to use LOOP AT...GROUP BY instead of the AT control level statements (since ABAP 7.40):
TYPES:
BEGIN OF ty_itab_line,
carrid TYPE sbook-carrid,
connid TYPE sbook-connid,
fldate TYPE sbook-fldate,
bookid TYPE sbook-bookid,
END OF ty_itab_line.
TYPES tt_itab TYPE STANDARD TABLE OF ty_itab_line WITH EMPTY KEY.
DATA(itab) = VALUE tt_itab( carrid = 'LH'
connid = '0370'
fldate = sy-datum
( bookid = 1 )
( bookid = 2 ) ).
DATA(log) = VALUE string_table( ).
SORT itab BY carrid connid fldate.
LOOP AT itab
ASSIGNING FIELD-SYMBOL(<line>)
GROUP BY ( carrid = <line>-carrid
connid = <line>-connid
fldate = <line>-fldate )
ASSIGNING FIELD-SYMBOL(<group_key>).
INSERT |Flight { <group_key>-carrid }{ <group_key>-connid } { <group_key>-fldate }| INTO TABLE log.
DATA(number_of_bookings) = 0.
LOOP AT GROUP <group_key> ASSIGNING <line>.
INSERT | - Booking { <line>-bookid }| INTO TABLE log.
number_of_bookings = number_of_bookings + 1.
ENDLOOP.
INSERT | - Number of bookings for flight { <group_key>-carrid }{ <group_key>-connid
} { <group_key>-fldate }: { number_of_bookings }| INTO TABLE log.
ENDLOOP.Happy grouping!