ABAP顾问
分类:
2007-12-05 11:20:00
*&---------------------------------------------------------------------*
*& Report z_barry_deep_itab *
*&---------------------------------------------------------------------*
REPORT z_barry_deep_itab.
TABLES ekko.
DATA: BEGIN OF itab OCCURS 0 ,
ebeln LIKE ekko-ebeln ,
lifnr LIKE ekko-lifnr ,
bedat LIKE ekko-bedat ,
ebelp LIKE ekpo-ebelp ,
matnr LIKE ekbe-matnr ,
END OF itab.
TYPES : BEGIN OF tp_ptab ,
ebeln LIKE ekbe-ebeln ,
ebelp LIKE ekpo-ebelp ,
matnr LIKE ekbe-matnr ,
END OF tp_ptab .
TYPES tt_ptab TYPE STANDARD TABLE OF tp_ptab WITH DEFAULT KEY .
DATA: it_ptab TYPE STANDARD TABLE OF tp_ptab WITH HEADER LINE .
DATA: wa_ptab LIKE LINE OF it_ptab .
TYPES : BEGIN OF tp_ktab ,
ebeln LIKE ekko-ebeln ,
lifnr LIKE ekko-lifnr ,
bedat LIKE ekko-bedat ,
ptab TYPE tt_ptab ,
END OF tp_ktab .
DATA: it_ktab TYPE STANDARD TABLE OF tp_ktab WITH HEADER LINE .
DATA: tmpebeln LIKE ekko-ebeln.
SELECT-OPTIONS: s_aedat FOR ekko-aedat.
START-OF-SELECTION.
PERFORM getdata.
PERFORM fixdata.
*---------------------------------------------------------------------*
* FORM getdata *
*---------------------------------------------------------------------*
FORM getdata.
SELECT ekko~ebeln ekko~lifnr ekko~bedat
ekpo~ebelp ekpo~matnr
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ekko INNER JOIN ekpo ON ekko~ebeln = ekpo~ebeln
WHERE ekko~aedat IN s_aedat.
ENDFORM.
*---------------------------------------------------------------------*
* FORM fixdata *
*---------------------------------------------------------------------*
FORM fixdata.
LOOP AT itab .
ON CHANGE OF itab-ebeln .
CLEAR it_ktab-ptab.
CLEAR tmpebeln .
tmpebeln = itab-ebeln .
LOOP AT itab WHERE ebeln = tmpebeln .
wa_ptab-ebeln = itab-ebeln .
wa_ptab-ebelp = itab-ebelp .
wa_ptab-matnr = itab-matnr .
COLLECT wa_ptab INTO it_ktab-ptab .
ENDLOOP .
SORT it_ktab-ptab BY ebeln matnr .
it_ktab-ebeln = itab-ebeln .
it_ktab-lifnr = itab-lifnr .
it_ktab-bedat = itab-bedat .
APPEND it_ktab .
ENDON .
ENDLOOP .
ENDFORM.