Understanding Subroutines: A Modularization Technique within Programs

 

  • Subroutine is also a modularization technique.
  • A subroutine is a modularization unit with in the program itself.
  • There is no separate transaction code to create a subroutine.
  • A subroutine is a block of code introduced by FORM and ends with ENDFORM.

Types of Subroutines :-

  • There are two types of Subroutines :-

1. Internal Subroutines :-

  • Subroutines which are defined and used in a same program are called as internal subroutines.

2. External Subroutines :-

  • Subroutines which are created in one program and used in another program are called as external subroutines.

Syntax For Calling of Subroutine - Without Parameters :-

  • Syntax :- PERFORM <perform name>.

  • In the example PERFORM = keyword,

    add = name of the subroutine,

    the logic for the subroutine add is written between FORM and ENDFORM.




Syntax For Calling of Subroutine - With Parameters :-

  • PERFORM <perform name> TABLES <tables parameters> USING <using parameters> CHANGING <changing parameters>.

  • We cannot change the sequence of tables using changing, but if any of them



    • In the example PERFORM, USING and CHANGING = keywords,

      sum = name of the subroutine,

      p_input1 and p_input2 = using parameters,

      lv_output = changing parameters.


Subroutine :- Actual Parameters and Formal Parameters

  • Parameters names that appear on the PERFORM statement are called as actual parameters.


  • Parameter names that appear on the FORM statement are called formal parameters.

  • In the example - p_input1, p_input2,

    lv_output = actual parameters,

    pv_input1, pv_input2, pv_output = formal parameters.


Subroutine With Parameters - Important Points

  • Perform and form statement must contain the same number of parameters. It means number of actual parameters must be same as that of formal parameters.
  • The addition tables using and changing can only occur once in a statement.

Function Modules and Subroutines Comparison :-

  • There is a separate transaction code SE37 (workbench tool) to create a function module, whereas there is no separate workbench tool to create a subroutine.
  • We can check the output of function module using F8 (we can independently run a function module to check the output), whereas we cannot run a subroutine independently.

We will see the practical implementation in next part.

Comments

Popular posts from this blog

Introduction to OData | Ui5 | Fiori

ODATA topics necessary for SAP Ui5 / FIORI

Introduction to SAP