TABLES: ekko.
TYPES: BEGIN OF ts_ekko,
ebeln TYPE ekko-ebeln,
lifnr TYPE ekko-lifnr,
END OF ts_ekko.
DATA wa_ekko TYPE ts_ekko.
FIELD-SYMBOLS <it_ekko> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
END OF ts_ekpo.
DATA wa_ekpo TYPE ts_ekpo.
FIELD-SYMBOLS <it_ekpo> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_lfa1,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
END OF ts_lfa1.
DATA wa_lfa1 TYPE ts_lfa1.
FIELD-SYMBOLS <it_lfa1> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_makt,
matnr TYPE makt-matnr,
spras TYPE makt-spras,
maktx TYPE makt-maktx,
END OF ts_makt.
DATA wa_makt TYPE ts_makt.
FIELD-SYMBOLS <it_makt> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_out,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
maktx TYPE makt-maktx,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
lifnr TYPE ekko-lifnr,
name1 TYPE lfa1-name1,
END OF ts_out.
DATA wa_out TYPE ts_out.
FIELD-SYMBOLS <it_out> TYPE STANDARD TABLE.
DATA: dref TYPE REF TO data.
FIELD-SYMBOLS <where> TYPE any.
INITIALIZATION.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.
START-OF-SELECTION.
CREATE DATA dref TYPE TABLE OF ts_ekko.
ASSIGN dref->* TO <it_ekko>.
SELECT ebeln lifnr
FROM ekko INTO TABLE <it_ekko>
WHERE ebeln IN s_ebeln.
IF sy-subrc = 0.
CREATE DATA dref TYPE TABLE OF ts_ekpo.
ASSIGN dref->* TO <it_ekpo>.
ASSIGN 'ebeln = <it_ekko>-ebeln' TO <where>.
SELECT ebeln ebelp matnr werks
lgort menge meins
FROM ekpo INTO TABLE <it_ekpo>
FOR ALL ENTRIES IN <it_ekko>
WHERE (<where>).
IF sy-subrc = 0.
CREATE DATA dref TYPE TABLE OF ts_makt.
ASSIGN dref->* TO <it_makt>.
ASSIGN 'matnr = <it_ekpo>-matnr' TO <where>.
SELECT matnr spras maktx
FROM makt INTO TABLE <it_makt>
FOR ALL ENTRIES IN <it_ekpo>
WHERE (<where>)
AND spras = sy-langu.
ENDIF.
CREATE DATA dref TYPE TABLE OF ts_lfa1.
ASSIGN dref->* TO <it_lfa1>.
ASSIGN 'lifnr = <it_ekko>-lifnr' TO <where>.
SELECT lifnr name1
FROM lfa1 INTO TABLE <it_lfa1>
FOR ALL ENTRIES IN <it_ekko>
WHERE (<where>).
ENDIF.
SORT: <it_ekpo> BY ('EBELN'),
<it_ekko> BY ('EBELN'),
<it_makt> BY ('MATNR'),
<it_lfa1> BY ('LIFNR').
IF <it_ekpo> IS ASSIGNED.
CREATE DATA dref TYPE TABLE OF ts_out.
ASSIGN dref->* TO <it_out>.
LOOP AT <it_ekpo> INTO wa_ekpo.
wa_out-ebeln = wa_ekpo-ebeln.
wa_out-ebelp = wa_ekpo-ebelp.
wa_out-matnr = wa_ekpo-matnr.
wa_out-werks = wa_ekpo-werks.
wa_out-lgort = wa_ekpo-lgort.
wa_out-menge = wa_ekpo-menge.
wa_out-meins = wa_ekpo-meins.
IF <it_ekko> IS ASSIGNED.
READ TABLE <it_ekko> INTO wa_ekko
WITH KEY ('EBELN') = wa_ekpo-ebeln
BINARY SEARCH.
IF sy-subrc = 0 AND <it_lfa1> IS ASSIGNED.
READ TABLE <it_lfa1> INTO wa_lfa1
WITH KEY ('LIFNR') = wa_ekko-lifnr
BINARY SEARCH.
IF sy-subrc = 0.
wa_out-lifnr = wa_lfa1-lifnr.
wa_out-name1 = wa_lfa1-name1.
ENDIF.
ENDIF.
ENDIF.
IF <it_makt> IS ASSIGNED.
READ TABLE <it_makt> INTO wa_makt
WITH KEY ('MATNR') = wa_ekpo-matnr
BINARY SEARCH.
IF sy-subrc = 0.
wa_out-maktx = wa_makt-maktx.
ENDIF.
ENDIF.
APPEND wa_out TO <it_out>.
CLEAR: wa_out, wa_makt, wa_ekko, wa_ekpo, wa_lfa1.
ENDLOOP.
ENDIF.
IF <it_out> IS ASSIGNED.
WRITE: / 'PO',
15 'Item',
24 'Material',
40 'Description',
75 'Plant',
81 'S.Loc.',
87 'Qty',
105 'UoM',
110 'Vendor',
121 'Name'.
ULINE.
LOOP AT <it_out> INTO wa_out.
WRITE: / wa_out-ebeln,
15 wa_out-ebelp,
24 wa_out-matnr,
40 wa_out-maktx,
75 wa_out-werks,
81 wa_out-lgort,
87 wa_out-menge,
105 wa_out-meins,
110 wa_out-lifnr,
121 wa_out-name1.
ENDLOOP.
ENDIF.
TYPES: BEGIN OF ts_ekko,
ebeln TYPE ekko-ebeln,
lifnr TYPE ekko-lifnr,
END OF ts_ekko.
DATA wa_ekko TYPE ts_ekko.
FIELD-SYMBOLS <it_ekko> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
END OF ts_ekpo.
DATA wa_ekpo TYPE ts_ekpo.
FIELD-SYMBOLS <it_ekpo> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_lfa1,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
END OF ts_lfa1.
DATA wa_lfa1 TYPE ts_lfa1.
FIELD-SYMBOLS <it_lfa1> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_makt,
matnr TYPE makt-matnr,
spras TYPE makt-spras,
maktx TYPE makt-maktx,
END OF ts_makt.
DATA wa_makt TYPE ts_makt.
FIELD-SYMBOLS <it_makt> TYPE STANDARD TABLE.
TYPES: BEGIN OF ts_out,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
maktx TYPE makt-maktx,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
lifnr TYPE ekko-lifnr,
name1 TYPE lfa1-name1,
END OF ts_out.
DATA wa_out TYPE ts_out.
FIELD-SYMBOLS <it_out> TYPE STANDARD TABLE.
DATA: dref TYPE REF TO data.
FIELD-SYMBOLS <where> TYPE any.
INITIALIZATION.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.
START-OF-SELECTION.
CREATE DATA dref TYPE TABLE OF ts_ekko.
ASSIGN dref->* TO <it_ekko>.
SELECT ebeln lifnr
FROM ekko INTO TABLE <it_ekko>
WHERE ebeln IN s_ebeln.
IF sy-subrc = 0.
CREATE DATA dref TYPE TABLE OF ts_ekpo.
ASSIGN dref->* TO <it_ekpo>.
ASSIGN 'ebeln = <it_ekko>-ebeln' TO <where>.
SELECT ebeln ebelp matnr werks
lgort menge meins
FROM ekpo INTO TABLE <it_ekpo>
FOR ALL ENTRIES IN <it_ekko>
WHERE (<where>).
IF sy-subrc = 0.
CREATE DATA dref TYPE TABLE OF ts_makt.
ASSIGN dref->* TO <it_makt>.
ASSIGN 'matnr = <it_ekpo>-matnr' TO <where>.
SELECT matnr spras maktx
FROM makt INTO TABLE <it_makt>
FOR ALL ENTRIES IN <it_ekpo>
WHERE (<where>)
AND spras = sy-langu.
ENDIF.
CREATE DATA dref TYPE TABLE OF ts_lfa1.
ASSIGN dref->* TO <it_lfa1>.
ASSIGN 'lifnr = <it_ekko>-lifnr' TO <where>.
SELECT lifnr name1
FROM lfa1 INTO TABLE <it_lfa1>
FOR ALL ENTRIES IN <it_ekko>
WHERE (<where>).
ENDIF.
SORT: <it_ekpo> BY ('EBELN'),
<it_ekko> BY ('EBELN'),
<it_makt> BY ('MATNR'),
<it_lfa1> BY ('LIFNR').
IF <it_ekpo> IS ASSIGNED.
CREATE DATA dref TYPE TABLE OF ts_out.
ASSIGN dref->* TO <it_out>.
LOOP AT <it_ekpo> INTO wa_ekpo.
wa_out-ebeln = wa_ekpo-ebeln.
wa_out-ebelp = wa_ekpo-ebelp.
wa_out-matnr = wa_ekpo-matnr.
wa_out-werks = wa_ekpo-werks.
wa_out-lgort = wa_ekpo-lgort.
wa_out-menge = wa_ekpo-menge.
wa_out-meins = wa_ekpo-meins.
IF <it_ekko> IS ASSIGNED.
READ TABLE <it_ekko> INTO wa_ekko
WITH KEY ('EBELN') = wa_ekpo-ebeln
BINARY SEARCH.
IF sy-subrc = 0 AND <it_lfa1> IS ASSIGNED.
READ TABLE <it_lfa1> INTO wa_lfa1
WITH KEY ('LIFNR') = wa_ekko-lifnr
BINARY SEARCH.
IF sy-subrc = 0.
wa_out-lifnr = wa_lfa1-lifnr.
wa_out-name1 = wa_lfa1-name1.
ENDIF.
ENDIF.
ENDIF.
IF <it_makt> IS ASSIGNED.
READ TABLE <it_makt> INTO wa_makt
WITH KEY ('MATNR') = wa_ekpo-matnr
BINARY SEARCH.
IF sy-subrc = 0.
wa_out-maktx = wa_makt-maktx.
ENDIF.
ENDIF.
APPEND wa_out TO <it_out>.
CLEAR: wa_out, wa_makt, wa_ekko, wa_ekpo, wa_lfa1.
ENDLOOP.
ENDIF.
IF <it_out> IS ASSIGNED.
WRITE: / 'PO',
15 'Item',
24 'Material',
40 'Description',
75 'Plant',
81 'S.Loc.',
87 'Qty',
105 'UoM',
110 'Vendor',
121 'Name'.
ULINE.
LOOP AT <it_out> INTO wa_out.
WRITE: / wa_out-ebeln,
15 wa_out-ebelp,
24 wa_out-matnr,
40 wa_out-maktx,
75 wa_out-werks,
81 wa_out-lgort,
87 wa_out-menge,
105 wa_out-meins,
110 wa_out-lifnr,
121 wa_out-name1.
ENDLOOP.
ENDIF.
No comments:
Post a Comment