Tip

Recursive perform statement sample

This source is an example of Recursive Perform Statement. This is not a useful source for your project, but for thosewho studies Recursive Perform Statements, this can be a useful example of ABAP Recursive Perform Statement.


*Writen By Hakchin.
*We can get the factorial of number 5.
*5*4*3*2*1=120

DATA fa TYPE p VALUE 5.
DATA result TYPE p.
BREAK-POINT.
PERFORM factorial USING    fa
                  CHANGING result.
WRITE:/ fa, / result.
*&---------------------------------------------------------------------*
*&      Form  factorial
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FA  text
*      <--P_RESULT  text
*----------------------------------------------------------------------*
FORM factorial USING    value(p_fa)
               CHANGING value(p_result).
  DATA l_fa TYPE p.
  p_result = l_fa = p_fa.
  p_fa = p_fa - 1.
  IF p_fa > 1.
    PERFORM factorial USING    p_fa
                      CHANGING p_result.
  ENDIF.
  IF p_fa = 1.
    p_result = p_result * p_fa.
  ELSE.
    p_result = p_result * l_fa.
  ENDIF.
ENDFORM.                    " factorial


Output:
              5
            120

    Requires Free Membership to View

This was first published in April 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.