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

Select Material by Material Type

Former Member
0 Likes
944

I have Material Number in an internal table and not material type.i want to delete all the material Number from the table whose material type not equal to 'ZFRT'.How i can i do that? Kindly help me.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
699

Well, it would be easier and better to have Material Type within the internal table if you have the chance to do that, or even you could do this condition when selecting the materials from the database into the internal table, but if you truely have no other option, then i guess you can do this.



data: xmara type mara

loop at itab.

   select single * from mara into xmara
               where matnr = itab-matnr
                   and mtart = 'ZFRT'.
   if sy-subrc <> 0.
     delete itab.
     continue.
    endif.

endloop.

REgards,

Rich Heilman

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
700

Well, it would be easier and better to have Material Type within the internal table if you have the chance to do that, or even you could do this condition when selecting the materials from the database into the internal table, but if you truely have no other option, then i guess you can do this.



data: xmara type mara

loop at itab.

   select single * from mara into xmara
               where matnr = itab-matnr
                   and mtart = 'ZFRT'.
   if sy-subrc <> 0.
     delete itab.
     continue.
    endif.

endloop.

REgards,

Rich Heilman

Read only

0 Likes
699

Rich Heilman

It Works Perfect....

Thanks

Read only

Former Member
0 Likes
699

Hi,

If you have material number in it_itab, then


TYPES : BEGIN OF x_mara,
          matnr TYPE matnr,
          mtart TYPE mtart,
        END   OF x_mara.

DATA : it_mara TYPE TABLE OF x_mara.

SELECT matnr mtart
  FROM mara
  INTO TABLE it_mara
  FOR ALL ENTRIES IN it_itab
  WHERE matnr = it_itab-matnr
    AND mtart = 'ZFRT'.

IF sy-subrc = 0.
  DELETE it_itab FROM it_mara.
ELSE.
  REFRESH : it_mara.
ENDIF.

Reward points if the answer is helpful.

Regards,

Mukul

Read only

Former Member
0 Likes
699

Hi,

If you have material number in it_itab, then


TYPES : BEGIN OF x_mara,
          matnr TYPE matnr,
          mtart TYPE mtart,
        END   OF x_mara.
 
DATA : it_mara TYPE TABLE OF x_mara.
 
SELECT matnr mtart
  FROM mara
  INTO TABLE it_mara
  FOR ALL ENTRIES IN it_itab
  WHERE matnr = it_itab-matnr
    AND mtart = 'ZFRT'.
 
IF sy-subrc = 0.
  DELETE it_itab FROM it_mara.
ELSE.
  REFRESH : it_mara.
ENDIF.

Reward points if the answer is helpful.

Regards,

Mukul