Variants:
1. PERFORM form.
2. PERFORM form IN PROGRAM prog.
3. PERFORM n OF form1 form2 form3 ... .
4. PERFORM n ON COMMIT.
5. PERFORM n ON ROLLBACK.
6. PERFORM form(prog).
Additions:
1. ... USING p1 p2 p3 ...
2. ... CHANGING p1 p2 p3 ...
3. ... TABLES itab1 itab2 ...
Effect
Calls the
subroutine form defined usng a
- FORM statement. After the subroutine has
finished, processing continues after the PERFORM statement. The
parameters of the subroutine are position parameters, and must be passed in
the call according to the definition of the formal parameters in the
corresponding FORM statement.
Example
PERFORM HELP_ME.
...
FORM HELP_ME.
...
ENDFORM.
The PERFORM statement calls the subroutine
HELP_ME.
Note
Runtime errors:
- PERFORM_PARAMETER_MISSING: The subroutine called has more
parameters than you passed to it.
-
- PERFORM_TOO_MANY_PARAMETERS: You passed more parameters to
the subroutine than it was expecting.
-
-
- PERFORM_CONFLICT_TAB_TYPE,
-
- PERFORM_STD_TAB_REQUIRED,
-
- PERFORM_CONFLICT_GENERIC_TYPE,
-
- PERFORM_BASE_WRONG_ALIGNMENT,
-
- PERFORM_PARAMETER_TOO_SHORT,
-
- PERFORM_CAST_DEEP_MISMATCH,
-
- PERFORM_TABLE_REQUIRED: The type of a parameter did not
correspond to the type specified in the FORM statement.
-
Effect
These two additions have an identical function. However, you should
always use the same addition as is used in the corresponding FORM
definition (for documentary reasons).
The statement passes the parameters p1 p2 p3 ... to
the subroutine. A subroutine may have any number of parameters.
The order in which you list the parameters is crucial. The first parameter in
the PERFORM statement is passed to the first formal parameter in the
FORM defintion, the second to the second, and so on.
You can specify offset and length of a parameter as variables. If you
use the addition '...USING p1+off(*) ', the parameter p1
will be passed with the offset off, but the length will not exceed
the total length of the field.
Example
DATA: NUMBER_I TYPE I VALUE 5,
NUMBER_P TYPE P VALUE 4,
BEGIN OF PERSON,
NAME(10) VALUE 'Paul',
AGE TYPE I VALUE 28,
END OF PERSON,
ALPHA(10) VALUE 'abcdefghij'.
FIELD-SYMBOLS <POINTER> TYPE ANY.
ASSIGN NUMBER_P TO <POINTER>.
PERFORM CHANGE USING 1
NUMBER_I
NUMBER_P
<POINTER>
PERSON
ALPHA+NUMBER_I(<POINTER>).
FORM CHANGE USING VALUE(PAR_1)
PAR_NUMBER_I
PAR_NUMBER_P
PAR_POINTER
PAR_PERSON STRUCTURE PERSON
PAR_PART_OF_ALPHA.
ADD PAR_1 TO PAR_NUMBER_I.
PAR_NUMBER_P = 0.
PAR_PERSON-NAME+4(1) = ALPHA.
PAR_PERSON-AGE = NUMBER_P + 25.
ADD NUMBER_I TO PAR_POINTER.
PAR_PART_OF_ALPHA = SPACE.
ENDFORM.
Field contents after the PERFORM statement:
NUMBER_I = 6
NUMBER_P = 6
<POINTER> = 6
PERSON-NAME = 'Paula'
PERSON-AGE = 25
ALPHA = 'abcde j'
-
If you want to pass the body of an internal table itab that
has a header line, you must use the notation itab[] (see Data
Objects). If you do not use the brackets, the header line of the tabel is
passed.
- The field types and lengths of the parameters remain the same. If a
parameter is changed within the subroutine, it will still have the changed
value after the subroutine has finished. This does not apply to parameters
passed using VALUE. werden.
-
- If you pass literals, they may not be changed unless you pass them to
a formal parameter defined with USING VALUE .
-
Effect
TABLES allows you to pass
internal tables
to a subroutine.
Example
TYPES: BEGIN OF ITAB_TYPE,
TEXT(50),
NUMBER TYPE I,
END OF ITAB_TYPE.
DATA: ITAB TYPE STANDARD TABLE OF ITAB_TYPE WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 100,
BEGIN OF ITAB_LINE,
TEXT(50),
NUMBER TYPE I,
END OF ITAB_LINE,
STRUC like T005T.
...
PERFORM DISPLAY TABLES ITAB
USING STRUC.
FORM DISPLAY TABLES PAR_ITAB STRUCTURE ITAB_LINE
USING PAR like T005T.
DATA: LOC_COMPARE LIKE PAR_ITAB-TEXT.
WRITE: / PAR-LAND1, PAR-LANDX.
...
LOOP AT PAR_ITAB WHERE TEXT = LOC_COMPARE.
...
ENDLOOP.
ENDFORM.
Within the subroutine DISPLAY, you can use any internal table
operation to work with the internal table that you passed to it.
Note
If you use TABLES, it must always be the
first addition in a PERFORM statement.
Additions:
1. ... USING p1 p2 p3 ...
2. ... CHANGING p1 p2 p3 ...
3. ... TABLES itab1 itab2 ...
4. ... IF FOUND
See Passsing SY-REPID not allowed and Receiving SY-SUBRC not
allowed.
Effect
This variant is similar to variant 2 (external perform).
However, here you can specify the names of both the subroutine and the program
in which it occurs dynamically at runtime. If you do this, you should place
the variables form and prog in parentheses. The names in
form and prog must be entered in uppercase, otherwise a
runtime error occurs. If you do not specify any additions (such as
USING ) you do not need to specify the program after IN PROGRAM.
In this case, the system looks for the subroutine in the current program.
Example
DATA: RNAME(30) VALUE 'WRITE_STATISTIC', "Form and program
"names must
PNAME(8) VALUE 'ZYX_STAT'. "be written in
"upper case
PERFORM (RNAME) IN PROGRAM ZYX_STAT.
PERFORM WRITE_STATISTIC IN PROGRAM (PNAME).
PERFORM (RNAME) IN PROGRAM (PNAME).
All three PERFORM statements have the same effect, that is,
they call the subroutine 'WRITE_STATISTIC' , which is defined in the
program 'ZYX_STAT'.
Notes
Dynamic PERFORM statements require more CPU time, since the
system has to locate the subroutine each time.
Note
Runtime errors:
- PERFORM_NOT_FOUND: Unable to find the specified
subroutine.
-
- LOAD_PROGRAM_NOT_FOUND: Unable to find the specified main
program.
-
- PERFORM_PROGRAM_NAME_TOO_LONG: The specified program cannot
exist because the program name is longer than 40 characters.
-
Effect
The system only calls the subroutine if it and its main program exist.
If this is not the case, the statement is ignored.
Effect
Calls the subroutine with the index n from the list of
subroutines in the statement. At runtime, n must contain a value
between 1 (first name) and the total number of subroutines listed in the
PERFORM statement (last name). The list can contain up to 256
subroutines.
Note
Runtime errors:
- PERFORM_INDEX_0: The specified index was too
small.
-
- PERFORM_INDEX_NEGATIVE: The specified index was
negative.
-
- PERFORM_INDEX_TOO_LARGE: The specified index was too
big.
-
Additions:
1. ... LEVEL idx
Effect
Calls the specified subroutine at the next COMMIT WORK
statement. This allows you to delay the subroutine until the logical
transaction is finished. Even if you register the same subroutine more than
once, it is only executed once. For further information, refer to
- COMMIT WORK. The ROLLBACK WORK
statement deregisters all subroutines registered using this addition.
Notes
- You cannot use USING or CHANGING with the ...
ON COMMIT addition. If you need to pass data to the subroutine, you must
place it in global variables or use the EXPORT ... TO MEMORY
statement.
-
- The PERFORM ... ON COMMIT statement can also be used during
update. The corresponding subroutine is called at the end of the update
task.
-
Effect
The LEVEL addition, followed by a field, determines the
sequence in which the specified subroutines will be executed at the COMMIT
WORK statement. The subroutines are called in ascending order of their
level. If you do not use the LEVEL addition, the subroutine assumes
the level zero. If two or more subroutines have the same level, they are
executed in the sequence in which they are called in the program. You assign
levels by defining constants in an include program. The level must have type
I.
Effect
The specified subroutine is executed if a