DATA: i_num1 TYPE I VALUE 10,
i_num2 TYPE I VALUE 20.
WRITE: / ‘I_NUM1=‘,i_num1 LEFT-JUSTIFIED,
‘I_NUM2=‘,i_num2 LEFT-JUSTIFIED.
PERFORM CALCULATOR USING i_num1 i_num2.
WRITE: / ‘I_NUM1=‘,i_num1 LEFT-JUSTIFIED,
‘I_NUM2=‘,i_num2 LEFT-JUSTIFIED.
FORM CALCULATOR USING NUM1 NUM2.
WRITE: / ‘ NUM1=‘,NUM1 LEFT-JUSTIFIED,
‘ NUM2=‘,NUM2 LEFT-JUSTIFIED.
NUM1 = NUM1 + 10.
NUM2 = NUM2 + 12.
ENDFORM.
运行结果很明显,如下图:
3)值传递参数并返回最终值(CALL BY VALUE AND RETURN RESULT)
传递参数的方式同值传递相同,但在子程序结束执行是会将传入参数变量的最终值回传一份给外部程序变量。
[Syntax]
FORM <subform> [.....] [CHANGING VALUE(f1)...]
PERFORM <subform> [.....] [CHANGING VALUE(f1)...]
CHANGING VALUE(f1)首先按CALL BY VALUE而后RETURN RESULT给外部变量.
[For Example]
DATA: i_num1 TYPE I VALUE 10,
i_num2 TYPE I VALUE 20,
i_num3 TYPE I.
WRITE: / ‘I_NUM1=‘,i_num1,
‘I_NUM2=‘,i_num2,
‘I_NUM3=‘,i_num3.