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.
SKIP.
PERFORM CALCULATOR USING I_NUM1 I_NUM2 CHANGING I_NUM3.
WRITE: /‘I_NUM1=‘,I_NUM1,
‘I_NUM2=‘,I_NUM2,
‘I_NUM3=‘,I_NUM3.
SKIP.
"一、 传递参数时将参数的地址(ADDRESS)传至子程序中,也就是子程序中的参数变量与外部程序的参数变量共享地址内的值。
"又叫CALL BY ADDRESS,若子程序中的参数变量的值发生了改变,那么,外部程序的实际变量的值也发生改变。
*FORM CALCULATOR USING NUM1 NUM2 CHANGING NUM3.
*
* NUM3 = NUM1 + NUM2.
* WRITE: ‘NUM1=‘,NUM1,
* ‘NUM2=‘,NUM2,
* ‘NUM3=‘,NUM3.
* ENDFORM.
"二、值传递就是将参数的值复制一份到另一个至内存地址中,所以在子程序中参数变量的值的改变不影响外部程序实际变量的值。
FORM CALCULATOR USING VALUE(NUM1) VALUE(NUM2) CHANGING SUM.
SUM = NUM1 + NUM2.
NUM1 = NUM1 * NUM2.
NUM2 = NUM1 * NUM2.
WRITE: /‘NUM1=‘,NUM1,
‘NUM2=‘,NUM2,
‘SUM=‘,SUM.
ENDFORM.
"三、传递参数的方式同值传递相同,但在子程序结束执行是会将传入参数变量的最终值回传一份给外部程序变量。
*FORM CALCULATOR USING NUM1 NUM2 CHANGING VALUE(TOTAL).
* TOTAL = NUM1 + NUM2.
* WRITE: / ‘NUM1=‘,NUM1,
* ‘NUM2=‘,NUM2,
* ‘TOTAL=‘,TOTAL,
* ‘I_NUM3=‘,I_NUM3.
* ENDFORM.
原文地址:https://www.cnblogs.com/salah/p/11917014.html