‎2006 Nov 20 12:13 AM
Hi,
Can some one help me with the sample code or a prototype or logic in:
Identifying the List of materials (MATNR) which are unique to Plant number(WERKS) 0004 only & Non shared with other Plants.
Thank you.
‎2006 Nov 20 12:19 AM
You can use table MARC. First do a SELECT and get all of the materials for plant 4. Then loop at this internal table and do a select against MARC with that material, then check how many records where retrieved, if more than one, then you know that that material is extended to other plants, not just plant 4.
data: imarc type table of marc with header line.
data: imarcx type table of marc with header line.
data: marc_lines type i.
select * into table imarc from marc
where werks = '0004'.
loop at imarc.
refresh imarcx.
select * into table imarcx from marc
where matnr = imarc-matnr.
describe table imarcx lines marc_lines.
if marc_lines > 1.
write:/ 'Material is extended to other plants, not just 0004'.
elseif marc_lines = 1.
write:/ 'Material is extended to plant 0004 only'.
endif.
endloop.Regards,
Rich Heilman
‎2006 Nov 20 12:19 AM
You can use table MARC. First do a SELECT and get all of the materials for plant 4. Then loop at this internal table and do a select against MARC with that material, then check how many records where retrieved, if more than one, then you know that that material is extended to other plants, not just plant 4.
data: imarc type table of marc with header line.
data: imarcx type table of marc with header line.
data: marc_lines type i.
select * into table imarc from marc
where werks = '0004'.
loop at imarc.
refresh imarcx.
select * into table imarcx from marc
where matnr = imarc-matnr.
describe table imarcx lines marc_lines.
if marc_lines > 1.
write:/ 'Material is extended to other plants, not just 0004'.
elseif marc_lines = 1.
write:/ 'Material is extended to plant 0004 only'.
endif.
endloop.Regards,
Rich Heilman
‎2006 Nov 20 1:57 AM
Rich:
When using select * into table inside a loop, is the REFRESH still needed?
~Suresh
‎2006 Nov 20 3:07 AM
Thank you Rich!!
That was awesome. I really didn,t get the thought of 'DESCRIBE'...
Anyways thank you once again for the detailed code.
‎2006 Nov 20 3:11 AM
Thanks to others too.
But I felt much comfortable with his code i ment by RICH...
Anyways I'm rewardin you guys too .
‎2006 Nov 20 2:00 PM
‎2006 Nov 20 2:34 AM
Hi Sekhar
Please check another way of extracting the same.
TABLES: MARC.
TYPES: BEGIN OF T_MARC,
MATNR TYPE MATNR,
COUNT TYPE I,
END OF T_MARC.
DATA: IT_MARC TYPE TABLE OF T_MARC.
PARAMETERS: P_WERKS TYPE WERKS_D OBLIGATORY.
SELECT MATNR COUNT( * ) INTO TABLE IT_MARC FROM MARC AS A
WHERE EXISTS ( SELECT * FROM MARC WHERE MATNR = A~MATNR
AND WERKS = P_WERKS )
GROUP BY MATNR
HAVING COUNT( * ) EQ 1.
Kind Regards
Eswar
‎2006 Nov 20 3:05 AM
hI,
TRY THIS CODE.
tables: mara.
data: itab like marC occurs 0 with header line.
DATA: ITAB_TMP LIKE MARC OCCURS 0 WITH HEADER LINE.
selection-screen: begin of block blk1 with frame title text-001.
select-options: s_MATNR for mara-matnr.
selection-screen end of block blk1.
start-of-selection.
select * from marC into table itab
where matnr in s_MATNR.
SORT ITAB.
ITAB_TMP[] = ITAB[].
SORT ITAB_TMP.
loop at itab.
LOOP AT ITAB_TMP WHERE MATNR = ITAB-MATNR AND
WERKS <> ITAB-WERKS.
DELETE ITAB WHERE MATNR = ITAB-MATNR.
EXIT.
ENDLOOP.
endloop.
LOOP AT ITAB.
WRITE : / ITAB-MATNR,20 ITAB-WERKS.
ENDLOOP.
Note: Above code is sample only. needs to be tuned as per the requirement.
regards,
sundaramj.