FORM

Short Reference

Syntax

FORM subr [TABLES table_parameters]
          [USING parameters]
          [CHANGING parameters]
          [RAISING exc1 exc2 ... ].
  ...
ENDFORM.

Extras:

1. ... TABLES table_parameters

2. ... USING parameters

3. ... CHANGING parameters

4. ... RAISING exc1 exc2 ...

Effect

The FORM statement defines a subr subroutine and its interface. The naming conventions apply to the subr name. The subroutine's functionality is implemented between the statements FORM and ENDFORM. The additions define the formal parameters of the subroutine and the propagation of the class-based exceptions to the caller is declared.

Local data types and data objects can be declared within the subroutine. Furthermore, the formal parameters of the subroutine and the global data types and data objects of the frame program can be accessed.

You call a subroutine using the PERFORM statement.

Addition 1

... TABLES table_parameters

Effect

TABLES is used to declare table parameters table_parameters. Table parameters are obsolete formal parameters that are typed as internal standard tables with header lines. The addition TABLES can be listed only before USING or CHANGING.

If an internal table without header line or a table body is transferred as an actual parameter to this type of formal parameter, then an empty local header line is generated in the subroutine. If an internal table with header line is used as the actual parameter, then both the table body and the header line are passed to the subroutine. For formal parameters defined with TABLES, no pass by value is possible.

Notes

Addition 2

... USING parameters

Addition 3

... CHANGING parameters

Effect

These additions define formal parameters parameters. Formal parameters can be used in the subroutine as data objects at all operand positions that match their typing and their changeability defined by USING or CHANGING.

When you define the formal parameters parameter, you have the option of defining either pass by reference or pass by value. The effect of this definition for formal parameters defined with USING and CHANGING is as follows:

Notes

Example

In a subroutine, the formal parameter ptab can be used at an operand position that expects an index table, since it is typed accordingly. The formal parameter wa is completely generic and the system does not check until runtime whether it is suitable for the line type of the internal table.

FORM fill_table USING    wa   TYPE any
                CHANGING ptab TYPE INDEX TABLE.
  APPEND wa TO ptab.
ENDFORM.

Addition 4

... RAISING exc1 exc2 ...

Effect

With the addition RAISING, class-based exceptions exc1 exc2 ... can be passed, which are triggered in or propagated to the subroutine by the ABAP runtime environment or using the statement RAISE EXCEPTION, but are not handled in a TRY block. Subclasses of CX_STATIC_CHECK and CX_DYNAMIC_CHECK can be implicitly declared. Subclasses of CX_NO_CHECK are implicitly declared.

For exc1 exc2 ..., all exception classes that are visible at this point that are subclasses of CX_STATIC_CHECK CX_DYNAMIC_CHECK can be specified here. The exception classes must be specified in ascending order with respect to their inheritance hierarchy.

If an exception for this superclass occurs, which can be neither handled nor passed on, this leads to either a syntax error or an exception that must be handled by the caller CX_SY_NO_HANDLER.

Notes