1. PERFORM
form.
2. PERFORM
form IN PROGRAM prog.
3.
PERFORM n OF form1 form2 form3 ... .
4.
PERFORM form ON COMMIT.
5.
PERFORM form ON ROLLBACK.
6. PERFORM form(prog).
PERFORM form.
1. ... TABLES
itab1 itab2 ...
2. ...
USING u1 u2 u3 ...
3. ... CHANGING c1 c2 c3 ...
Calls the subroutine form defined usng a FORM statement. After the subroutine has finished, processing continues after the PERFORM statement.
The order and number of parameters after
TABLES, USING,
and CHANGING depends strictly on the definition of the
subroutine interface in the FORM statement (position parameter).
If you use the
TABLES addition with FORM,
you must also use it at the start with PERFORM and specify
the correct number of table-like actual parameters after. With PERFORM
the additions USING and CHANGING
are synonymous. You can specify both additions or only one. It is only essential that the number, order,
and type of the specified actual parameters correspond to the formal parameters. However, for reasons
of protocol you should use the additions as with the definition of the subroutine in FORM.
PERFORM HELP_ME.
...
FORM HELP_ME.
...
ENDFORM.
The PERFORM statement calls the subroutine HELP_ME.
... TABLES itab1 itab2 ...
You must use TABLES to transfer internal
tables to subroutines whose interface definitions have a TABLES addition in the FORM statement.
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 DISPLAY subroutine, you can use all available
table operations on the transferred internal tables. For TABLES
parameters the system automatically creates a header, which may be filled with the contents of the actual parameter header.
... USING u1 u2 u3 ...
... CHANGING c1 c2 c3 ...
These additions must be followed by type-related actual parameters for all
USING and CHANGING
parameters of the called subroutine. The two additions are equivalent. Only the order of the parameters
is important. The first
USING or CHANGING
parameter of the PERFORM call is transferred to the first
USING or CHANGING
parameter of the subroutine, the second to the second, and so on. For documentation reasons you should, when calling, use the same addition as with the subroutine definition.
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.
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
ASSIGN NUMBER_P TO
PERFORM
CHANGE USING 1
NUMBER_I
NUMBER_P
PERSON
ALPHA+NUMBER_I(
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
PERSON-NAME = 'Paula'
PERSON-AGE =
25
ALPHA = 'abcde j'
PERFORM form IN PROGRAM prog.
1. ... TABLES
itab1 itab2 ...
2. ...
USING u1 u2 u3 ...
3. ... CHANGING c1 c2 c3 ...
4. ... IF FOUND
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.See Passing SY-REPID not allowed and Receiving SY-SUBRC not allowed.
External
PERFORM. Calls a subroutine form
of another ABAP program prog. You can transfer both the
subroutine name and the program name dynamically (at runtime); in this case you must enclose
form or prog
in brackets. The names transferred with
form or prog
must be in upper case, otherwise a runtime error will occur. If there are no subsequent addtional specifications
(for example USING), you do not need to specify the program
name after IN PROGRAM; in this case the system searches for the routine in the current program.
If you call a routine of a program prog, the system loads
this program prog into the PXA buffer (if it is not already there). For storage space reasons, you should not call too many subroutines belonging to different programs.
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'.
Dynamic PERFORM statements require more CPU time, since the system has to locate the subroutine each time.
... TABLES itab1 itab2 ...
See variant 1, addition 1.
... USING u1 u2 u3 ...
See variant 1, addition 2.
... CHANGING c1 c2 c3 ...
See variant 1, addition 3.
... IF FOUND
The system only calls the subroutine if it and its main program exist. If this is not the case, the statement is ignored.
PERFORM n OF form1 form2 form3 ... .
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.
PERFORM form ON COMMIT.
Calls the specified subroutine at COMMIT WORK. This allows you to delay
the subroutine until the logical transaction is finished through COMMIT
WORK. Even if you register the same subroutine more than once, it is only executed once.
While the subroutines registered with PERFORM ... ON COMMIT
are executed,
PERFORM ... ON COMMIT, PERFORM
... ON ROLLBACK
, COMMIT WORK or ROLLBACK
WORK must not be called again.
The ROLLBACK WORK statement deregisters all subroutines registered using this addition.
... LEVEL idx
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.
PERFORM form ON ROLLBACK.
Effect
The
specified subroutine is executed if a ROLLBACK WORK occurs. This allows
you, for example, to delete data, such as an internal table or data in memory, that was intended for
use in PERFORM...ON COMMIT. If you register the same subroutine
more than once, it will still only be executed once per ROLLBACK
WORK.
While the subroutines registered with PERFORM
... ON ROLLBACK are executed, PERFORM /.. ON COMMIT,
PERFORM ... ON ROLLBACK, COMMIT
WORK or ROLLBACK WORK must not be called again.
PERFORM form(prog).
1. ... TABLES
itab1 itab2 ...
2. ...
USING u1 u2 u3 ...
3. ... CHANGING c1 c2 c3 ...
4. ... IF FOUND
This variant is not allowed in an ABAP Objects context.See PERFORM form(prog) not allowed.
Calls the subroutine form defined in program prog ("external PERFORM").
... TABLES itab1 itab2 ...
See variant 1, addition 1.
... USING u1 u2 u3 ...
See variant 1, addition 2.
... CHANGING c1 c2 c3 ...
See variant 1, addition 3.
... IF FOUND
The specified subroutine is only called if the subroutine and its main program exist. Otherwise, the statement is ignored.
Non-Catchable Exceptions
Calling Subroutines