Introduction :
A subroutine is a reusable section of code.
It is a modularization unit within the program where a function is encapsulated in the form of source code.
Subroutines are used to modularize the program.
Generally Subroutines are called by using PERFORM keyword and defined within FORM and ENDFORM block.
here are three ways to pass the values with Subroutines.
1. pass by value:
In this type, the actual and formal parameters will be referring to separate memory.
The formal parameter is changed, the actual parameter will not be changed.
The parameters which are passed in the perform call are known as actual parameters or actual arguments.
The parameters which are received by the called Form & endform are known as formal parameters or formal arguments.
Example is shown below:
example1 : pass by value : using - using value().
example2 : pass by value : changing - using value().
output
2. pass by reference:
In this type, the actual and formal parameters are referred to the same memory.
If the formal parameter is changed, the actual parameter is also changed.
example1 : pass by reference : using - using.
example2 : pass by reference : using - changing.
3. pass by value and return:
In this type, the actual and formal parameters will be referring to separate memories.
If the formal parameter is changed, the actual parameter is also changed after executing the FORM...ENDFORM.
example1 : pass by value and return : using - changing value().
example2 : pass by value and return : changing - changing value().
you can use subroutines according to your requirements.
this is a basic approach .
A subroutine is a reusable section of code.
It is a modularization unit within the program where a function is encapsulated in the form of source code.
Subroutines are used to modularize the program.
Generally Subroutines are called by using PERFORM keyword and defined within FORM and ENDFORM block.
here are three ways to pass the values with Subroutines.
1. pass by value:
In this type, the actual and formal parameters will be referring to separate memory.
The formal parameter is changed, the actual parameter will not be changed.
The parameters which are passed in the perform call are known as actual parameters or actual arguments.
The parameters which are received by the called Form & endform are known as formal parameters or formal arguments.
Example is shown below:
example1 : pass by value : using - using value().
output
example2 : pass by value : changing - using value().
output
2. pass by reference:
In this type, the actual and formal parameters are referred to the same memory.
If the formal parameter is changed, the actual parameter is also changed.
example1 : pass by reference : using - using.
output
example2 : pass by reference : using - changing.
output
3. pass by value and return:
In this type, the actual and formal parameters will be referring to separate memories.
If the formal parameter is changed, the actual parameter is also changed after executing the FORM...ENDFORM.
example1 : pass by value and return : using - changing value().
output
example2 : pass by value and return : changing - changing value().
output
you can use subroutines according to your requirements.
this is a basic approach .
Hi, this was a nice article on parameter interface & the three types of exchanges- pass by value, pass by parameter, pass by value & return.
ReplyDeleteThank you for sharing, I had been searching for this for quite some time.
On a lighter note, the admin/author of the blog should start moderating the comments just like the one made before me.