FORM form [TABLES ...] [USING ...] [CHANGING ...].
1. ...
TABLES itab1 ...
itabn
2. ...
USING [VALUE(p1)|p1] ... [VALUE(pn)|pn]
3. ...
CHANGING [VALUE(p1)|p1] ... [VALUE(pn)|pn]
4. ... RAISING cx1 ... cxn
Defines a subroutine called by PERFORM
You can assign a type to the parameters of the subroutine. For details about types of formal parameters, see specifying forms.
PERFORM WELCOME.
FORM WELCOME.
WRITE / 'Hello world'.
ENDFORM.
The subroutine
WELCOME called by the PERFORM statement outputs 'Hello world'.
... TABLES itab1 ... itabn
Instead of the
TABLES addition, you should use the USING or
CHANGING addition wherever possible. You can only use
tables with table type STANDARD
in the TABLES addition. The internal
tables you specify are always passed to the FORM along
with their header line. If you pass a table without header line as a TABLES
parameter, the system automatically generates a header line for it. This is only valid within the
FORM
. You should not use any global commands (such as
HIDE) on the header line. For details about specifying
the type of a TABLES parameter, see specifying
types. TABLES parameters are always passed by reference.
TYPES: BEGIN OF T_X.
INCLUDE STRUCTURE SFLIGHT.
TYPES:
ADDITION(8) TYPE C,
END OF T_X.
...
DATA: X
TYPE STANDARD TABLE OF T_X WITH NON-UNIQUE
DEFAULT KEY INITIAL
SIZE 0.
FORM U TABLES X STRUCTURE SFLIGHT.
...
PERFORM U TABLES X.
...
FORM U TABLES X STRUCTURE SFLIGHT.
WRITE: X-FLDATE.
ENDFORM.
... USING [VALUE(p1)|p1] ... [VALUE(pn)|pn]
Defines formal parameters
p1,...pn, which
are replaced by actual parameters when the subroutine is called.
You can assign a type to the formal
parameters p1, ..., pn (see specifying types). You can also specify the method with which they are passed.
Passing methods:
TYPES: BEGIN OF FLIGHT_STRUC,
FLCARRID LIKE SFLIGHT-CARRID,
PRICE LIKE SFLIGHT-FLDATE,
END OF FLIGHT_STRUC.
DATA: MY_FLIGHT TYPE
TABLE OF FLIGHT_STRUC,
IBOOK1 TYPE TABLE
OF SBOOK,
IBOOK2 LIKE TABLE OF IBOOK1,
STRUC TYPE SBOOK.
PERFORM DISPLAY
USING MY_FLIGHT IBOOK1 IBOOK2 STRUC.
FORM DISPLAY USING P_ITAB LIKE MY_FLIGHT[]
P_BOOK1
LIKE IBOOK1[]
P_BOOK2
LIKE IBOOK2[]
P_STRU LIKE STRUC.
DATA: L_FLIGHT LIKE LINE OF P_ITAB,
L_CARRID LIKE
L_FLIGHT-FLCARRID.
...
WRITE: / P_STRU-CARRID, P_STRU-CONNID.
...
LOOP AT P_ITAB INTO L_FLIGHT WHERE FLCARRID = L_CARRID.
...
ENDLOOP.
ENDFORM.
... CHANGING [VALUE(p1) |(p1)] ... [VALUE(pn) |(pn)]
The parameters after CHANGING can accept the same specifications
as those after
USING.
To link the VALUE
specification with the change of a parameter value, you can use the addition
CHANGING ... . Then, all the formal parameters specified
by VALUE(...) are transported back to the actual parameters
at the end of the subroutine (i.e. after ENDFORM). If
the subroutine is terminated by a dialog message, none of the parameters referenced by
CHANGING VALUE ... changes.
Otherwise, the effect of
USING and CHANGING is identical.
DATA: NUMBER_1 TYPE I VALUE 1,
NUMBER_2 TYPE I VALUE 2,
TEXT_1(10) VALUE
'one',
TEXT_2(10) VALUE 'two'.
PERFORM CONFUSE USING NUMBER_1
NUMBER_2
TEXT_1
NUMBER_1
TEXT_2.
FORM CONFUSE USING PAR_NUMBER_1 TYPE I
PAR_NUMBER_2 TYPE I
PAR_TEXT_1 TYPE C
VALUE(PAR_V_NUMBER_1) TYPE I
VALUE(PAR_V_TEXT_2) TYPE C.
ADD 3 TO PAR_V_NUMBER_1.
ADD 4 TO PAR_NUMBER_1.
ADD NUMBER_1 TO PAR_NUMBER_2.
TEXT_2 = 'three'.
PAR_TEXT_1 = PAR_V_TEXT_2.
PAR_V_TEXT_2 = 'four'.
ENDFORM.
Field contents after the
PERFORM call:
NUMBER_1
= 5
NUMBER_2 = 7
TEXT_1 = 'two'
TEXT_2 = 'three'
... RAISING cx1 ... cxn
The addition you can use for the definition of METHODS, FORM and FUNCTION informs the calling program which class-based exceptions can occur.
After RAISING, you therefore list the exception classes whose exceptions may occur and which cannot be caught locally within the procedure. You may only specify classes of the categories CX_STATIC_CHECK and CX_DYNAMIC_CHECK. It is possible to specify superclasses to declare groups of exceptions in a simple manner. Since the order of the exceptions is important to the CATCH clause, you must specify the exception classes according to their inheritance hierarchy even if you declare them in ascending order.
If the interface is violated at runtime for exceptions of the categories CX_STATIC_CHECK and CX_DYNAMIC_CHECK - that is, an exception of this type leaves a procedure and the exception was not defined in the RAISING clause - the system triggers an exception of the class CX_SY_NO_HANDLER and stores a reference to the original exception in the attribute PREVIOUS. (Any handler for such an exception then does not catch the original exception but instead a programming error in the procedure called.)
The addition may only be used for the definition of METHODS and FUNCTIONS if the addition EXCEPTIONS (for exceptions that are not class-based) is not used simultaneously. Also, using the RAISING addition within the procedure defined that way means the following restrictions:
In subroutines, you are recommended to use the following procedure:
Defining Subroutines