Friday, April 22, 2022

SUBROUTINES IN SAP ABAP

SUBROUTINES IN SAP. How we used in SAP. Details About SUBROUTINES IN SAP ABAP. 



When ever same logic is needed to be executed many times in a program, create a subroutine and call the subroutine when ever the logic is needed to be executed.

Perform statement is used to create the subroutine and to call the subroutine. 

A subroutine can be created with passing the variables and without passing the variables. The logic of the subroutine is written between form and endform. It is not required to start the subroutine name with Z OR Y.

The variables that are passed into subroutine are called global variables or actual variables. The variables that are used to receive the values in subroutine from main program are called local variables or formal variables.

There are 3 ways to pass the variables into subroutine.


CALL BY VALUE

CALL BY REFERENCE

CALL BY VALUE AND RESULT


CALL BY VALUE:- In this new memory area is allocated for the local variables between form and endform. When the values of local variables are changed , they are changed in only or reflected in only newly created memory area. The original values of corresponding global variables are not changed. 


CALL BY REFERENCE:- In this no new memory area is created for the local variables between form and endform. They make use of memory of the corresponding global variables. Hence when the values of local variables are changed between form and endform immediately the corresponding global variables values are changed.


CALL BY VALUE AND RESULT:-  In this new memory area is created for local variables. When ever the values of local variables are changed between form and endform, the changes are reflected in only newly created memory area. But when the control is moving back from subroutine to main program, the values present in local memory are copied back to the corresponding global variables memory area.


Hence we can say that in CALL BY VALUE the values of global variables are never changed when corresponding local variables values are changed, in CALL BY REFERENCE the values of global variables are changed immediately. In CALL BY VALUE AND RESULT the values of corresponding global variables are changed control moves from subroutine to main program.  

No comments:

Post a Comment