0% found this document useful (0 votes)
30 views10 pages

SAP ABAP - Modularization PDF

The document discusses modularization techniques in SAP ABAP, which involve breaking down application programs into smaller, manageable units to enhance readability, maintainability, and code reusability. It outlines various types of modularization techniques, including subroutines, includes, and function modules, detailing their definitions, advantages, and usage. Additionally, it provides insights into parameters, function groups, and interview questions related to modularization in SAP ABAP.

Uploaded by

sainathpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views10 pages

SAP ABAP - Modularization PDF

The document discusses modularization techniques in SAP ABAP, which involve breaking down application programs into smaller, manageable units to enhance readability, maintainability, and code reusability. It outlines various types of modularization techniques, including subroutines, includes, and function modules, detailing their definitions, advantages, and usage. Additionally, it provides insights into parameters, function groups, and interview questions related to modularization in SAP ABAP.

Uploaded by

sainathpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

SAP ABAP DOCUMENT

MODULARIZATION TECHNIQUES:

Modularisation is a technique used to divide the application program into smaller


units to maintain easily and reduce the code redundancy

Advantages of Modularisation Techniques—>

● Easy to read and understood


● Easy to maintain
● Easy to debug
● Eliminates code redundancy
● Increases reusability of code
Types of Modularisation techniques—>
1. SUBROUTINE
2. INCLUDE
3. FUNCTION MODULE
4. MACRO
NOTE-->
1. As an ABAP consultant we don’t use MACRO as this is to be used by HR
Consultants

1. SUBROUTINE

● Subroutines are procedures that can be defined in any program and called
from any ABAP program.
● Subroutines normally contain sections of code or algorithms.
● Subroutines can be defined anywhere in the program
● Subroutines can be defined using FORM and ENDFORM statements.
● PERFORM statement is used to call the subroutine

Syntax:

PERFORM PERFORM_NAME.

FORM FORM_NAME.

CODING.

ENDFORM.
SAP ABAP DOCUMENT

External subroutines

External subroutines are defined globally.


These can be used by other programs.
And can also be nested.

PERFORM PERFORM_NAME in program USing XXX.

FORM FORM_NAME using xxx.

CODING.

ENDFORM.

2. INCLUDE
● If the same set of statements (source code) is used in more than one program,
those statements can add to the include program.
● Include programs are only used to modularise the source code but have no
parameter interface.
● Include programs are not standalone programs and cannot be executed
independently.
● Include programs available globally and can be used in any ABAP program.
● Include programs contain small pieces of source code that can be included in a
program with an INCLUDE statement.
● INCLUDE programs can’t call themselves. The INCLUDE program must be
syntax error free and contain complete statements.
CONVENTION—> INCLUDE name should always start with either ‘y’ or ‘z’.

SYNTAX

INCLUDE ZINCLUDE_NAME.

NOTE--> We can write the declaration part inside of an INCLUDE.


SAP ABAP DOCUMENT

3. FUNCTION MODULE—>
● Function modules are subprograms that contain a set of reusable source code
statements with importing, exporting parameters and exceptions.
● Function modules are stored in the central library.Function modules available to
the entire system. Function modules can execute independently.
● If the source code is only used within the same program, then use a Subroutine.
Otherwise a function module is preferred.
● Every function module is a part of the function group. The function group acts as
a container for function modules that would logically belong together.
● Function modules plays significant role in updating the databases.

Types of FUNCTION MODULES—>


1. Normal Module
2. Remote Enable Module (RFC)
3. Update Function Module (not in use now)

Components of Function Module—>

● Import - Input parameters of a Function Module.


● Export - Output parameters of a Function Module.
● Changing - Specifies the parameters act as importing and exporting parameters
to a Function Module.

Steps to create a function module.

1. Create a function group using transaction code se80.


2. Create a function module using transaction code se37.
3. On the import tab write the requirements for importing parameters.
4. On the export tab write the requirements for exporting parameters.
5. Write the condition in the source code tab.

After executing the program click on the circled button to get the following output
screen.

CALLING FUNCTION MODULE IN ABAP PROGRAM

1. Click on the PATTERN option.


SAP ABAP DOCUMENT

2. Select CALL FUNCTION radio button and type the FUNCTION MODULE as per
requirement.
3. Remove commenting by selecting the statements and pressing ctrl + > .
4. Write code to display data.

Actual Parameter : these are the actual values passed to the subroutine
while calling the subroutine..

Formal Parameter : The formal parameters are the parameters that you
define in the subroutine declaration..

EX:

Data : v_x type i, “global variables

v_y type i.

Perform sub1 using v_x v_y. (actual parameters)

( or)

Perform sub1 using 20 30. (actual parameters)

Form sub1 using v_x v_y. (formal parameters)

(or)

Form sub1 using k1 k2. (formal parameters)


SAP ABAP DOCUMENT

Data v_z type i “ local variable

Endform.

To return values from subroutines we use CHANGING keyword.

Data : v_x type i, “global variables

v_y type i.

V_r1 type i.--- 0

V_r2 type i.--- 0

V_x = 40.

V_y = 30.

Perform sub1 using v_x v_y changing v_r1 v_r2.

Form sub1 using k1 k2 changing m1 m2.

M1 = k1 + k2.

M2 =k1-k2. endform.
SAP ABAP DOCUMENT

Interview questions on modularization


1. What is Modularization in SAP ABAP?
● Modularization essentially means – breaking things down into simpler forms.
● This also promotes reusability – that is, once you write a module to perform a specific
task, you can reuse the same module when having to perform the same task again.

Need & Advantages of SAP ABAP Modularization

● The modules, or processing blocks, enhance how we structure the program.


● They make it easy for us to read the code.
● They also make it easy to maintain the code.
● These help to avoid redundancy.
● They introduce ‘reusability’ features in code – i.e. we can reuse a block defined in one
area into another area as well.

Various Modularization Techniques in SAP ABAP

● Macros
● Include
● Subroutines
● Function Modules
● Methods & Classes

2. What includes programs in SAP ABAP?

● Include programs are used to split ABAP source code into individual repository objects.
An ABAP program can be created in the program attributes using the program type
include program.

3. What are subroutines?

● Subroutines are used to modularize the program. Generally Subroutines are called by
using the PERFORM keyword and defined within the FORM and ENDFORM block.

4. What are actual parameters and formal parameters?

● Actual Parameter : these are the actual values passed to the subroutine while
calling the subroutine..

PERFORM subroutine USING XXX

TABLES XXX or STRUCTURE XXX

CHANGING XXX
SAP ABAP DOCUMENT

RETURNING XXX.

● Formal Parameter : The formal parameters are the parameters that you define in
the subroutine declaration..

FORM subroutine USING XXX

TABLES XXX ( declaration ) or STRUCTURE XXX ( declaration )

CHANGING XXX

RETURNING XXX.

5. What is pass by reference and pass by values?

● By default all parameters are pass by reference.


● These concepts are generally used for Function modules or Subroutines etc.
For example, we are passing a variable lv_num using the function module -

CALL FUNCTION 'NEW_FM1'


EXPORTING
VAR = lv_num.

● When we PASS lv_num by VALUE, the actual value of lv_num is copied into VAR.
When we PASS lv_num by REFERENCE, the reference, or the memory address of
lv_num is passed to the Function module. So, VAR and lv_num refers to the same
memory address and have the same value.

6. What is the difference between the function module and a normal ABAP/4
subroutine?
● Subroutines do not return values. Subroutines do not return exceptions. Sub
routines cannot be tested independently.
● Declaring data as common parts is not possible for function modules. Function
modules are stored in a central library.

7. Can we call a subroutine in another program? and what is the syntax?


● Yes, we can call using external subroutines.

syntax-
perform form_tc(report_name).
SAP ABAP DOCUMENT

8. What are function modules in SAP ABAP?


● Function modules are ABAP routines that encapsulate program code and provide
an interface for data exchange. Function modules are stored in a central function
library. They are not application-specific and are available system-wide. The ABAP
Workbench comes with a large number of standard function modules.

Function Groups :

● Function groups (also called function pools) are ABAP programs of a special type. They
are the only program type that can contain function modules.

9. What are the components of the function modules?

● The key components of a function module in SAP ABAP are: Import parameters (input
data), Export parameters (output data), Changing parameters (data that can be
modified both as input and output), Internal tables (used for passing multiple data
values), and Exceptions (error handling mechanisms); all of these are defined within the
function module's interface to clearly define how data is exchanged with the calling
program.

Explanation of each component:

Import Parameters:
These are variables that are passed as input to the function module from the calling
program, and cannot be modified within the function module itself.
Export Parameters:
These are variables that carry the results calculated within the function module back to
the calling program as output data.
Changing Parameters:
These variables act as both input and output parameters, allowing the function module
to modify the data passed in and return the updated values.
Internal Tables:
These are data structures that can be used to pass multiple values as input or output to
a function module, enabling flexible data exchange.
Exceptions:
These are predefined error conditions that can be raised within the function module to
signal issues to the calling program, allowing for proper error handling.

10. Types of function modules in SAP ABAP?


There are a few types of function modules in SAP ABAP, including:
Normal Function Module
SAP ABAP DOCUMENT

The default option, which runs immediately and synchronously on the current SAP system

Remote Function Module (RFC)


Can communicate within and outside of SAP, and is often used to call information from
other systems

Update Function Module


Runs later in a process called an update work process, which can be started with the
statement COMMIT WORK
SAP ABAP DOCUMENT

You might also like