Documente Academic
Documente Profesional
Documente Cultură
Use of Macros
Subroutines
Function Modules
1 DEFINE <macro_name>
2
3 'Macro Statements
4
5 END-OF-DEFINITION
Macros can use Parameters &N where N = 1,2,3...
Example:?
1
DATA: number1 TYPE I VALUE 1.
2
3
DEFINE increment.
4
5
ADD 1 to &1.
6
WRITE &1.
7
8
END-OF-DEFINITION.
9
10
Increment number1.
11
12
WRITE number1.
13
Output: 2
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
?
1 Include <include program Name>
Points to Note
Example:
?
1 INCLUDE ZILX0004.
2
3 WRITE: / 'User', SY-UNAME,/ 'Date', SY-DATUM.
4
5 ================================
6
7 PROGRAM ZRPM0001.
8
9 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.
Syntax?
1 FORM <Subroutine> [<pass>].
2
3 <Statement block>.
4
5 ENDFORM.
<Subroutine> = Name of the subroutine
<pass> = Parameters being passed
Types of Subroutines
1. Internal
o Subroutine defined in same program being called.
o Can access all the data objects declared in the main ABAP/4 program.
2. External
o Subroutine defined outside the program being called.
o Need to use the <pass> option or declare data objects in common parts of
memory.
Calling a Subroutine Internal Subroutines
?
1 PERFORM <subroutine> [<pass>]
<subroutine> = Name of the subroutine
Nested calls are allowed in subroutines (i.e. PERFORM within a FORM ... ENDFORM ).
To define local data, use the DATA statement after FORM . Each time you enter the
subroutine, the data is recreated (with an initial value) and released at the end (from the
stack).
To define global data used within a subroutine, use the LOCAL statement after FORM .
The values are saved when you enter the subroutine and then released at the end (from
the stack)
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?
1 FUNCTION <function module>
2
3 <Statements>
4
5 ENDFUNCTION.
Important information Associated with Function Module
Administration
Import/Changing/Export parameters.
Table Parameters/Exceptions.
Documentation
Global Data - L<fgrp>TOP .Global data for the function group- Accessible across
function modules in the function group.
Main Program - SAPL<fgrp> . Contains the list of all the include files for that function
group
f1 = a 1.... f n = a n]
[IMPORTING
f1 = 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
When you create a function group or function module, the main program and include
programs are generated automatically.