Site icon DataFlair

Modularization in SAP ABAP

modularization techniques in sap abap

FREE Online Courses: Click for Success, Learn for Free - Start Now!

In this tutorial, we’ll be learning about SAP ABAP modularization techniques. They make programs readable, flexible, and reusable. Let’s dive right into the world of modules!

What is Modularization in SAP ABAP?

Need & Advantages of SAP ABAP Modularization

Various Modularization Techniques in SAP ABAP

  1. Macros
  2. Include Files
  3. Subroutines
  4. Function Modules
  5. Methods & Classes

Modularization can be of two broad categories –

  1. Modules through source code
      1. Local Macros
      2. Glocal Include
  2. Modules at ABAP programs (processing blocks)
      1. Subroutines
      2. Function modules

SAP- ABAP Macro

SYNTAX

DEFINE <macro_name>.
        ...
        <STATEMENTS>
        ...
        END-OF-DEFINITION.

EXAMPLE

DEFINE ZDATAFLAIR_MACRO.
        
        WRITE: “This is the first macro.”.
        WRITE: “This is the second macro.”.
        WRITE: “This is the third macro.”.
        WRITE: “This is the fourth macro.”.
        WRITE: “This is the fifth macro.”.

        END-OF-DEFINITION.

OUTPUT

This is the first macro.
This is the second macro.
This is the third macro.
This is the fourth macro.
This is the fifth macro.

Include Programs

SYNTAX

INCLUDE <program_name>

EXAMPLE

ZS_DATAFLAIR_001:

REPORT ZS_DATAFLAIR_001.
INCLUDE ZDATAFLAIR.
WRITE: “Hello, this is the parent program.”.

ZDATAFLAIR:

WRITE: “Hello, this is the INCLUDE program.”.

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

OUTPUT

Hello, this is the INCLUDE program.
Hello, this is the parent program

However, there are a few rules we should keep in mind while using INCLUDE:

  1. Include programs cannot include themselves.
  2. The code within a program that we want to include must contain complete statements.

Subroutines in SAP ABAP

SYNTAX

FORM <subroutine_name>.
…
<statements>
…
ENDFORM.

EXAMPLE

FORM ZF_DATAFLAIR_001.
WRITE: “This is a form.”.
ENDFORM.

OUTPUT

This is a form.

Types of SAP ABAP Subroutines

  1. Internal subroutines:
    • If a subroutine is in the same program which is being called, we call it an internal subroutine.
    • An internal subroutine is allowed to access data objects in the program.
  2. External subroutines:
    • If a subroutine is outside the program which is being called, we call it an external subroutine.
    • An external subroutine is not allowed to access data objects in the program and has to use the PASS option for access.

Calling an internal subroutine

SYNTAX

PERFORM <subroutine_name> [<parameters_to_pass>]

EXAMPLE

PERFORM <ZF_DATAFLAIR_001>		“Since there are no parameters in our example

OUTPUT

This is a form.
Calling an external subroutine

SYNTAX

PERFORM <subroutine_name> (<Program>)[<parameters_to_pass>]

EXAMPLE

PERFORM <ZF_DATAFLAIR_001> (ZR_SS_DATAFLAIRSAMPLE_001)

OUTPUT

This is a form.

Function Modules in SAP ABAP

SYNTAX

FUNCTION <function_name>
…
<statements>
…
ENDFUNCTION.

EXAMPLE

FUNCTION ZF_DATAFLAIR
WRITE: “This is statement 001.”.
WRITE: “This statement can be executed independently of statement 001.”.
ENDFUNCTION.

CALLING ABOVE FUNCTION MODULE

CALL FUNCTION <module_name>
        [EXPORTING <exporting_parameters>]
        [IMPORTING <importing_parameters>]
        [CHANGING <changing_parameters>]
        [TABLES <table_names>]
        [EXCEPTIONS <exception_names>]
        [OTHERS = ro]

OUTPUT

This is statement 001.
This statement can be executed independently of statement 001.

Function Groups in SAP ABAP

How to Create a Function Group & Function Module

  1. Open the SAP system.
  2. Click on tcode input box and type in ‘SE80’.
  3. You will get a dropdown menu, from which you will select ‘Program’.
  4. Now we will write the name of the function group (must start with ‘Z’).
  5. Function group is created.
  6. Now that the function group is opened, you get the option to directly create a function module.
  7. Add its name and properties, include necessary files that have its source code and hit enter.
  8. Save, test and activate the created function module.

Methods & Classes in SAP ABAP

Summary

Thus, we learnt in this tutorial about the various techniques of modularization in ABAP. We learnt the meaning and use of modularization techniques, and the various types in ABAP. We also saw a few examples and tutorials on how to use the techniques.

Exit mobile version