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 data from Final Internal Table?

Former Member
0 Likes
1,097

Hi all,

In my program my final internal table is being displayed as ALV.

APPEND S_OUTPUT TO IT_OUTPUT.

in it_output the first column is VBELN comming from VBRK

after that i have written below code:

SELECT AUART
            VGBEL
       FROM VBAK
       INTO CORRESPONDING FIELDS OF TABLE
       IT_VBAK WHERE AUART IN ('ZCRM' ,'ZDRM' ,'ZRE1').


after the data is fetched from the above select query i need to compare the vgbel field of IT_vbak and VBELN field of my final internal table it_output

wherever it matches it should delete that record from my final internal tabel it_output


can anyone please tell me what to write???



LOOP AT IT_VBAK INTO WA_VBAK.

       READ TABLE IT_OUTPUT INTO S_OUTPUT WITH KEY INV_NO = WA_VBAK-VGBEL.???????

1 ACCEPTED SOLUTION
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
994

loop at it_output into lwa_output.

lv_tabix = sy-tabix.

read table it_vbak into lwa_vbak with key vgbel = lwa_outout-vbeln.

if sy-subrc eq 0.

delete it_output index lv_tabix

endif

endloop.

6 REPLIES 6
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
995

loop at it_output into lwa_output.

lv_tabix = sy-tabix.

read table it_vbak into lwa_vbak with key vgbel = lwa_outout-vbeln.

if sy-subrc eq 0.

delete it_output index lv_tabix

endif

endloop.

Read only

Former Member
0 Likes
994

Hi,

If you want to delete the entries from IT_VBAK, perform the following

Loop through IT_VBAK

     Read IT_OUTPUT based on VBELN = VGBEL of IT_VBAK

     If SY-SUBRC = 0

          Delete the entry from IT_VBAK based on INDEX

     End if

End Loop

Regards,

Jennifer

Read only

former_member183069
Active Participant
0 Likes
994

Hi,

Try this:

LOOP AT IT_VBAK INTO WA_VBAK.


      READ TABLE IT_OUTPUT INTO S_OUTPUT WITH KEY INV_NO = WA_VBAK-VGBEL.


         If sy-subrc  = 0.

           delete it_output INDEX sy-tabix.

        endif.


endloop.


Regards,

KK

Read only

Former Member
0 Likes
994

LOOP AT IT_VBAK INTO WA_VBAK.
       READ TABLE IT_OUTPUT INTO S_OUTPUT TRANSPORTING NO FIELDS

           WITH KEY INV_NO = WA_VBAK-VGBEL. // PUT HERE THE CONDITION

IF SY-SUBRC = 0 . //RECORD IS FOUND

     DELETE IT_OUTPUT INDEX SY-TABIX.  //delete the record

ENDIF.


Hope this help u


Note: for every VGBEL there cannot be more then "ONE RECORD" in your output table.

if say VGBEL is VGBEL1 and there is two lines in output internal table say on 10 and 11 position.

This code will delete only 10th  record not 11th record .



This problem is very simple and already answered by many in other posts too

Thanks

Sandeep


Read only

Former Member
0 Likes
994

Hi Vipin,

I  would like to add this for above solutions in perfrmance point of view..

based on the expected records in table IT_VBAK and IT_OUTPUT you decide on which table you have loop over.

if IT_VBAK is having less entries.

loop over IT_VBAK

     REad for corresponding record in IT_OUTPUT.

     if found

          delete it from IT_OUTPUT.

     endif.

endloop.

if IT_OUTPUT is having less entries then

Loop over IT_OUTPUT.

     check whether this entry is existed in IT_VBAK.

     if yes

          delete this record from IT_OUTPUT.

     endif.

endloop.

our little precautions will cause greate performance effect.

Regards,

Bhaskar

Read only

atul_mohanty
Active Contributor
0 Likes
994

Hi

Please follow the below steps.

1. In the IT_output table,  add one field 'Flag' as char1 at end of the structure.

2. After selecting data from VBAK, loop over IT_OUTPUT in to W_OUTPUT

3. Read the table IT_VBAK into WA_VBAK with key VGBEL = W_OUTPUT-VBELN.

   if sy-subrc = 0.

  work area of IT_OUTPUT-FLAG = 'X'.

  modify IT_OUTPUT from W_OUTPUT transporting flag.

  endif.
endloop.

4. Delete IT_OUTPUT where flag = 'X'.

Let us know, if it helps.

Regards,

Atul Mohanty