Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Extracting MATNR:

Former Member
0 Likes
1,831

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.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,627

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

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,628

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

Read only

0 Likes
1,627

Rich:

When using select * into table inside a loop, is the REFRESH still needed?

~Suresh

Read only

0 Likes
1,627

Thank you Rich!!

That was awesome. I really didn,t get the thought of 'DESCRIBE'...

Anyways thank you once again for the detailed code.

Read only

0 Likes
1,627

Thanks to others too.

But I felt much comfortable with his code i ment by RICH...

Anyways I'm rewardin you guys too .

Read only

0 Likes
1,627

Suresh, no the REFRESH is not needed. It is just one of my habits to clear stuff.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,627

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

Read only

Former Member
0 Likes
1,627

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.