08-13-2009 5:37 PM
Hi All,
I would like in my abap report to check efficiently each line item in the Purchase order and make sure each line item should have the same material group.
Any ideas appreciated.
Meghna
08-13-2009 6:36 PM
You can gather all the PO items from the table EKPO into a STANDARD TABLE like the the EKPO. For each line of the table LT_EKPO you will searching into the MARA (MARA-MATNR = EKPO-MATNR) and you will collect the MARA-MATKL into an internal table that will have only one field, the Material Group. At the end you will check how many lines has the internal table. Becouse you wil you the COLLECT instead of APPEND, if the PO has only one Material Group then this table should have only one line.
Check the following code (it has been written by hard)
With Regards
George
-
TABLES: MARA, EKPO.
TYPES: BEGIN OF TY_GROUP,
MATKL LIKE MARA-MATKL,
END OF TY_GROUP.
DATA: lt_group TYPE STANDARD TABLE OF TY_GROUP,
wa_group LIKE LINE OF lt_group.
DATA: lt_ekpo LIKE EKPO occurs 0,
wa_ekpo LIKE LINE OF lt_ekpo,
lines_count TYPE I.
SELECT * FROM EKPO INTO TABLE lt_ekpo
WHERE EBELN = p_ebeln.
SORT lt_ekpo.
LOOP AT lt_ekpo INTO wa_ekpo.
CLEAR MARA.
SELECT SINGLE * FROM MARA
WHERE MATNR = wa_ekpo-matnr.
WA_GROUP-MATKL = MARA-MATKL.
COLLECT wa_group INTO lt_group.
CLEAR wa_group.
ENDLOOP.
DESCRIBE TABLE lt_group LINES lines_count.
IF lines_count > 1.
DO SOMETHING.
ENDIF.
08-13-2009 7:05 PM
08-13-2009 7:21 PM
Hi maghana
There is a small modification in Michale code
TABLES: MARA, EKPO.
TYPES: BEGIN OF TY_GROUP,
matnr like mara-matnr,
MATKL LIKE MARA-MATKL,
END OF TY_GROUP.
DATA: lt_group TYPE STANDARD TABLE OF TY_GROUP,
wa_group LIKE LINE OF lt_group.
DATA: lt_ekpo LIKE EKPO occurs 0,
wa_ekpo LIKE LINE OF lt_ekpo,
lines_count TYPE I.
SELECT * FROM EKPO INTO TABLE lt_ekpo
WHERE EBELN = p_ebeln.
SORT lt_ekpo.
LOOP AT lt_ekpo INTO wa_ekpo.
CLEAR MARA.
SELECT SINGLE * FROM MARA
WHERE MATNR = wa_ekpo-matnr.
WA_GROUP-matnr = MARA-matnr.
WA_GROUP-MATKL = MARA-MATKL.
COLLECT wa_group INTO lt_group.
CLEAR wa_group.
ENDLOOP.
DESCRIBE TABLE lt_group LINES lines_count.
IF lines_count > 1.
DO SOMETHING.
ENDIF.
then it will not add any duplicates