ABAP Keyword Documentation → ABAP − Reference → Obsolete Language Elements → Obsolete Modularization → Subroutines
FORM
Other versions: 7.31 | 7.40 | 7.54
Obsolete Syntax
FORM subr [TABLES table_parameters]
[USING parameters]
[CHANGING parameters]
[RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...].
...
ENDFORM.
Extras
1. ... TABLES table_parameters
2. ... USING parameters
3. ... CHANGING parameters
4. ... RAISING exc1|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...
Effect
The statement FORM
defines a
subroutine subr
and its interface.
Naming conventions apply to the subr
name. The functions of the subroutine subr
are implemented between the statements
FORM
and ENDFORM
. The additions define the formal parameters of the subroutine and declare the propagation of the
class-based exceptions to the caller.
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 master program can be accessed.
Subroutines are called using the statement PERFORM
.
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 specified only before USING
or CHANGING
.
If an internal table without header line or a
table body is passed as an actual parameter to this type of formal parameter, an empty local header
line is generated in the subroutine. If an internal table with header line is used as the actual parameter,
both the table body and the header line are passed to the subroutine. Pass by value is not possible in formal parameters defined using TABLES
.
Notes
-
Formal parameters defined using
TABLES
can be replaced by formal parameters defined usingUSING
orCHANGING
. A local work area can also be created in the subroutine using the additionLIKE LINE OF itab
of the statementDATA
. -
If
TABLES
is specified afterUSING
orCHANGING
, a formal parameter called "TABLES" is created.
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 in all operand positions that match their
typing and their modifiability defined by USING
or CHANGING
.
When the formal parameters parameter
are defined, either pass by reference or pass by value can be defined. The effect of this definition
for formal parameters defined with USING
and CHANGING
is as follows:
-
Pass by reference for
USING
parameters
The formal parametersp1 p2 ...
are handled exactly like those parameters defined for pass by reference usingCHANGING
. -
Pass by reference for
CHANGING
parameters
For the formal parametersp1 p2 ...
, no local data object is created in the subroutine. Instead, when it is called, a reference is passed to the specified actual parameter. A change to the formal parameter in the subroutine also changes the value of the actual parameter. -
Pass by value for
USING
parameters
For each formal parameterp1 p2 ...
, a local data object with the same data type as the corresponding actual parameter is created in the subroutine and filled with its values. A change to the formal parameter in the subroutine does not change the value of the actual parameter. The actual parameter also retains its original value even after the subroutine has ended. -
Pass by value for
CHANGING
parameters
For each formal parameterp1 p2 ...
, a local data object with the same data type as the corresponding actual parameter is created in the subroutine and filled with its values. A change to the formal parameter in the subroutine does not directly change the value of the actual parameter. If the subroutine is ended usingENDFORM
,RETURN
,CHECK
, orEXIT
however, the content of the formal parameter is assigned to the actual parameter. If the subroutine is ended by a message or an exception, the actual parameter remains unchanged.
Notes
-
Formal parameters defined for pass by reference with
USING
should not be changed in the subroutine. In this case,CHANGING
can be used instead. Modifying access toUSING
parameters produces syntax check warnings ifCHANGING
parameters are specified at the same time. -
The addition
CHANGING
should be used for the formal parameter whose value is changed in the subroutine. -
The order of
USING
andCHANGING
is not arbitrary. SpecifyingUSING
afterCHANGING
creates a formal parameter called "USING".
Example
In a subroutine, the formal parameter ptab
can be used in an operand position
that expects an index table, since it is typed accordingly. The formal parameter wa
is completely generic and the system waits until runtime to check whether it is suitable for the row 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|RESUMABLE(exc1) exc2|RESUMABLE(exc2) ...
Effect
The addition RAISING
can be used to pass class-based exceptions exc1 exc2 ...
, which are raised in or propagated to the subroutine by the
ABAP runtime environment
or using the statement RAISE EXCEPTION
or the addition THROW
in a
conditional expression, but are not handled
in a TRY
block. Subclasses of CX_STATIC_CHECK
and CX_DYNAMIC_CHECK can be declared explicitly. Subclasses of CX_NO_CHECK are always declared implicitly with the addition RESUMABLE
.
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. Each exception class may only be specified once.
If an exception for this superclass is raised that cannot be handled and cannot be passed on, this produces either a syntax error or an exception that must be handled by the caller CX_SY_NO_HANDLER.
The addition RESUMABLE
declares an exception that can be propagated as a resumable exception. This means:
- A resumable exception is therefore propagated as such
- The addition does not have any effect on a non-resumable exception.
-
If a resumable exception is propagated in
RAISING
and the additionRESUMABLE
is not specified, it thus becomes non-resumable.
If a superclass is declared as resumable, any subclasses must also be declared as resumable.
Notes
-
Exceptions that are based on the subclasses of CX_STATIC_CHECK and CX_DYNAMIC_CHECK must be handled
either in the subroutine or declared explicitly using the
RAISING
addition. For CX_STATIC_CHECK, this is checked during the syntax check; for CX_DYNAMIC_CHECK, the check is not performed until runtime. -
In a subroutine, in which class-based exceptions are declared using the addition
RAISING
, the obsolete statementCATCH SYSTEM-EXCEPTIONS
cannot be used to handle catchable runtime errors. Instead, the handleable exceptions assigned to the runtime errors should be handled in aTRY
control structure. -
An exception that is raised as a resumable exception in the subroutine using
RAISE RESUMABLE EXCEPTION
should also be declared as resumable in the interface, since the exception would otherwise lose this property when the method is exited. -
See also Class-Based Exceptions in Procedures.