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 delete internal table rows

Former Member
0 Likes
5,416

Hello,

Here i have to delete internal table production order column based on hold column.

If you see the attached .jpeg file you will get clear idea about my issue.

I tried by giving this DELETE i_final[] WHERE hind IS not INITIAL. but it does not satisfy my requirement.


If hold column is marked with X then entire production order has to be deleted.

Please suggest me how...

1 ACCEPTED SOLUTION
Read only

kumud
Active Contributor
0 Likes
4,603

Hi,

If the requirement is to delete all the rows of an order if Hold is marked 'X' even once, I tried with the below code and it worked fine.

   TYPES: BEGIN OF tp_tab,
                order TYPE char20,
                hold TYPE flag,
                text TYPE char10,
               END OF tp_tab.

TYPES: BEGIN OF tp_tab1,
             t1 TYPE tp_tab,
             delete TYPE char1,
            END OF tp_tab1.

DATA: t_tab TYPE STANDARD TABLE OF tp_tab,
           t_tab1 TYPE STANDARD TABLE OF tp_tab1,
           w_tab TYPE tp_tab,
           w_tab1 TYPE tp_tab1.

FIELD-SYMBOLS: <fs_tab> TYPE tp_tab,
                           <fs_tab1> TYPE tp_tab1.

   LOOP AT t_tab ASSIGNING <fs_tab> WHERE hold EQ 'X'.
       w_tab1-t1-order = <fs_tab>-order.
       w_tab1-t1-hold  = <fs_tab>-hold.
       w_tab1-t1-text  = <fs_tab>-text.
       w_tab1-delete = 'X'.
       APPEND w_tab1 TO t_tab1.
       CLEAR w_tab1.
ENDLOOP.
UNASSIGN <fs_tab>.

LOOP AT t_tab1 ASSIGNING <fs_tab1> WHERE delete EQ 'X'.
  DELETE t_tab WHERE order = <fs_tab1>-t1-order.
ENDLOOP.

UNASSIGN <fs_tab1>.

You may take care of declaring constants as required.

Regards,

Kumud

Hello,

Here i have to delete internal table production order column based on hold column.

If you see the attached .jpeg file you will get clear idea about my issue.

I tried by giving this DELETE i_final[] WHERE hind IS not INITIAL. but it does not satisfy my requirement.


If hold column is marked with X then entire production order has to be deleted.

Please suggest me how...

26 REPLIES 26
Read only

former_member199125
Active Contributor
0 Likes
4,603

It should work,

otherwise try

delete i_final where hindi = 'X'.

Regards

Srinivas    

Read only

0 Likes
4,603

Hello Srinivas,

I tried as u said but the is same,

As per my logic & your logic the only specific hind column are deleted where it is having "X"

but my requirement is to delete entire production order with reference to hind column.

Read only

0 Likes
4,603

Ah.. Column HOLD became HIND and HIND became HINDI

Read only

Former Member
0 Likes
4,603

Hello,

First get the production order number where hind is not initial. and then delete all the entries for that order number.

I hope it helps.

Thanks.

Read only

Private_Member_49934
Product and Topic Expert
Product and Topic Expert
0 Likes
4,603

Loop at i_final[] assigning <fs_final> where HOLD = 'X'.

DELETE IT_FINAL WHERE  PRODUCTION_ORDER = <FS_FINAL>-PRODUCTION_ORDER.

ENDLOOP.

Read only

0 Likes
4,603

Hi,

You requirement is interesting.

What you can do is create a list of Production order that is need to deleted in new internal table and delete these from the I_FINAL table.

I_DELL[] = I_FINAL[].

DELETE I_DELL[] WHERE HOLD IS INITIAL.

SORT the I_DELL[] by Production order.

Delete the adjacent duplicate.

Now you 'll have the list of Production order that are needed to delete.

so for this you can do

Loop at I_FINAL INTO <WA>.

DELETE I_FINAL[] WHERE PRDORD = <wa>-prdord.

ENDLOOP.

Regards,

Rakesh

Read only

0 Likes
4,603

Hello Rakesh

Thanks for your response,,... I tried the code which is very similar.

But still i could not reach the requirement.

sort i_final by hind DESCENDING.

     lt_final[] = i_final[].

     loop at i_final  into wa_final where hind = 'X'.

       loop at lt_final  into wa1_final where aufnr = wa_final-aufnr.

         append wa1_final to lt1_final.

         clear: wa1_final.

       endloop.

       clear:wa_final.

     endloop.

     clear i_final[].

     FREE  i_final[].

     i_final[] = lt1_final[].

     SORT i_final ASCENDING by aufnr ktsch ltxa1 lmnga.

     delete ADJACENT DUPLICATES FROM  i_final COMPARING aufnr vornr.

     clear lt1_final[].

     free  lt1_final[].

   ENDIF.

Suggest me anything more i can do here.

Read only

0 Likes
4,603

Hi,

Instead of this you can write the like this it will works.

lt_final[] = i_final[].

Delete   lt_final[] where where hind is not intial.

sort lt_final by aufnr.

delete ADJACENT DUPLICATES FROM  lt_final COMPARING aufnr.

Loop at lt_final into <wa>.

delete i_final[] where aufnr = <wa>-aufnr.

endloop.

now you have the desire result in i_final[] .

Regards,

Rakesh

Read only

0 Likes
4,603

Still i output is same only the specific rows are getting deleted,

Here there are 3 columns

1. Production order

2. Hold

3. Standard Text (which is like Line item)

For Each production order there can be several hold and standard text,

Here If any hold column is there with "X" with reference to production order then entire production order and other details like standard text also has to be deleted.

Once see this new picture.

Here 110076839 and 110076862 and all the details has to be deleted because hold column is having "X" with reference that production order and 110076836 should remain as it is because no hold with "X".

I am explaining briefly because may be you could not get what was saying.

Read only

0 Likes
4,603

hi,

Can you send me the code that you r using.

Regards,

Rakesh

Read only

0 Likes
4,603

Hello rakesh

I already given logic which i have maintained in my program.

Read only

0 Likes
4,603

Hi,

Have you tried my logic..it will work or you can go for Kumud's logic both will work

Regards,

Rakesh

Read only

0 Likes
4,603

hi Kris nh,

want to confirm your requirement first.

1 production order no will have several entries, rigt?

each entry will have a hold.

if either of this production order no sets hold = 'X', all of these production order should be deleted, right?

in picture you gave, at last, only order no 110076836 left, right?

please reply.

Read only

0 Likes
4,603

Hai rakesh,

I tried with your logic but still i could not get to my requirement.

Now i am trying to with kumud logic.

It is a round 2500 lines of program with other fields and other logic  that is the reason  i did not paste here.

Thanks for your effect i will try kumud logic and will come back....

Read only

0 Likes
4,603

Yes Yang,

You are right,

production order no will have several entries,

each entry will have a hold.

if either of this production order no sets hold = 'X',

all of these production order should be deleted.

and order no 110076836 should not change anything because for this order does not have hold = 'X'.


Read only

0 Likes
4,603

ok, give u sample code.

assuming inter table is A.

delete A where hold <> 'X'.

table B = A.

sort B by production order.

DELETE ADJACENT DUPLICATES FROM B COMPARING production order no.

base on table B create a range.

LOOP AT B.

RANGE-SING = 'E'.

RANGE-OPTION = 'EQ'.

RANGE-LOW = B-production order no.

append range.

ENDLOOP.

delete A where production order no in RANGE.

done. please use it.

Read only

Former Member
0 Likes
4,603

sort i_final by Production_order hind.


Loop at i_final.

DELETE i_final where hind = 'X'.

ENDLOOP


Read only

former_member282968
Contributor
0 Likes
4,603

Check if this helps:

Hi Kris,

   types:BEGIN OF s_po,
            po   type char10,
            hold type char1,
            end of s_po.

data:it_s_po type table of s_po,
     wa_s_po type          s_po.

wa_s_po-po   = '110076836'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076836'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076836'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076839'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076839'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076839'.
wa_s_po-hold = ' '.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076862'.
wa_s_po-hold = ' '.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076862'.
wa_s_po-hold = ' '.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076862'.
wa_s_po-hold = ' '.
append wa_s_po to it_s_po.


loop at it_s_po into wa_s_po.
check wa_s_po-hold = 'X'.
delete it_s_po where po = wa_s_po-po.
endloop.

loop at it_s_po into wa_s_po.
write😕 wa_s_po-po,wa_s_po-hold.
endloop.

*output
110076862
110076862
110076862

With regards,

Read only

Former Member
0 Likes
4,603

try to do which i send logic 101% it will work

Read only

0 Likes
4,603

Hello Krupa,

If your dont mind anything please thoroughly check my issue.

The logic which has been given by you will not match to my requirement.

Read only

kumud
Active Contributor
0 Likes
4,604

Hi,

If the requirement is to delete all the rows of an order if Hold is marked 'X' even once, I tried with the below code and it worked fine.

   TYPES: BEGIN OF tp_tab,
                order TYPE char20,
                hold TYPE flag,
                text TYPE char10,
               END OF tp_tab.

TYPES: BEGIN OF tp_tab1,
             t1 TYPE tp_tab,
             delete TYPE char1,
            END OF tp_tab1.

DATA: t_tab TYPE STANDARD TABLE OF tp_tab,
           t_tab1 TYPE STANDARD TABLE OF tp_tab1,
           w_tab TYPE tp_tab,
           w_tab1 TYPE tp_tab1.

FIELD-SYMBOLS: <fs_tab> TYPE tp_tab,
                           <fs_tab1> TYPE tp_tab1.

   LOOP AT t_tab ASSIGNING <fs_tab> WHERE hold EQ 'X'.
       w_tab1-t1-order = <fs_tab>-order.
       w_tab1-t1-hold  = <fs_tab>-hold.
       w_tab1-t1-text  = <fs_tab>-text.
       w_tab1-delete = 'X'.
       APPEND w_tab1 TO t_tab1.
       CLEAR w_tab1.
ENDLOOP.
UNASSIGN <fs_tab>.

LOOP AT t_tab1 ASSIGNING <fs_tab1> WHERE delete EQ 'X'.
  DELETE t_tab WHERE order = <fs_tab1>-t1-order.
ENDLOOP.

UNASSIGN <fs_tab1>.

You may take care of declaring constants as required.

Regards,

Kumud

Read only

Former Member
0 Likes
4,603

Thanks Kumad,

Your idea was great.

It worked for me..by creating that indicator (delete) in the types

Your logic helped me a lot.

Thanks for your efforts.

Read only

keyur_pawar
Active Participant
0 Likes
4,603

Hi,

Try following code,

100% working.....

REPORT  ZDELETE_ITAB.


types: begin of s_tab,
   po type int4,
   hold type char10,
   tkey type char10,
   END OF s_tab.

   DATA: itab type table of s_tab,
         wa   type s_tab.

   wa-po   = 100001.
   wa-hold = ' '.
   wa-tkey = 's001'.
   append wa to itab.


   wa-po   = 100002.
   wa-hold = 'X'.
   wa-tkey = 's002'.
   append wa to itab.


   wa-po   = 100003.
   wa-hold = ' '.
   wa-tkey = 's003'.
   append wa to itab.


   wa-po   = 100004.
   wa-hold = 'X'.
   wa-tkey = 's004'.
   append wa to itab.

   wa-po   = 100004.
   wa-hold = ''.
   wa-tkey = 's005'.
   append wa to itab.

   wa-po   = 100004.
   wa-hold = ''.
   wa-tkey = 's006'.
   append wa to itab.


data : pono type char10.

LOOP AT itab into wa.
   IF wa-hold = 'X'.
     pono = wa-po.
   ENDIF.

   delete itab[] where po = pono.

ENDLOOP.



   LOOP AT itab into wa.
     write:/  wa-po, wa-hold, wa-tkey.
   ENDLOOP.

Regards,

KP

Read only

Former Member
0 Likes
4,603

Loop at IT_final into wa_final where hind = 'X'.

delete it_final where pono = wa_final-pono.

Endloop.

This should work!

Read only

Former Member
0 Likes
4,603

DELETE i_final WHERE hold = 'X'.

Read only

Former Member
0 Likes
4,603

Hi Kris,

This logic will definitely work.

   types:BEGIN OF s_po,
            po   type char10,
            hold type char1,
            end of s_po.

data:it_s_po type table of s_po,
     wa_s_po type          s_po,
     wa_s_po1 type          s_po.

wa_s_po-po   = '110076845'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076845'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076839'.
wa_s_po-hold = 'X'.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076839'.
wa_s_po-hold = ' '.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076862'.
wa_s_po-hold = ' '.
append wa_s_po to it_s_po.

wa_s_po-po   = '110076862'.
wa_s_po-hold = ' '.
append wa_s_po to it_s_po.

sort it_s_po by po.

loop at it_s_po into wa_s_po.

clear wa_s_po1.
read table it_s_po into wa_s_po1 with key po = wa_s_po-po
                                          hold = 'X'.

if sy-subrc eq 0.

delete it_s_po where po = wa_s_po-po.

endif.
clear: wa_s_po , wa_s_po1.
endloop.

Regards,

Ibrahim