REPORT demo_mod_tech_example_2.
DATA: num  TYPE i VALUE 5,
      fac  TYPE i VALUE 0.
PERFORM fact USING num CHANGING fac.
WRITE: / 'Factorial of', num, 'is', fac.
FORM fact
       USING value(f_num) TYPE i
       CHANGING f_fact    TYPE i.
  f_fact = 1.
  WHILE f_num GE 1.
    f_fact = f_fact * f_num.
    f_num = f_num - 1.
  ENDWHILE.
ENDFORM.
This produces the following output:
Factorial of          5 is        120
To ensure that an input parameter is not changed in the calling program, even if it is changed in the subroutine, you can pass data to a subroutine by value. In this example, the factorial of a number num is calculated. The input parameter num is passed to the formal parameter f_num of the subroutine. Although f_num is changed in the subroutine, the actual parameter num keeps its old value. The output parameter fac is passed by reference. 




Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Consultant
Contact : serkurumsal@yandex.com