Professional Documents
Culture Documents
By Modularizing The ABAP/4 Program
By Modularizing The ABAP/4 Program
By Modularizing The ABAP/4 Program
SUBROUTINE
FUNCTION MODULE
METHODS
INCLUDES AND MACROS
METHODS: It describes the functions and behavior of classes and their instances in ABAP objects methods
must be defined in classes.
MACROS: Macros designed based on place holder (place holder works like pointers in c language but in case of
place holder changes effect on output.
INCLUDES: If I am defining the same variables in many programs, instead of defining in all programs we have
define all the variables in one program and that program is included or added to the programs whenever
needed thats called include program. It cannot be executed independently it has to include in a program.
SUBROUTINES:
A subroutine is a reusable section of code. Its like a mini program that can be called from another point in
your program. Subroutine is generally for local modularization i.e. they are generally called from the program
in which they defined.
We can use subroutine to write functions that are used repeatedly with in a program. You can define
subroutine in any ABAP programs.
Syntax for defining subroutine
FORM (subroutine name) (parameter (Optional))
-----------------------------------------------------------------------------------------------------END FORM.
Syntax for calling subroutines
PARAMENTERS IN SUBROUTINES
Parameters can be either local or reference to global variables. The memory
for local parameters is allocated when the subroutine is called & freed when it
ends. If we define variables on the form statement, the perform statement
must pass a value to each of these variables.
Global variables: A global variable is one that is defined outside of a
subroutine by using the tables or data statement. It can be accessed from any
point in the program be it inside an event or inside a subroutine.
Local variables: A local variables is a variable that is defined inside a
subroutine using local data or statics statement. It is said to be local to
subroutine.
The two types of parameters are:
Formal parameters: Parameter names that appear on the form statements are
called formal parameters.
Form s1 using P1
P1 = X.
Write:/ P1.
End form
1) Stop: Immediately leaves the subroutine & goes directly to the end of selection event.
2) Exit: It leaves the loop, subroutine or comes out of the program & display the result without any condition.
3. Check: It also comes or immediately leaves the subroutine but it depends on logical expression. If it is false
comes out of the loop or subroutine.
NExt notes
Syntax
DEFINE <macro_name>
Macro Statements
END-OF-DEFINITION
Macros can use Parameters &N where N = 1,2,3...
Example:DATA: number1 TYPE I VALUE 1.
DEFINE increment.
ADD 1 to &1.
WRITE &1.
END-OF-DEFINITION.
Increment number1.
Include Programs
Include Programs are solely for modularizing source code, and have
no parameter interface. Include programs allow you to use the same
source code in different programs. They can be useful if you have
lengthy data declarations that you want to use in different programs.
Syntax
Include <include program Name>
Points to Note
Include programs cannot call themselves.
Include programs must contain complete statements.
Example:
INCLUDE ZILX0004.
================================
PROGRAM ZRPM0001.
INCLUDE ZILX0004.
Subroutines
Subroutines are procedures that you can define in any ABAP program and
also call from any program. Subroutines are normally called internally,
that is, they contain sections of code or algorithms that are used
frequently locally. If you want a function to be reusable throughout the
system, use a function module.
SyntaxFORM <Subroutine> [<pass>].
<Statement block>.
ENDFORM.
<Subroutine> = Name of the subroutine
<pass> = Parameters being passed
Types of Subroutines
Internal
Subroutine defined in same program being called.
Can access all the data objects declared in the main ABAP/4 program.
External
Subroutine defined outside the program being called.
Need to use the <pass> option or declare data objects in common parts of
memory.
Function Modules
Function Modules are general purpose ABAP/4
routines that anyone can use. Infact , there are a
large number of standard function Modules
available.
Function Modules are organized into Function
Groups: Collections of logically related functions.
A Function module always belongs to a Function
Group.
Syntax FUNCTION <function module>
<Statements>
ENDFUNCTION.
[EXPORTINGf1 = a 1.... f n = a n]
[IMPORTINGf1 = a 1.... f n = a n]
[CHANGING f1 = a 1.... f n = a n]
[TABLES f1 = a 1.... f n = a n]
[OTHERS = ro]].
Function groups
Function groups are containers for function modules. Infact, there are a large number of standard
Function Groups. All of the function modules in a function group can access the global data of the
group.Like executable programs (type 1) and module pools (type M), function groups can contain
screens, selection screens, and lists.
Points to Note
FunThe ction Groups cannot be executed.
name of a function group can be up to 26 characters long.
When you create a function group or function module, the main program and include programs are generated
automatically.
Function groups encapsulate data.
How to create a Function Group
Goto Transaction SE80.
Select Program in the DropDown.
Write the name of the Function Group That you want to create. Generally User made Function groups start with
"Z". e.g. - <Z_FUNCTION_GROUP_NAME> . Hit Enter Key.
Note that The TOP Include is create by default if the user checks the option of creating a TOP include.
How to create a Function Module
Create a function Group (say "ZCAL").
Create a function module, set the attributes like (Function group, Application, Short Text and Process Type) and
Save.
Include file "LZCALU01" will have source code of first function module.
Include file "LZCALTOP" will have global data.
Main program "SAPLZCAL" contains