Hello,

Sign up to join our community!

Welcome Back,

Please sign in to your account!

Forgot Password,

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

SAP EWM Help Latest Questions

  • 0
  • 0
DPM125

Subroutines in SAP

A subroutine is a block of reusable code defined using FORM and called using PERFORM. It is a procedural method of modularization mainly used in classical ABAP programming.

 When to use:

  • In classic procedural ABAP programs.
  • For logic reuse in the same or other programs via INCLUDE.
*&---------------------------------------------------------------------*
*& Report  ZREP_LCLCLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zrep_lclclass.

DATAlv_a TYPE VALUE 5,
      lv_b TYPE VALUE 10,
      lv_result TYPE VALUE 0.

WRITE/ 'Before subroutine call:',
       / 'lv_a ='lv_a,
       / 'lv_b ='lv_b,
       / 'lv_result ='lv_result.

* Call the subroutine
PERFORM calculate_sum USING    lv_a     " passed by value (copy)
                              lv_b     " passed by value (copy)
                       CHANGING lv_result.  " passed by reference (direct)

WRITE/ 'After subroutine call:',
       / 'lv_a ='lv_a,
       / 'lv_b ='lv_b,
       / 'lv_result ='lv_result.

*------------------------------------------------------------------*
* Subroutine Definition
*------------------------------------------------------------------*
FORM calculate_sum USING    p_a TYPE i
                            p_b TYPE i
                   CHANGING p_sum TYPE i.

  p_a p_a + 1.  " Modifies copy (no effect on lv_a)
  p_b p_b + 1.  " Modifies copy (no effect on lv_b)

  p_sum p_a + p_b.  " Modifies original lv_result (by reference)

ENDFORM. 

Output:

Related Questions

Leave an answer

Leave an answer