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

Deleting from Internal Table (dynamic)

Former Member
0 Likes
816

Hi,

I have an Internal table, which will contain daily movements for plants per material.

The internal table will contain 4 plants per material, with more than 1 material.

Now, i have four columns. If all of those columns for that material and for all plants for that material equal zero, i want to delete the specific record.

For example

Material Plant Daily 1 Daily 2 Daily 3 Daily 4

-


102 1 0 0 0 0

102 2 0 0 0 0

102 3 0 0 0 0

102 4 0 0 0 0

So, these 4 records should be deleted. However, say on of the daily columns will equal 1, then keep the 4 records (they are linked by material and plant.)

How do I do this?

Points will be rewarded and all help will be greatly appreciated.

Thanks,

John

Hi,

I have an Internal table, which will contain daily movements for plants per material.

The internal table will contain 4 plants per material, with more than 1 material.

Now, i have four columns. If all of those columns for that material and for all plants for that material equal zero, i want to delete the specific record.

For example

Material Plant Daily 1 Daily 2 Daily 3 Daily 4

-


102 1 0 0 0 0

102 2 0 0 0 0

102 3 0 0 0 0

102 4 0 0 0 0

So, these 4 records should be deleted. However, say on of the daily columns will equal 1, then keep the 4 records (they are linked by material and plant.)

How do I do this?

Points will be rewarded and all help will be greatly appreciated.

Thanks,

John

6 REPLIES 6
Read only

Former Member
0 Likes
779

Its a dynamic table right ??

cnt = 2. "This is because to skip 1st 2 fields in ASSIGN

Loop at <itab> into <wa>.

DO 4 times.

cnt = cnt + 1.

assign component cnt of structure <wa> into <fs>.

concatenate value <fs> into value.

ENDDO.

if value eq 0000.

delete <itab>.

endif.

endloop.

If the fields daily1/2/3/4 is non-char then add <fs> value into variable & check if value eq 0.

Read only

Former Member
0 Likes
779

Is this what you are looking for?

DELETE itab WHERE daily1 = 0 AND daily2 = 0 AND daily3 = 0 AND daily4 = 0.

Read only

0 Likes
779

Sort of. But it has to look and see if the other records with the same MATNR are also empty. If all are empty for the MATNR, then do that. Otherwise, even the empty ones need to be displayed.

Read only

0 Likes
779

Loop at itab.

At new matnr. "Reset the count for evry new material no

cnt = 0.

endat.

if cnt = 0. "Add daily1/2/3/4 fields of all materials

cnt = cnt + itab-daily1 + itab-daily2 + itab-daily3 + itab-daily4.

endif.

at end of matnr. "If count = 0,delete all same materials

if cnt = 0.

delete itab where matnr = itab-matnr.

endif.

endat.

Endloop.

Read only

0 Likes
779

Check this.


DATA: BEGIN OF itab OCCURS 0,
        matnr LIKE marc-matnr,
        werks LIKE marc-werks,
        daily1 TYPE i,
        daily2 TYPE i,
        daily3 TYPE i,
        daily4 TYPE i.
DATA: END OF itab.

DATA: itab_per_matnr LIKE itab OCCURS 0 WITH HEADER LINE,
      wa_itab        LIKE itab.

itab_per_matnr[] = itab[].
LOOP AT itab INTO wa_itab.
*-- check if there is at least one non-zero record for this material
  LOOP AT itab_per_matnr WHERE matnr = wa_itab-matnr
                           AND ( daily1 > 0 OR
                                 daily2 > 0 OR
                                 daily3 > 0 OR
                                 daily4 > 0 ).
    EXIT
  ENDLOOP.
  IF sy-subrc <> 0.
    DELETE itab WHERE matnr = wa_itab-matnr.
  ENDIF.
ENDLOOP.

Read only

former_member194669
Active Contributor
0 Likes
779

Hi,

Check this.,


sort itab by material

loop at itab.
 
  at new of matnr.
     move 'Y' to v_flg.
     move 'Y' to v_dflg
  endat.
  if v_flg eq 'Y'.
    move itab-matnr to v_matnr.
  endif.
  if itab-daily1 ne 0 and itab-dail2 ne 0
     and itab-daily3 ne 0 and itab-daily4 ne 0.
     move 'N' v_dlfg.
  endif.
  at end of matnr.
    if v_dflg eq 'Y'.
       delete itab where matnr eq v_matnr.
    endif.
    clear : v_flg, v_dlfg.
  endat.
  
endloop.

aRs