Google Search - Blog...........

ABAP - Sample Program On For All Entries - MM.

REPORT ZTEST.

TABLES:MARA,MARC,MARD,MAKT.

DATA:BEGIN OF IT_MARA OCCURS 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MEINS LIKE MARA-MEINS,
END OF IT_MARA.

DATA:BEGIN OF IT_MARC OCCURS 0,
MATNR LIKE MARC-MATNR,
WERKS LIKE MARC-WERKS,
PSTAT LIKE MARC-PSTAT,
END OF IT_MARC.

DATA:BEGIN OF IT_MARD OCCURS 0,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
LABST LIKE MARD-LABST,
END OF IT_MARD.

DATA:BEGIN OF IT_FINAL OCCURS 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MEINS LIKE MARA-MEINS,
WERKS LIKE MARC-WERKS,
PSTAT LIKE MARC-PSTAT,
LGORT LIKE MARD-LGORT,
LABST LIKE MARD-LABST,
MAKTX LIKE MAKT-MAKTX,
MAKTG LIKE MAKT-MAKTG,
END OF IT_FINAL.

DATA:BEGIN OF IT_MAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
MAKTG LIKE MAKT-MAKTG,
END OF IT_MAKT.
SELECT-OPTIONS:S_MATNR FOR MARA-MATNR.

START-OF-SELECTION.
SELECT MATNR
MTART
MEINS
FROM MARA
INTO TABLE IT_MARA
WHERE MATNR IN S_MATNR.




IF NOT IT_MARA[] IS INITIAL.
SELECT MATNR
WERKS
PSTAT
FROM MARC
INTO TABLE IT_MARC
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR.


SELECT MATNR
MAKTX
MAKTG
FROM MAKT
INTO TABLE IT_MAKT
FOR ALL ENTRIES IN IT_MARA
WHERE MATNR = IT_MARA-MATNR.


IF NOT IT_MARC[] IS INITIAL.
SELECT WERKS
LGORT
LABST
FROM MARD
INTO TABLE IT_MARD
FOR ALL ENTRIES IN IT_MARC
WHERE WERKS = IT_MARC-WERKS.

ENDIF.
ENDIF.

LOOP AT IT_MARA.
IT_FINAL-MATNR = IT_MARA-MATNR.
IT_FINAL-MTART = IT_MARA-MTART.
IT_FINAL-MEINS = IT_MARA-MEINS.
READ TABLE IT_MARC WITH KEY MATNR = IT_MARA-MATNR.
IT_FINAL-WERKS = IT_MARC-WERKS.
IT_FINAL-PSTAT = IT_MARC-PSTAT.
READ TABLE IT_MARD WITH KEY WERKS = IT_MARC-WERKS.
IT_FINAL-LABST = IT_MARD-LABST.
IT_FINAL-LGORT = IT_MARD-LGORT.
READ TABLE IT_MAKT WITH KEY MATNR = IT_MARA-MATNR.
IT_FINAL-MAKTX = IT_MAKT-MAKTX.
IT_FINAL-MAKTG = IT_MAKT-MAKTG.
APPEND IT_FINAL.
ENDLOOP.

format color 7.
write:/1 'Material no',
20 'Material type',
30 'unit',
40 'plant',
50 'status' ,
60 'storage loc',
70 'stock',
80 'material desc'.
format color off.

LOOP AT IT_FINAL.
WRITE:/10 IT_FINAL-MATNR,
20 IT_FINAL-MTART,
30 IT_FINAL-MEINS,
40 IT_FINAL-WERKS,
50 IT_FINAL-PSTAT,
60 IT_FINAL-LGORT,
70 IT_FINAL-LABST,
80 IT_FINAL-MAKTX.
ENDLOOP.

No comments:

Post a Comment