Application Development 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: 

Compare Values of two coloumns in the same internal table

former_member207873
Participant
0 Kudos

I am having an internal table which is having values like below.

Billing  Doc No
Cancelled Bill Doc No
                            9000032                                 9000045
                             9000033                                   _______
                              9000034                                ____________
                               9000045                                __________

So what I wanted to do is if there is a cancelled billing doc no for a particular billing document no...as in this case 9000045 exists for 9000032. So I wanted to take that cancelled billing doc no and check whether it exits in billing doc no and if it exits I have to delete it. After which I wanted to delete all the Billing doc nos which are having canelled billing doc no's. Like here I have to delete 9000032 since a cancelled billling doc no exits for 9000032. How to achieve this?

Regards,

Marina.

9 REPLIES 9

former_member209120
Active Contributor
0 Kudos

HI Marina,

Try like this

TYPES : BEGIN OF ty_table,
         f1  TYPE i,
         f2  TYPE i,
         END OF ty_table.

DATA : it_table TYPE TABLE OF ty_table,
        wa_table TYPE ty_table,
        it_table_1 TYPE TABLE OF ty_table,
        wa_table_1 TYPE ty_table,
        var TYPE i.


wa_table-f1 = '9000032'.
wa_table-f2 = '9000045'.
APPEND wa_table TO it_table.
CLEAR wa_table.

wa_table-f1 = '9000033'.
wa_table-f2 = ' '.
APPEND wa_table TO it_table.
CLEAR wa_table.

wa_table-f1 = '9000034'.
wa_table-f2 = ''.
APPEND wa_table TO it_table.
CLEAR wa_table.

wa_table-f1 = '9000035'.
wa_table-f2 = ''.
APPEND wa_table TO it_table.
CLEAR wa_table.

it_table_1 = it_table.

LOOP AT it_table INTO wa_table.
   READ TABLE it_table INTO wa_table WITH KEY f1 = wa_table-f2.
   IF sy-subrc = 0.
     DELETE it_table.
   ENDIF.
ENDLOOP.

DELETE it_table WHERE f2 IS NOT INITIAL.


Loop at it_table into wa_table.
  
   write : / wa_table-f1, wa_table-f2.

endloop.


0 Kudos

LOOP AT it_tab INTO wa_tab.

  IF wa_tab-cancel_vbeln IS NOT INITIAL.

    READ TABLE it_tab INTO wa_tab WITH KEY vbeln = wa_tab-cancel_vbeln.

    IF sy-subrc EQ 0.

      DELETE it_tab INDEX sy-tabix.

    ENDIF.

    DELETE it_tab.

  ENDIF.

ENDLOOP.

Cheers!

Former Member
0 Kudos

if im correct it is about delete row(s) to which entry exist in column cancelled_doc. you can do like this.:

loop at itab into wa_itab.

if wa_itab-cancelled_doc is not initial.

delete itab index sy-tabix.

endloop.

Rgds

former_member198834
Participant
0 Kudos

hi

1. first copy the itab to another itab

     itab2[] = itab1[]

2. loop at itab1 into wa_tab1.

          read table itab2 into wa_tab2 with key f2 = wa_tab1-f1.

            if sy-subrc = 0.

            delete itab1 index sy-tabix

           endif.

      clear wa_tab1.

     endloop.

hope it will work

suresh

Former Member
0 Kudos

Hi Maria,

Try this.

LOOP AT itab INTO wa.

     IF wa-fieldname IS NOT INITIAL.

               DELETE itab index sy-tabix.

     ENDIF.

ENDLOOP.

Regards,

Anoop

Former Member
0 Kudos

Hi Marina,

Single deletes will take lot of time....

Still you can directly filter the records during select itself FKSTO is Space this will not select the cancelled docs.

Now for your query delete on same table in loop is not recommended and also in large datasets it will be slow to delte single records.

ADD 1 more field in table as FLAG type c

itab_tmp[] = itab[].

Loop at itab_tmp into wa_tmp.

READ TABLE itab into wa_tmp with key vbeln = wa_tmp-sfakn.

if sy-subrc is initial.

wa_tmp-flag = 'X'.

modify itab from wa_tmp transporting flag where vbeln = wa_tmp-sfakn. " This will mark the original record.

modify itab from wa_tmp transporting flag where sfakn = wa_tmp-sfakn. " This will mark the cancel record.

endif.

endloop.

delete itab where flag = 'X'.

Regards

0 Kudos

Hi,

I tried your logic Yakub. But it is not working properly. I would like to follow your logic with the flag concept.

Here is how I have done.

IT_TEMP[] = IT_FINOVR[].

LOOP AT IT_TEMP INTO WA_TEMP.

READ TABLE IT_FINOVR INTO WA_TEMP WITH KEY VBELN = WA_TEMP-SFAKN.

  IF SY-SUBRC IS INITIAL.

  WA_TEMP-FLAG = 'X'.
 
  MODIFY IT_FINOVR FROM WA_TEMP TRANSPORTING FLAG WHERE VBELN = WA_TEMP-SFAKN.
* MODIFY IT_FINOVR FROM WA_TEMP TRANSPORTING FLAG WHERE SFAKN = WA_TEMP-SFAKN.
  CLEAR WA_TEMP-FLAG.

  ENDIF.

ENDLOOP.

DELETE IT_FINOVR WHERE FLAG = 'X'.

Regards,

Marina.

0 Kudos

can you debug and check please the code should work also check may be it could be a conversion issue also.

0 Kudos

Hello,

I degugged. But  after the first modify it is taking all values as 'x'.

regards

Marina.