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: 

Dynamic Subroutine.

former_member676613
Participant
0 Kudos

Hi All,

What is use of Dynamic sub routine as it is used in one of my code i am not able to understand its occurance how it is working.

Please help.

thanks,

Chandresh

8 REPLIES 8

Former Member
0 Kudos

Hi,

Dynamic subroutines allow you to call subtourines of other programs. In some cases you would write a subtroutine or a subroutine pool for some common functionality. When that functionality needs to be used in your program, you would simply call that subroutine in the subtrouine pool program using the syntax PERFORM form IN PROGRAM prog.

regards,

Advait

0 Kudos

Hi,

Thanks for the response but in my case as i can see it is not GLOBAL type subroutine .

And as u suggested that it may be created in Subroutine pool so can u help me in searching that pool.

Thanks,

Chandresh

0 Kudos

Hi,

The program name that you pass while calling the subroutine is the program where the subroutine is actually written. You can see the program in se38.

Also its not always necessary that the subroutine belongs to a subroutine pool, it could be a normal executable program as well.

example perform

0 Kudos

Alternatively run the program, debug it to get into subroutine pool, and see in the code preview in debugger what it does and what other forms are included in that pool.

MarcinPciak
Active Contributor
0 Kudos

Is something is dynamic in ABAP it basically means its name is unknown before program is started.

Only if this point is reached by Runtime Environment then the name (in your case of subroutine) is determined depednign on the context. Once you want to call one subroutine and another time different one, but still using the same point of call.

Suppose you have subroutine pool generated somewhere in the program (dynamic code which is written by your program and executed when needed). You defined there two subroutines and now depending on some calculation you want to invoke certain subroutine.


data: subr_name type string.

"depending of different conditions you determine subroutine's name
IF condition1 = true.
  subr_name = 'SUB1'.
else if condition2 = true.
 subr_name = 'SUB2'.
endif.

"now you call (from one point) your subroutine. Note that this code can be used couple times i.e. within a loop therefore this code is dynamically determined during execution. You just use one point to call different subroutines
 
"because SUBR_NAME is unknown before program starts (you cannot say when looking at the code wheter it will call SUB1 or SUB2) it must be embraced with paranthesis (SUBR_NAME), meaning WILL BE DETERMINED during execution
PERFORM (subr_name) IN PROGRAM (prog)
               USING ..... IF FOUND.

"What it does is simply calling a subroutine which name resides in data object SUBR_NAME in PROG (which is also determined dynamically). 

Hope it will give you some overview, what dynamic programming is.

Regards

Marcin

0 Kudos

Hi,

Thanks for the response but in my case as i can see it is not GLOBAL type subroutine .

And as u suggested that it may be created in Subroutine pool so can u help me in searching that pool.

Thanks,

Chandresh

Former Member
0 Kudos

hi

Local data types and objects declared in subroutines using the TYPES and DATAstatements are deleted when the subroutine ends, and recreated each time the routine is called.

Every subroutine has its own local namespace. If you declare a local data type or object with the same name as a global data type or object, the global type or object cannot be addressed from within the subroutine. Local data types or data objects hide identically named global data types or objects. This means that if you use the name of a data type or object in the subroutine, you always address a locally declared object u2013 if this exists u2013 and otherwise a globally declared one. To prevent global data types or objects from being hidden, local types and objects must have other names assigned to them. For example, all local names in subroutines could begin with u2018F _u2019.

Thanks

Rajesh Kumar

former_member676613
Participant
0 Kudos

anserwed