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

Looping the function module

Former Member
0 Likes
1,305

Hai,

loop at it_tab1 into wa_tab1.

call function ' '

endloop.

i am calling a function module all values are coming while i debug the function module but the value is not moved to my internal table.

what is my error?.

3 REPLIES 3
Read only

Former Member
0 Likes
569

Hi,

can you show the piece of code what you have written.

Best regards,

raam

Read only

Former Member
0 Likes
569

>

> i am calling a function module all values are coming while i debug the function module but the value is not moved to my internal table.

>

> what is my error?.

Values are coming into..? values are not moved to internal table which one is that..?

Is it inside the function you are talking..?, show the code related to that part.

Read only

ian_maxwell2
Active Participant
0 Likes
569

>loop at it_tab1 into wa_tab1.

>call function ' '

>endloop.

>i am calling a function module all values are coming while i debug the function module but the value is not >moved to my internal table.

>what is my error?.

I assume that you are expecting that the function is going to update the values of some fields of the internatl table for the record that you are are currently on in the loop. It would help if you can post the full piece of code, but I'll take a shot at it anyways.

I figure that most likely you are useing the fields in wa_tab1 as your input and output fields of the function that you are calling. The issue is that this will just be updating the work area and not the actual table, so as soon as you reach the endloop the values are gone.

There are two possible solutions to this:


loop at it_tab1 into wa_tab1.
    l_Tabix = sy-Tabix.    

    Call function FooBar
    Importing a value of something into wa_tab1-SomeField.
  
    modify it_tab1 from wa_tab1 index l_Tabix.  <-This is what you're missing

endloop.

Note in the above code, the modify statement actaully moves the values from the work area to the internal table record. Inside the loop you don't really need to use the "index l_Tabix" part but I tend to use this to ensure that no mistakes in the logic are made. By default it will update the current record that you are looping on. You can also define "Transporting" for certain fields which means that it won't move all fields, just the ones that you specify.

http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb36a1358411d1829f0000e829fbfe/frameset.htm

I tend to also use a lot of field-symbols because it allows you to modify records in the internal table directly. The following is an example:


Field-Symbols:
  <tab1> type ????

loop at it_tab1  assigning <tab1>
 
   Call function FooBar
    Importing a value of something into <tab1>-SomeField. 
 
endloop.

Hope this helps.

~Ian

Edited by: Ian Maxwell on Aug 4, 2008 1:38 AM