PERFORM参数传递
参数传递:
将主程序变量传递给子例程形式参数
传递类型
值传:子例程中参数变量的值的改变,不影响外部程序实际变量的值.
DATA:A TYPE I VALUE 3, B TYPE I VALUE 6, C TYPE I. WRITE:'A=',A,'B=',B,'C=',C. PERFORM ADD USING A B CHANGING C. WRITE:/ SY-ULINE. WRITE:/ 'A=',A,'B=',B,'C=',C."A B的值不会变 FORM ADD USING VALUE(D) VALUE(E) CHANGING F. D = D + 2. E = E - 4. F = D + E. WRITE:/ SY-ULINE. WRITE:/ 'A=',A,'B=',B,'C=',C,/ 'D=',D,'E=',E,'F=',F. "A B的值不会变 ENDFORM.
引用传:若子例程中的参数变量的值发生了改变,那么,外部程序的实际变量的值也发生改变.
DATA:A TYPE I VALUE 3, B TYPE I VALUE 6, C TYPE I. WRITE:'A=',A,'B=',B,'C=',C. PERFORM ADD USING A B CHANGING C. WRITE:/ SY-ULINE. WRITE:/ 'A=',A,'B=',B,'C=',C."A B的值不会变 FORM ADD USING D E CHANGING F. D = D + 2."提示不应该更改 USING 参考参数。而应将参数定义为USING-VALUE(...) 或 CHANGING 参数as a USING-VALUE(...) or CHANGING parameter. E = E - 4."提示不应该更改 USING 参考参数。而应将参数定义为USING-VALUE(...) 或 CHANGING 参数as a USING-VALUE(...) or CHANGING parameter. F = D + E. WRITE:/ SY-ULINE. WRITE:/ 'A=',A,'B=',B,'C=',C,/ 'D=',D,'E=',E,'F=',F. "A B的值会变 ENDFORM.
值传并返回结果:传递参数的方式同值传递相同,但在子例程执行过程中,变量值不改变,而结束执行后,把变量的最终值返回.
DATA:A TYPE I VALUE 3, B TYPE I VALUE 6, C TYPE I. WRITE:'A=',A,'B=',B,'C=',C. PERFORM ADD USING A B CHANGING C. WRITE:/ SY-ULINE. WRITE:/ 'A=',A,'B=',B,'C=',C."A B的值不会变 FORM ADD USING D E CHANGING VALUE(F). D = D + 2."提示不应该更改 USING 参考参数。而应将参数定义为USING-VALUE(...) 或 CHANGING 参数as a USING-VALUE(...) or CHANGING parameter. E = E - 4."提示不应该更改 USING 参考参数。而应将参数定义为USING-VALUE(...) 或 CHANGING 参数as a USING-VALUE(...) or CHANGING parameter. F = D + E. WRITE:/ SY-ULINE. WRITE:/ 'A=',A,'B=',B,'C=',C,/ 'D=',D,'E=',E,'F=',F. "A B的值会变,C的值不会变 ENDFORM.