REPORT demo_mod_tech_example_1.
DATA: num1 TYPE i,
num2 TYPE i,
sum TYPE i.
num2 TYPE i,
sum TYPE i.
num1 = 2. num2 = 4.
PERFORM addit USING num1 num2 CHANGING sum.
PERFORM addit USING num1 num2 CHANGING sum.
num1 = 7. num2 = 11.
PERFORM addit USING num1 num2 CHANGING sum.
PERFORM addit USING num1 num2 CHANGING sum.
FORM addit
USING add_num1 TYPE any
add_num2 TYPE any
CHANGING add_sum TYPE any.
USING add_num1 TYPE any
add_num2 TYPE any
CHANGING add_sum TYPE any.
add_sum = add_num1 + add_num2.
PERFORM out USING add_num1 add_num2 add_sum.
PERFORM out USING add_num1 add_num2 add_sum.
ENDFORM.
FORM out
USING out_num1 TYPE any
out_num2 TYPE any
out_sum TYPE any.
USING out_num1 TYPE any
out_num2 TYPE any
out_sum TYPE any.
WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is',
out_sum.
ENDFORM.
This produces the following output:
Sum of 2
and 4
is 6
Sum of 7
and 11
is 18
In this example, the actual parameters num1, num2, and sum are passed by reference to the formal parameters of the subroutine addit. After changing add_sum, the latter parameters are then passed to the formal parameters out_num1, out_num2, and out_sum of the subroutine out.
Input parameters that are changed in the subroutine are also changed in the
calling program. To prevent this, you must pass the parameter as a value in a
USING addition.
Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Consultant
Contact : serkurumsal@yandex.com
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Consultant
Contact : serkurumsal@yandex.com
Social Plugin