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

How to do this Please help

Former Member
0 Likes
812

I have a internal table with fields mblnr bwart matnr menge.

The records are like this.

mblnr bwart matnr menge

1) 12000001 10 000001 112

2) 12000001 10 000001 112

3) 12000004 10 000001 112

4) 12000006 10 000001 112

5) 12000011 10 000001 112

6) 12000011 50 000001 112

7) 12000011 51 000001 112

😎 12000021 10 000001 112

9) 12000022 10 000001 112

10) 12000022 51 000001 112

11) 12000030 10 000001 112

here mvt types 10 - 50,51 are combination,which we use for bom. if we pass material of bwart type 10 we get materials of type 50 and 51.

ie for example if we pass car we get parts of car like tyres,engine etc.

so if a material doc which does not have atleast 50 or 51 for 10 mvt type that documents should be deleted.

For example in above records 1 and 2 is not needed because they dont have combination like 50 or 51.

so they should be deleted.

Record 5,6 and 7 should be there because they have a combination for mvt type 10 we have 50 and 51.

record 8 should be deleted. and record 9 and 10 should be there.

Below I had a code for deleting the records if the material doc is not repeated ie if it is unique.

it works fine for my requirement , but in some cases it wont.

For example the record 1 and 2 we have same doc number but dont have the combination mvt types either 50 or 51 for 10.

so my above code wont delete this 2 records because they are having same doc number ie they are repeated.

So please modify my code so that i will achieve my requirement ie deleting the records which dont having combination of 10 and ( 50 or 51).

SO please tell me how to do. Thanks for all the replies.

Thanks for all the replies.

I have a internal table with fields mblnr bwart matnr menge.

The records are like this.

mblnr bwart matnr menge

1) 12000001 10 000001 112

2) 12000001 10 000001 112

3) 12000004 10 000001 112

4) 12000006 10 000001 112

5) 12000011 10 000001 112

6) 12000011 50 000001 112

7) 12000011 51 000001 112

😎 12000021 10 000001 112

9) 12000022 10 000001 112

10) 12000022 51 000001 112

11) 12000030 10 000001 112

here mvt types 10 - 50,51 are combination,which we use for bom. if we pass material of bwart type 10 we get materials of type 50 and 51.

ie for example if we pass car we get parts of car like tyres,engine etc.

so if a material doc which does not have atleast 50 or 51 for 10 mvt type that documents should be deleted.

For example in above records 1 and 2 is not needed because they dont have combination like 50 or 51.

so they should be deleted.

Record 5,6 and 7 should be there because they have a combination for mvt type 10 we have 50 and 51.

record 8 should be deleted. and record 9 and 10 should be there.

Below I had a code for deleting the records if the material doc is not repeated ie if it is unique.

it works fine for my requirement , but in some cases it wont.

For example the record 1 and 2 we have same doc number but dont have the combination mvt types either 50 or 51 for 10.

so my above code wont delete this 2 records because they are having same doc number ie they are repeated.

So please modify my code so that i will achieve my requirement ie deleting the records which dont having combination of 10 and ( 50 or 51).

SO please tell me how to do. Thanks for all the replies.

Thanks for all the replies.

4 REPLIES 4
Read only

Former Member
0 Likes
780

Declare an another internal table with same type. Copy the same data into the second internal table.

sort itab2 by mblnr.

loop at itab2.

at new mblnr.

read itab1 with key mblnr = itab2-mblnr bwart ='10'.

if sy-subrc eq 0.

read itab1 with key mblnr = itab2-mblnr bwart ='50'.

if sy-subrc ne 0.

read itab1 with key mblnr = itab2-mblnr bwart ='51'.

if sy-subrc ne 0.

delete from itab1 where mblnr = itab2-mblnr.

endif.

endif.

endif.

endloop.

reward the points if it helpful to you

Read only

Former Member
0 Likes
780


types : begin of t_data,
            mblnr type ...,
            bwart type..,
            matnr type,
             menge type...,
            end of t_data.

data : itab type standard table of t_data,
        watab type t_data,
         itemp type standard table of t_data.

" Assuming ITAB is already populated with those records

itemp[] = itab[].

loop at itab.
read table itemp with key mblnr = itab-mblnr
                                     bwart = 50.
if sy-subrc eq 0.
continue.
else.
read table itemp with key mblnr = itab-mblnr
                                     bwart = 51.
if sy-subrc eq 0.
continue.
else.
delete itab where mblnr = itab-mblnr.
endif.

endloop.

Read only

Former Member
0 Likes
780

Suppose itab is your internal table.

data : itab1 like standard table of itab with header line.

data : itab2 like standard table of itab with header line.

<b>to delete same records.</b>

sort itab by mblnr bwart matnr menge.

Delete adjacent duplicates from itab comparing mblnr bwart matnr menge.

<b>copying itab to itab1.</b>

itab1[] = itab[].

<b>You can avoid the below two lines " but i recommand to use these for fast access"</b>

<b>delete itab where bwart ne '10'.

delete itab1 where bwart eq '10'.</b>

LOOP AT ITAB where bwart eq '10'.

read table itab1 with key mblnr = itab-mblnr.

if bwart = '50' or bwart eq '51'.

move-corresponding itab1 to itab2.

append itab2.

move-corresponding itab to itab2.

append itab2.

endif.

endloop.

itab2 is your required table.

reward if useful.

Regards

Amit Singla

Read only

rainer_hbenthal
Active Contributor
0 Likes
780

REPORT z.

DEFINE fill.
  wa_list-mblnr = &1.
  wa_list-bwart = &2.
  wa_list-matnr = &3.
  wa_list-menge = &4.

  append wa_list to it_list.
END-OF-DEFINITION.

TYPES:
  BEGIN OF t_list,
    mblnr(08),
    bwart(02),
    matnr(06),
    menge(03),
  END OF t_list.

DATA:
  wa_list TYPE t_list,
  it_list TYPE STANDARD TABLE OF t_list,
  ipos TYPE i.

FIELD-SYMBOLS:
  <p> TYPE t_list.

fill '12000001' '10' '000001' '112'.
fill '12000001' '10' '000001' '112'.
fill '12000004' '10' '000001' '112'.
fill '12000006' '10' '000001' '112'.
fill '12000011' '10' '000001' '112'.
fill '12000011' '50' '000001' '112'.
fill '12000011' '51' '000001' '112'.
fill '12000021' '10' '000001' '112'.
fill '12000022' '10' '000001' '112'.
fill '12000022' '51' '000001' '112'.
fill '12000030' '10' '000001' '112'.

LOOP AT it_list ASSIGNING <p>.
  WRITE:/ <p>-mblnr, <p>-bwart, <p>-matnr, <p>-menge.
ENDLOOP.

LOOP AT it_list ASSIGNING <p>.
  ipos = sy-tabix.

  IF <p>-bwart <> '50' AND <p>-bwart <> '51'.
    READ TABLE it_list WITH KEY mblnr = <p>-mblnr
                                bwart = '50'
      INTO wa_list.
    IF sy-subrc > 0.
      READ TABLE it_list WITH KEY mblnr = <p>-mblnr
                                  bwart = '51'
        INTO wa_list.

      IF sy-subrc > 0.
        DELETE it_list INDEX ipos.
      ENDIF.

    ENDIF.

  ENDIF.
ENDLOOP.

WRITE:/ sy-uline.

LOOP AT it_list ASSIGNING <p>.
  WRITE:/ <p>-mblnr, <p>-bwart, <p>-matnr, <p>-menge.
ENDLOOP.