Ex:
Steps
- Go to transaction code SE38.
DATA : FACT TYPE I.
PARAMETERS : NUM TYPE I.
PERFORM FACTORIAL USING NUM CHANGING FACT.
WRITE : 'FACTORIAL OF ', NUM , '=', FACT.
*&---------------------------------------------------------------------*
*& Form FACTORIAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_NUM text
* <--P_FACT text
*----------------------------------------------------------------------*
form FACTORIAL using p_num
changing p_fact.
P_FACT = 1.
WHILE P_NUM >= 1..
p_fact = p_fact * P_NUM.
P_NUM = P_NUM - 1.
ENDWHILE.
endform. " FACTORIAL
PARAMETERS : NUM TYPE I.
PERFORM FACTORIAL USING NUM CHANGING FACT.
WRITE : 'FACTORIAL OF ', NUM , '=', FACT.
*&---------------------------------------------------------------------*
*& Form FACTORIAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_NUM text
* <--P_FACT text
*----------------------------------------------------------------------*
form FACTORIAL using p_num
changing p_fact.
P_FACT = 1.
WHILE P_NUM >= 1..
p_fact = p_fact * P_NUM.
P_NUM = P_NUM - 1.
ENDWHILE.
endform. " FACTORIAL
-------------------------------------------------------------
Output
Note : Variable value has been changed. So pass the variable using pass by Value.
No comments:
Post a Comment