Sie sind auf Seite 1von 2

Calling Subroutines

You call subroutines using the statement


PERFORM... [USING ... <pi>... ]
[CHANGING... <pi>... ].
Subroutines can call other subroutines (nested calls) and may also call themselv
es (recursive calls). Once a subroutine has finished running, the calling progra
m carries on processing after the PERFORM statement. You can use the USING and C
HANGING additions to supply values to the parameter interface of the subroutine.
With the PERFORM statement, you can call subroutines which are coded in the same
ABAP program (internal calls), or subroutines which are coded in other ABAP pro
grams (external calls).
You can also specify the name of the subroutine dynamically at runtime, and call
subroutines from a list.
Internal Subroutine Calls
To call a subroutine defined in the same program, you need only specify its name
in the PERFORM statement:
PERFORM <subr> [USING ... <pi>... ]
[CHANGING... <pi>... ].
The internal subroutine can access all of the global data of the calling program
.
External subroutine calls
The principal function of subroutines is for modularizing and structuring local
programs. However, subroutines can also be called externally from other ABAP pro
grams. In an extreme case, you might have an ABAP program that contained nothing
but subroutines. These programs cannot run on their own, but are used by other
ABAP programs as pools of external subroutines.
However, if you want to make a function available throughout the system, you sho
uld use function modules instead of external subroutines. You create function mo
dules in the ABAP Workbench using the Function Builder. They are stored in a cen
tral library, and have a defined release procedure.
You can encapsulate functions and data in the attributes and methods of classes
in ABAP Objects. For any requirements that exceed pure functions, you can use gl
obal classes instead of external subroutines.
When you call a subroutine externally, you must know the name of the program in
which it is defined:
PERFORM <subr>(<prog>) [USING ... <pi>... ]
[CHANGING... <pi>... ] [IF FOUND].
You specify the program name <prog> statically. You can use the IF FOUND option
to prevent a runtime error from occurring if the program <prog> does not contain
a subroutine <sub>. In this case, the system simply ignores the PERFORM stateme
nt.
When you call an external subroutine, the system loads the whole of the program
containing the subroutine into the internal session of the calling program (if i
t has not already been loaded).
Specifying Subroutines Dynamically
You can specify the name of a subroutine and, in the case of external calls, the
name of the program in which it occurs, dynamically as follows:
PERFORM (<fsubr>)[IN PROGRAM (<fprog>)][USING ... <pi>... ]
[CHANGING... <pi>... ]
[IF FOUND].
The names of the subroutine and the external program are the contents of the fie
lds <fsubr> and <fprog> respectively. By using the option IF FOUND, you can prev
ent a runtime error from being triggered if <fprog> does not contain a subroutin
e with the name <fsubr>. If you omit the parentheses, this variant of the PERFOR
M statement behaves like the static variant.

Das könnte Ihnen auch gefallen