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

call subroutines dynamically

Former Member
0 Likes
1,695

Hi all experts,

I got a problem with dynamical calling subroutines. I have a huge list of subroutines to call. Each of them has own defined paramter interface.

Such like this.

FORM subroutine

USING var1 TYPE typ1

CHANGING var2 TYPE typ2

                    ...

                    varN TYPE typN

We dont know the data types of paramters and the number of CHANGING PARAMETER is variate too.

I have tried to use the "generate subroutine pool" to call them dynamically but the number of subroutine pools I want to create is heavily exceed the limit of 36 times.

Is there any other intelligent way to implement it.

Thanks and with best Regards,

Jun

8 REPLIES 8
Read only

Former Member
0 Likes
1,367

is it possible to build a paramter table like dynamically calling the class method or function module?

Read only

0 Likes
1,367

Hi,

is there anything preventing you from using class methods?

You could rebuild your subroutines as methods of a (local) class.

Or else although this might seem a bit bulky but still way better then generate subroutine pool

you could build a wrapper method for each of your subroutines, thus beeing able to use parameter tables on the caller site and then addressing each subroutine with the correct supply of parameters.

Regards

Jörg

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,367

You have look at the technique of calling a subroutine from a sap script. I think the same applies here.

Why not encapsulating each of the 36 calls in different LUW's . Will this work ?

Read only

franois_henrotte
Active Contributor
0 Likes
1,367

if the number of parameters is not always the same then you have to pass an internal table as parameter, and inside the table you have your parameters

for this purpose you could use a structure like DYNPREAD for your internal table

now if you want to be able to pass any type of parameter to your routine then you set a parameter with type TYPE REF TO DATA. Before you call the routine you do a GET REFERENCE OF on your parameter and you pass the reference. Then in the routine you are able to get the type of the parameter (do an ASSIGN then a DESCRIBE) and react accordingly

Read only

0 Likes
1,367

hi François Henrotte,

Thanks for your reply. The problem is  I cant do any modifications in the routines which I called.

Regards,

Jun

Read only

Former Member
0 Likes
1,367

hi Jun Long,

                You can define data type as generic type and take the paramater into a internal table and pass the value by creating method.Let me know if you want more clarification.

Regards,

Ankita

Read only

0 Likes
1,367

Hi Ankita,

please give more clarification.

Do you mean I should create a class method as Interface to receicve the parameters in internal table of generic types. Then I call the subroutine within my class method?

Thanks and Regards,

Jun

Read only

Former Member
0 Likes
1,367

Hi Jun,

The best approach in such case is to use Class and method in place of subroutene, where you can make the parameters optional.

If it is required to use only subroutene, then you declare parameters with type ANY and pass different structures at different call.

Hope this helps.

Cheers,

Samir