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: 

refreshing the internal table

Former Member
0 Kudos

Hi all,

I am writing a logic in an user-exit for Sales order,

Suppose there are 5 line items in sales order, and for each item the user exit is getting executed.

The user-exit contains the below statements.

Loop at xvbpak where ( partner eq '18' or partner = '19')."this is header internal table.

if sy-subrc eq 0.

move xvbpak to xvbpap.

xvbpap-posnr = xvbpaf-posnr. "passing the current line item number to xvbpap table..

append xvbpap.

clear xvbpap.

endif.

endloop.

This statement would be executed for each item in the sales order to copy header partner into item partners.

Once it completes, i have to delete the entries from header partner internal table xvbpak.

How can i write logic for deleting the entries from xvbpak after processing all items in the sales order.

The internal table xvbpaf contains all items in the sales order.

Thanks,

Deno

5 REPLIES 5

suresh_datti
Active Contributor
0 Kudos

Hi Deno,

First off, you need not check the sy-subrc inside a loop as only then you will be inside the loop. You can try the following code to refresh your itab..


Loop at xvbpak where partner eq '18' or partner = '19'.
move xvbpak to xvbpap.
xvbpap-posnr = xvbpaf-posnr. 
append xvbpap.
clear xvbpap.
delete xvbpak index sy-tabix.
endloop.

Regards,

Suresh Datti

0 Kudos

Hi Suresh,

thanks for the prompt reply.

Loop at xvbpak where partner eq '18' or partner = '19'.

move xvbpak to xvbpap.

xvbpap-posnr = xvbpaf-posnr.

append xvbpap.

clear xvbpap.

delete xvbpak index sy-tabix.

endloop.

As i said in the previous mail, when the next item comes in, there will be no entry in the internal table xvbpak.

the bunch of statements will be executed five times if there are five line items in the sales order.

The table entries from xvbpak should be deleted only after processing all items in the internal table xvbpaf.

Thanks,

Deno

0 Kudos

Try:


Loop at xvbpak where 
  partner = '18' or 
  partner = '19'.
  move xvbpak to xvbpap.
  xvbpap-posnr = xvbpaf-posnr. 
  append xvbpap.
  clear xvbpap.
endloop.

delete xvbpak where partner eq '18' or partner = '19'.

Rob

former_member186741
Active Contributor
0 Kudos

Why not do it the first time through the exit. It wasn't clear from your post whether to delete all entries from xvbpak or only the 18/19 entries. I've assumed all, but you can change the code easily if that's wrong:

if not xvbpak[] is initial.

Loop at xvbpaf.

Loop at xvbpak where ( partner eq '18' or partner = '19')."this is header internal table.

move xvbpak to xvbpap.

xvbpap-posnr = xvbpaf-posnr. "passing the current line item number to xvbpap table..

append xvbpap.

endloop.

endloop.

loop at xvbpak.

delete xvbpak.

endloop.

endif.

Former Member
0 Kudos

Hi,

Write your code in USEREXIT_SAVE_DOCUMENT ( include MV45AFZZ). This exit triggers while saving sales document and since it triggering at saving, you have all the tables available in this exit.

So, you can write whatever logic you want to write with all the data available and it only triggeres once.

I hope this will help you.

Pal