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

To delete an internal table based on two column value condition

0 Likes
7,264

Hi everyone,

I have a internal table having 17 records

I need to delete two rows based on two field column values

For example:

Condition is , If movement type-bwart is 102 and its document number-belnr is initial, it shud check 101 movement type and if its document number is also initial.

It should delete both the line items from the internal table.How could we achieve this?

Hi everyone,

I have a internal table having 17 records

I need to delete two rows based on two field column values

For example:

Condition is , If movement type-bwart is 102 and its document number-belnr is initial, it shud check 101 movement type and if its document number is also initial.

It should delete both the line items from the internal table.How could we achieve this?

6 REPLIES 6
Read only

TMSingh_SAP
Participant
0 Likes
3,894

Hi,

I modified- check this:

Loop at it_tab into data(ls_tab1) where bwart = 102 and belnr = ' '.

Lv_tabix1 = sy-tabix.

Read it_tab into data(ls_tab2) with key 101 and belnr = space..

if sy-subrc is initial.

lv_tabix2 = sy-tabix.

Delete it_tab index index lv_tabix1. " delete 102

Delete it_tab index index lv_tabix2. " delete 101

endif.

Endloop.

Thanks,

Mohan

Read only

0 Likes
3,894

Hi Mohan,

That is not my requirement.

I need to check first movement type 102 and it's document number , if it's inital and then I should check 101 and it's document number.

If both document number is initial , I will delete both the rows

Read only

0 Likes
3,894
* Syntax may be wrong, please rewrite yourself...

LOOP AT ITAB ASSIGNING <FS> WHERE BWART = '102'
                              AND BELNR IS INITIAL.
READ TABLE ITAB TRANSPORTING NO FIELDS WITH KEY BWART = '101'
                                                BELNR = ' '.
IF SY-SUBRC EQ 0.
   FLAG = 'X'.
ENDIF.
ENDLOOP.


IF FLAG EQ ABAP_TRUE.
   DELETE ITAB WHERE BWART = '102' AND '101'.
ENDIF.
Read only

Former Member
0 Likes
3,894

SORT: <internal_table> BY <primary_key>.

READ TABLE <internal_table> INTO <work_area1> WITH KEY BWART = '102'
                                                       BELNR = space
                                                       BINARY SEARCH.
IF sy-subrc EQ 0.
  READ TABLE <internal_table> INTO <work_area2> WITH KEY BWART = '101'
                                                         BELNR = space
                                                         BINARY SEARCH.
  IF sy-subrc EQ 0.
     DELETE <work_area1> FROM <internal_table>.
     DELETE <work_area2> FROM <internal_table>.
  ENDIF.
ENDIF.
                                                            
Read only

DoanManhQuynh
Active Contributor
0 Likes
3,894

I think there are alot of solution for this, just add one of mine 🙂

LOOP AT itab INTO wa group by ( vbeln = wa-vbeln ) ASSIGNING <fs_grp_key>.
  IF <fs_grp_key>-vbeln IS INITIAL.
 LOOP AT GROUP <fs_grp_key> INTO wa2.
 IF wa2-bwart = '102' AND line_exist( <fs_grp_key>[ bwart = '101' ] ).
 ELSE.
 it_final = VALUE #( BASE ( it_final ) ( wa2 ) ).
 ENDIF.
 ENDLOOP.
 ELSE.
 it_final = VALUE #( BASE ( it_final ) FOR m in GROUP <fs_grp_key> ( m ) ).
 ENDIF.
ENDLOOP.

Read only

0 Likes
3,894

Sorted!

Thanks Everyone..