DATA: BEGIN OF count_line,
carrid TYPE spfli-carrid,
count TYPE i,
END OF count_line,
spfli_tab TYPE TABLE OF spfli. DATA: dbcur1 TYPE cursor,
dbcur2 TYPE cursor. OPEN CURSOR @dbcur1 FOR
SELECT carrid, count(*) AS count
FROM spfli
GROUP BY carrid
ORDER BY carrid. OPEN CURSOR @dbcur2 FOR
SELECT *
FROM spfli
ORDER BY carrid. DO.
FETCH NEXT CURSOR @dbcur1 INTO @count_line.
IF sy-subrc <> .
EXIT.
ENDIF.
FETCH NEXT CURSOR @dbcur2
INTO TABLE @spfli_tab PACKAGE SIZE @count_line-count.
ENDDO. CLOSE CURSOR: @dbcur1,
@dbcur2.
DATA: wa_spfli TYPE spfli,
wa_sflight TYPE sflight,
wa_sflight_back TYPE sflight. DATA: c1 TYPE cursor,
c2 TYPE cursor. OPEN CURSOR @c1 FOR
SELECT *
FROM spfli
ORDER BY PRIMARY KEY. OPEN CURSOR @c2 FOR
SELECT *
FROM sflight
ORDER BY PRIMARY KEY. DATA(out) = cl_demo_output=>new( ). DO.
FETCH NEXT CURSOR @c1 INTO @wa_spfli.
IF sy-subrc NE .
EXIT.
ENDIF.
out->begin_section(
|{ wa_spfli-carrid } { wa_spfli-connid }| ).
DO.
IF NOT wa_sflight_back IS INITIAL.
wa_sflight = wa_sflight_back.
CLEAR wa_sflight_back.
ELSE.
FETCH NEXT CURSOR @c2 INTO @wa_sflight.
IF sy-subrc <> .
EXIT.
ELSEIF wa_sflight-carrid <> wa_spfli-carrid
OR wa_sflight-connid <> wa_spfli-connid.
wa_sflight_back = wa_sflight.
EXIT.
ENDIF.
ENDIF.
out->write(
|{ wa_sflight-carrid } {
wa_sflight-connid } {
wa_sflight-fldate }| ).
ENDDO.
out->end_section( ).
ENDDO. CLOSE CURSOR: @c1, @c2. out->display( ).