SUBROUTINES
FORM - ENDFORM
This statement is used to create subroutines.
PERFORM
This statement is used to invoke the subroutine created. Subroutines are used to call a piece of code frequently within the program or externally from other program.
LOCAL SUBROUTINES:
The subroutine is called locally from the same program using PERFORM statement.
Eg:
PERFORM NAME. FORM NAME. DO 5 TIMES. WRITE: / 'WELCOME TO ABAP'. ENDDO. ENDFORM.
Pass by value:
Only the copies of the actual parameter will be sent to formal parameter. In this case if you change the values of formal parameters it will not affect the actual parameter.
Eg:
DATA: A (10) VALUE 'INDIA', B TYPE I VALUE '20'. PERFORM NAME USING A B. FORM NAME USING X Y. X = 'BANGALORE'. Y = '100'. WRITE: / X, Y. ENDFORM.
Pass by reference:
Only the address of the actual parameter will be sent to formal parameter. In this case if you change the values of formal parameters it will not affect the actual parameter.
Eg:
DATA: A (10) VALUE 'INDIA', B TYPE I VALUE '20'. PERFORM NAME USING A B. FORM NAME USING X Y. WRITE: / X, Y. ENDFORM.
Macros:
A macro is a set of statements that can be used more than once in the ABAP program. For example, a macro can be useful for long calculations or for writing complex WRITE statements. A macro can be used only in that program in which it is created.
Syntax:
DEFINE macro. Statements END-OF-DEFINITION.