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

Delete rows from an internal table

former_member206394
Active Participant
0 Likes
2,283

i have two internal tables.

say: internal_table1 and internal_table2 with content as follows:

internal_table1 has only one field i.e., objid

internal_table2 it of type qcat_stru.

internal_table2 has been filled with data that has been extracted with L-D-E evaluation path.(so it contains otypes of L, D, E, P).

Where as internal_table1 is filled for all entries in internal_table2 with otype = 'E' and relat = 024 and sclas = 'F' and sobid in s_loc(select options).

Now, i need to delete rows from internal_table2 where otype = 'E' and objid other than those in internal_table1.  Can anyone help me in this regard.

1 ACCEPTED SOLUTION
Read only

former_member196490
Active Participant
0 Likes
2,246

Try this.

Loop at internal_table_2.

l_tabix = sy-tabix.

Read table internal_table_1 with key objid = internal_table_2-objid.

If sy-subrc= 0.

   delete internal_table_2 index l_tabix.

endif.

endloop.

15 REPLIES 15
Read only

Former Member
0 Likes
2,246

What have you tried so far?

Rob

Read only

Former Member
0 Likes
2,246

LOOP AT itab2 into ls_itab2.

     IF ls_itab2-otype = 'E'.

          CONTINUE.

     ENDIF.

     READ TABLE itab1 TRANSPORTING NO FIELDS

          WITH KEY objid = ls_itab2-objid.

     IF sy-subrc = 0.

          CONTINUE.

     ENDIF.

     DELETE itab2.

ENDLOOP.

I hope it helps.

Kind regards,

Vasco Bradão

Read only

Former Member
0 Likes
2,246

Hi,

Please show us some of your program code.

Jake.

Read only

Former Member
0 Likes
2,246

Hi Shankar,

I hope this code helps.

Delete itab2 where otype = ‘E’. "deletes itab2 where otype is 'E'

Loop at itab2 into wa2.

Read table itab1 into wa1 with key objid = wa2-objid.

If sy-subrc NE 0.

Delete itab1 where objid = wa1-objid. "Deletes itab2 where objid not in itab1.

Endif.

Endloop.

Thanks,

Aravind

Read only

former_member196490
Active Participant
0 Likes
2,247

Try this.

Loop at internal_table_2.

l_tabix = sy-tabix.

Read table internal_table_1 with key objid = internal_table_2-objid.

If sy-subrc= 0.

   delete internal_table_2 index l_tabix.

endif.

endloop.

Read only

Private_Member_49934
Product and Topic Expert
Product and Topic Expert
0 Likes
2,246

Isn't it a damn basic question?

Read only

0 Likes
2,246

It is - that's why it's locked now.

The answer from Neha Sinha was marked as correct.

Rob

Read only

Former Member
0 Likes
2,246

Hi Shankar,

Firstly, declare a char1 field (say 'FLAG') in the type of internal_table2. Once both the tables have been populated, do the following:

1. DELETE internal_table2 WHERE otype = 'E'. (Solution to the first part of your problem)

2. SORT internal_table1 BY objid.

3. DATA: li_itab1 LIKE internal_table1, l_index TYPE sytabix.

4. li_itab1[] = internal_table1[].

5. SORT li_itab1 BY objid.

6. DELETE ADJACENT DUPLICATES FROM li_itab1 COMPARING objid.

3. LOOP AT internal_table2 INTO work_area2.

     l_index = sy-tabix.

          READ TABLE li_itab1 INTO work_area1 WITH KEY objid = work_area2-objid.

          IF sy-subrc NE 0.

               work_area2-flag = 'X'.

               MODIFY internal_table2 FROM work_area2 INDEX l_index

               TRANSPORTING flag.

          ENDIF.

          CLEAR: work_area1, work_area2, l_index.

     ENDLOOP.

4. DELETE internal_table2 WHERE flag = 'X'. (Solution to the second part of your problem)

Hope it helps.

Regards,

Gautam.

Read only

0 Likes
2,246

Hi everyone,

here is the exact requirement.

{code} 

DATA BEGIN OF tab_struct OCCURS 0.
        INCLUDE STRUCTURE qcat_stru.
        data END OF tab_struct.
types: begin of ty_loc_e,
  objid type hrp1001-objid,
  end of ty_loc_e.
  data: it_loc_e type STANDARD TABLE OF TY_LOC_E with HEADER LINE,
        WA_LOC_E TYPE TY_LOC_E.
 
  CALL FUNCTION 'RHPH_STRUCTURE_READ'
        EXPORTING
          plvar             = '01'
          otype             = 'L'
          objid             = '50000000'       
          wegid             = 'L-D-E-§'
          begda             = '19000101'
          endda             = '99991231'
          tdepth            = '12'
        TABLES
          stru_tab          = tab_struct
        EXCEPTIONS
          catalogue_problem = 1
          root_not_found    = 2
          wegid_not_found   = 3
          OTHERS            = 4.
    ENDIF.
   
    SELECT objid FROM hrp1001 INTO TABLE it_loc_e
                            FOR ALL ENTRIES IN tab_struct
                            WHERE otype = 'E' AND
                                  objid = tab_struct-objid AND
                                  plvar = '01' AND
                                  relat = '024' AND
                                  sclas = 'F' AND
                                  sobid IN s_loc.

{code}

tab_struct contains all the data of different otypes (like L,D,E,P).

and it_loc_e contains only E type.

Now, i want to delete the records in tab_struct which are otype = 'E' and objid other than those records in it_loc_e.

please help me in this regard.


     

Read only

0 Likes
2,246

SORT tab_struct BY otypes.

DELETE tab_struct WHERE otypes NE 'E'.

Jake.

Read only

0 Likes
2,246

loop at tab_struct where otype = 'E'.

l_index = sy-tabix.

read table  it_loc_e with key objid = tab_struct-objid.

If sy-subrc = 0.

delete tab_struct index l_tabix.

endif.

endloop.

Read only

0 Likes
2,246

i dont want to delete all the otypes other than 'E'.

but, lets take an example.

if tab_struct has the following data:

1 L 50000000   EADS TRAINING CATALOGUE 20090101 99991231 00000000

2 L 50000001 50000001 B BUSINESS SUPPORT 20090101 99991231 20090101

3 L 50000012 50000012 B01 Communication & External Affairs** 19000101 99991231 20090101

4 D 10029871 10029871 Cost Center Test Héritage Cost Center Jonathan 20100101 99991231 20100101

5 E 10002539 10002539 E 11 Test Héritage Cost Center Jonathan 20100903 20100904 20100903

6 P 00001200 00001200 Imp Mr Chief 1 FR Imp 20090101 99991231 20100903

7 E 10111280 10111280 E 11 Test Héritage Cost Center Jonathan 20110501 20110502 20110501

8 E 10111303 10111303 E 11 Test Héritage Cost Center Jonathan 20110501 20110502 20110501

9 H 00000001 00000001 Otto Ottokar Otto 19970101 99991231 20110501

10 E 10111304 10111304 E 11 Test Héritage Cost Center Jonathan 20110503 20110504 20110503

11 E 10111543 10111543 E 11 Test Héritage Cost Center Jonathan 20111201 20111202 20111201

12 E 10111588 10111588 E 11 Test Héritage Cost Center Jonathan 20111205 20111214 20111205

and if it_loc_e has the following data

1. 10111304

2. 10111543

now, from tab_struct content, i want to delete all the records of type E other than 10111304, 10111543.(all L,D,P type data should remain the same.) and my new content should be as follows

1 L 50000000   EADS TRAINING CATALOGUE 20090101 99991231 00000000

2 L 50000001 50000001 B BUSINESS SUPPORT 20090101 99991231 20090101

3 L 50000012 50000012 B01 Communication & External Affairs** 19000101 99991231 20090101

4 D 10029871 10029871 Cost Center Test Héritage Cost Center Jonathan 20100101 99991231 20100101

5 P 00001200 00001200 Imp Mr Chief 1 FR Imp 20090101 99991231 20100903

6 H 00000001 00000001 Otto Ottokar Otto 19970101 99991231 20110501

7 E 10111304 10111304 E 11 Test Héritage Cost Center Jonathan 20110503 20110504 20110503

8 E 10111543 10111543 E 11 Test Héritage Cost Center Jonathan 20111201 20111202 20111201

please help me in this regard

Read only

0 Likes
2,246

With the below code only records those records in the table tab_struct would be deleted which have obtyp = 'E' and are not present in it_loc_e.

loop at tab_struct where otype = 'E'.

l_index = sy-tabix.

read table  it_loc_e with key objid = tab_struct-objid.

If sy-subrc <> 0.

delete tab_struct index l_tabix.

endif.

endloop

Read only

0 Likes
2,246

it should be sy-subrc<> 0 in the 4th line above

Read only

0 Likes
2,246

as i understand your issue.

you want to delete record from tab_structure which otypes = E and which is not in it_loc_e.

sort tab_structure by otypes.

read tab_structure into wa_tab_structure index 1.

     if wa_tab_structure-otypes = e.

               read table it_loc_e into wa_it_loc_e with key wa_it_loc_e -objid = wa_tab_structure -objid.

                    if sy_subrc <> 0.

                         delete tab_structure from wa_tab_structure.

                    endif.

     endif.

     index = index +1.

revert if any problem

regards

rohit