求相同物料描述不同料號的原始碼

qiujun發表於2007-03-07

一個比較精典的程式,可以求出一個產品(同一描述)編了多個料號的情況。

REPORT ZJZTEST02.

DATA: BEGIN OF WA_MARA,
MAKTX TYPE MAKT-MAKTX,
MATNR TYPE MARA-MATNR,
END OF WA_MARA.
DATA: G_TABIX LIKE SY-TABIX,
G_LINES TYPE I.
DATA IT_MARA LIKE TABLE OF WA_MARA WITH HEADER LINE.
DATA IT_RESULT LIKE TABLE OF WA_MARA WITH HEADER LINE.

SELECT MAKT~MAKTX MARA~MATNR
FROM MARA
INNER JOIN MAKT
ON MARA~MATNR = MAKT~MATNR AND MAKT~SPRAS = SY-LANGU
INTO CORRESPONDING FIELDS OF TABLE IT_MARA.

SORT IT_MARA BY MAKTX MATNR.

LOOP AT IT_MARA.
G_TABIX = SY-TABIX.
AT NEW MAKTX.
CLEAR WA_MARA.
READ TABLE IT_MARA INDEX G_TABIX INTO WA_MARA.
CONTINUE.
ENDAT.
IF WA_MARA IS NOT INITIAL.
IT_RESULT = WA_MARA.
APPEND IT_RESULT.
CLEAR WA_MARA.
ENDIF.
IT_RESULT = IT_MARA.
APPEND IT_RESULT.
ENDLOOP.

LOOP AT IT_RESULT.
WRITE: / IT_RESULT-MATNR, IT_RESULT-MAKTX.
ENDLOOP.

DESCRIBE TABLE IT_RESULT LINES G_LINES.
WRITE G_LINES.

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90072/viewspace-903132/,如需轉載,請註明出處,否則將追究法律責任。

相關文章