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 at functionmodule

Former Member
0 Likes
2,562

Hi All,

Here i'm passing three internal tables to a functionmodule by putting three itabs in loop. Just like below.



loop at itab1.
loop at itab2.
loop at itab3.

calling functionmodule.

endloop.
endloop.
endloop.

.

Very poor performance as Its taking toomuch time to give result. So is there any other way to call FM with all the required data?

Thanks in advance.

Regards

g.s.naidu

21 REPLIES 21
Read only

joginder_singh
Active Participant
0 Likes
2,128

Hi ,

Can you enhance your question in detail ,so that some one can help you to provide the best solution.

What data the Itab1,itab2,itab3 contains and which function module ur using in a loop.?

Cheers

J.

Read only

0 Likes
2,128

Hi

Thank you for the response. There i'm having usernames, tcodes and dates in the three itabs and i'm passing all to a custom functionmodule.

Thank you

Regards

g.s.naidu

Read only

matt
Active Contributor
0 Likes
2,128

Rewrite your function module so you can call it like this:

CALL FUNCTION MODULE 'functionmodule' EXPORTING it_itab1 = itab2 it_itab2 = itab2 it_itab3 = itab3.

matt

Read only

0 Likes
2,128

Hi,

You use can use the Matt solution if you want to pass the whole interbal table data and if you want to transfer just workarea then u need to modify the code using the read statements based on the appropriate conditions instead of Loops .

I hope this anwer give some hint to resolve the issue.

Cheers

J.

Read only

0 Likes
2,128

Hi

Yes Matt's solution is right but i canot change the function module code. So J can you give some example code for using read statements for three itabs.

Thank you

regards

g.s.naidu

Read only

0 Likes
2,128

Hi

Can you just post the code which you have written right now ,so that i can modify the same. Bceause i should know what the fields exits in the itab1,itab2,itab3 to write a read statment based on it. So place your code along with function module ,so that i know what are the export n imprort parameters.

Include the structure of itab1,itab2, & itab3.

Cheers

J.

Read only

0 Likes
2,128

Naidu...

Loop at the first table and read the second and the third table based on some common key fields.......

If you loop thrice...and suppose.. each of the table has 10 entries.. the total number of loops would be.... 10 x 10 x 10 ie... 1000....

so... imagine having 1 lakh records... the program wont even run in fore ground.. i guess...

so best ..way..is to use READ within the loop..

Read only

matt
Active Contributor
0 Likes
2,128

>

> Yes Matt's solution is right but i canot change the function module code.

It would have been a good idea to mention that upfront. It is rather important to any solution... Moving thread to performance.

matt

Read only

0 Likes
2,128

I agree.

Loop at i_tab1 into watab1,

Read TABLE itab2 into watab2 with key SOMETHING = watab1-something.

subrc = 0.

read from i

subrc = 0.

tab3 into watab3 with key SOMETHING = watab1 or watab2.

call fm.

endloop.

Read only

0 Likes
2,128

Hi,

How complex is the function module that you used?

If the function module contains logic to select from db table and your internal table have a lot of records, your program will have poor performance due to multipe reopen connection activity to the database.

If you have a lot of data in your internal table, I would suggest to read the function module source code and try to recreate the logic in a way that you only need to have db connection open for one time.

Simple example :

Poor performance code:

Loop at vendor data.

call FM to get vendor open item.

endloop

FM Logic :

Select * from tab1 to itab1 where (condition from fm parameter).

Better performance code:

Select * from tab1 for all entries in vendor data to itab1.

I've tried that with one of my report that will have 10.000 + vendors and the running time reduced is significant. Hope it helps.

Regards,

Abraham

Read only

0 Likes
2,128

Hello,

I don't understand, why it's impossible to change a customer function module. Why isn't it possible to enhance this customer module, w/o touching the actual logic, i.e. all old reports calling the function module have to work after the modification, w/o modifying the call of the function in the reports?

Add a table with all of your records. When the table isn't filled, move the "old" parameters into the table, and then process the coding for all records in the table. In this way you can process single entries ("old version") and multiple entries ("new version").

Best regards

Stephan

Read only

0 Likes
2,128

Hi,

Before calling the fms, try to accumalte all the data in 3 internal loop which is required for the function module in the fourth table.Loop only the fourth table and call the function module inside the loop.

Read only

0 Likes
2,128

Without knowing the FM's interface no bidy can give best solution to improve the performance. Query should have more information. And also raised by someone the requirement for itab1 X itab2 X itab3...

is need to be looked in..

Kindly give the interface of FM.

Read only

abdul_hakim
Active Contributor
0 Likes
2,128

Hi

This piece of code is going to impact the performance of your program heavily for sure.

Try to avoid calling function modules in loop you could replace with READ TABLE based on certain condtion. Think of some other workarounds as well.

Cheers,

Hakim

Read only

Former Member
0 Likes
2,128

Hi,

Add new structure with all three ITAB table fields and move all fields. So you can lood the final table with function module.

Regards

Md.MahaboobKhan

Read only

0 Likes
2,128

Please take a look at the problem carefully guys.

He mention that he need to do such as below:

loop at itab1.

loop at itab2.

loop at itab3.

call fm.

endloop.

endloop.

endloop.

That's mean itab2 can contain more than 1 record using key provided by itab1 and itab3 can contain more than 1 record using key provided by itab2, otherwise he would use Read statement. Hence, the only way to reconstruct the itab4 is doing the same thing with his approach.

You will still need to loop 3 times which mean if each of your itab has 10 entries, your itab4 will have 10 x 10 x 10 entries or 1000 entries and in the end you will still execute the FM 1000 times.

Don't confuse him by restating his logic in different way but same cost.

The main issues here is the FM is called 1000 times so if there are any select statement inside this FM, he will have 1000 reopen connection to the database. This is something that must be avoided to fix the program performance.

Regards,

Abraham

Read only

Former Member
0 Likes
2,128

loop at itab1.
  loop at itab2.
    loop at itab3.
         calling functionmodule.
      endloop.
   endloop.
endloop.

your coding depends on the sizes of the three tables, like N1* N2 * N3, that is cubic and will be slow.

Either all three N stay small.

Or must consider whether really every line in itab2 goes with every line itab1, etc.

Usually not all combinations are really needed, from business sense it must be possible to get

a coding like that


loop at itab1 into wa1.
  loop at itab2 where wa1.

   endloop.
endloop.

A third nested loop is not really necessary! Also here you must use a SORTED table for itab,

or a read binary search and a loop from index , exit with standard table (not recommended).

Siegfried

Read only

Former Member
0 Likes
2,128

no, I would say you are wrong!

I have never seen a business case where you spread that the data into 3 tables, and process it in a way

that you execute

itab1 x itab2 x itab3

Maybe it is necessary, that 1000 executions are necessary that is not the issue. But usually not every line with itab1 goes with every line of itab2 and every line of itab3.

The question is how does it increase if more data must be processed, does every table grow?

20 * 20 * 20 = 8000 ? or only one. only the later one is acceptable.

Be aware, that I am talking about business software. Optimzation problems have quadratic coding and can be made faster, that is something different.

But altogether, with the poor information of the question it is not clear how the solution could look like.

Siegfried

Read only

0 Likes
2,128

>

> no, I would say you are wrong!

>

> I have never seen a business case where you spread that the data into 3 tables, and process it in a way

> that you execute

> itab1 x itab2 x itab3

>

> Maybe it is necessary, that 1000 executions are necessary that is not the issue. But usually not every line with itab1 goes with every line of itab2 and every line of itab3.

>

> The question is how does it increase if more data must be processed, does every table grow?

>

> 20 * 20 * 20 = 8000 ? or only one. only the later one is acceptable.

>

> Be aware, that I am talking about business software. Optimzation problems have quadratic coding and can be made faster, that is something different.

>

> But altogether, with the poor information of the question it is not clear how the solution could look like.

>

> Siegfried

I agree that we can not continue with poor information of the question.

What we don't know is where do we get that three itab from.

Is it come from the table directly?

Is it possible to do select join to 3 table so instead of getting 3 table we can get 1 itab?

In the end, i will still stick with my opinion that eventhough you only have 1 itab in the end, if you have quite significant select statement in your called function module, you will still need to find a way to prevent multiple select that resulted in multiple db connection open.

If you can enhance your function module to process multiple entires, that would be perfect.

Regards,

Abraham

Read only

Former Member
0 Likes
2,128

Hi,

Check that fm is dependent of all the three itabs.

If it is independent call the FM independently.

loop at itab1.

Call the fm.

Endloop.

loop at itab2.

Call the fm.

Endloop.

loop at itab3.

Call the fm.

Endloop.

If FM is dependent of all the three itabs.

Look at any 3 common fields in 3 internal tables.

Take one more itab that is itab4, contain itba1, itab2 or common of itba1, itab2(Depend on requirements).

Loop at itab3.

Read table itab1.

Read table itab2.

Move itab1 and tab2 to itab4.

Call fm with itab4.

Endloop.

Read only

Former Member
0 Likes
2,128

Hello,

place subroutine inside the loop,and call ur function moudle using subroutines.

Regards,

Anil.D