PERFORM

Variants:

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).

Variant 1

PERFORM form.

Extras:

1. ... TABLES   itab1 itab2 ...

2. ... USING    u1 u2 u3 ...

3. ... CHANGING c1 c2 c3 ...

Effect

Calls the subroutine form defined usng a FORM statement. After the subroutine has finished, processing continues after the PERFORM statement.

Note

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.

Example

PERFORM HELP_ME.
...
FORM HELP_ME.
  ...
ENDFORM.

The PERFORM statement calls the subroutine HELP_ME.

Addition 1

... TABLES itab1 itab2 ...

Effect

You must use TABLES to transfer internal tables to subroutines whose interface definitions have a TABLES addition in the FORM statement.

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 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.

Addition 2

... USING    u1 u2 u3 ...

Addition 3

... CHANGING c1 c2 c3 ...

Effect

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.

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 TYPE ANY.
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
   = 6
PERSON-NAME = 'Paula'
PERSON-AGE  = 25
ALPHA       = 'abcde    j'

Notes

  1. 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.


  2. 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.


  3. If you pass literals, they may not be changed unless you pass them to a formal parameter defined with USING VALUE.


Variant 2

PERFORM form IN PROGRAM prog.

Extras:

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.

Effect

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.

Note

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.

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.

Addition 1

... TABLES itab1 itab2 ...

Effect

See variant 1, addition 1.

Addition 2

... USING u1 u2 u3 ...

Effect

See variant 1, addition 2.

Addition 3

... CHANGING c1 c2 c3 ...

Effect

See variant 1, addition 3.

Addition 4

... IF FOUND

Effect

The system only calls the subroutine if it and its main program exist. If this is not the case, the statement is ignored.

Variant 3

PERFORM n OF form1 form2 form3 ... .


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.

Variant 4

PERFORM form ON COMMIT.

Extras:

1. ... LEVEL idx

Effect

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.

Notes

  1. 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 MEMORYstatement.
  2. The PERFORM ... ON COMMIT statement can also be used during update. The corresponding subroutine is called at the end of the update task.

Addition 1

... LEVEL idx

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.

Variant 5

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.

Notes

  1. Subroutines registered using PERFORM... ON COMMIT cannot have USING or CHANGING parameters. Any data you want to pass to them must be contained in global variables or buffered using EXPORT ... TO MEMORY.
  2. If you catch a type A message (MESSAGE) using the EXCEPTIONS..ERROR_MESSAGE addition in the CALL FUNCTION statement, a ROLLBACK WORK occurs, in which the subroutines registered using PERFORM ... ON ROLLBACK are executed.

Variant 6

PERFORM form(prog).

Extras:

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.

Effect

Calls the subroutine form defined in program prog ("external PERFORM").

Notes

  1. You pass parameters to the external subroutine as described in variant 1.


  2. However, you can also do it using a shared data area (DATA BEGIN OF COMMON PART).


  3. Please consult Data Area and Modularization Unit Organization documentation as well.


  4. You can use nested calls, including several different subroutines in different programs.


  5. When you call a subroutine that belongs to a program prog, prog is loaded into the PXA buffer (if it has not been loaded already). To minimize the possibility of memory problems, try not to use too many external subroutines from a large number of different programs.


Addition 1

... TABLES itab1 itab2 ...

Effect

See variant 1, addition 1.

Addition 2

... USING u1 u2 u3 ...

Effect

See variant 1, addition 2.

Addition 3

... CHANGING c1 c2 c3 ...

Effect

See variant 1, addition 3.

Addition 4

... IF FOUND

Effect

The specified subroutine is only called if the subroutine and its main program exist. Otherwise, the statement is ignored.

Notes

Exceptions

Non-Catchable Exceptions

Additional help

Calling Subroutines