Code: Alles auswählen.
Beispiel:
Tabelle1
von-Datum - bis-Datum
01.01.2010 - 31.12.2010
01.01.2011 - 30.04.2011
01.05.2011 - 31.12.9999
Tabelle2
01.01.2010 - 31.05.2010
01.06.2010 - 31.12.2010
01.01.2011 - 30.06.2011
01.07.2011 - 31.12.9999
Ergebnis:
01.01.2010 - 31.05.2010
01.06.2010 - 31.12.2010
01.01.2011 - 30.04.2011
01.05.2011 - 30.06.2011
01.07.2011 - 31.12.9999
Code: Alles auswählen.
REPORT zzawtest29.
TYPES: BEGIN OF ts_dates,
datvn TYPE datvon,
datbi TYPE datbi,
END OF ts_dates.
DATA: gt_date1 TYPE TABLE OF ts_dates,
gt_date2 TYPE TABLE OF ts_dates,
gt_dates TYPE TABLE OF ts_dates,
gs_dates TYPE ts_dates.
DATA: gv_start TYPE datvon.
INITIALIZATION.
* Ausgangstabellen füllen
APPEND '2010010120101231' TO gt_date1.
APPEND '2011010120110430' TO gt_date1.
APPEND '2011050199991231' TO gt_date1.
APPEND '2010010120100531' TO gt_date2.
APPEND '2010060120101231' TO gt_date2.
APPEND '2011010120110630' TO gt_date2.
APPEND '2011070199991231' TO gt_date2.
START-OF-SELECTION.
**** Lösung beginnt hier
APPEND LINES OF gt_date2 TO gt_date1.
LOOP AT gt_date1 INTO gs_dates.
IF gs_dates-datvn < gv_start
OR gv_start IS INITIAL.
gv_start = gs_dates-datvn.
ENDIF.
CLEAR gs_dates-datvn.
COLLECT gs_dates INTO gt_dates.
ENDLOOP.
SORT gt_dates BY datbi.
LOOP AT gt_dates INTO gs_dates.
gs_dates-datvn = gv_start.
MODIFY gt_dates FROM gs_dates.
gv_start = gs_dates-datbi + 1.
ENDLOOP.