FORM

FORM Syntax Diagram

Basic form

FORM form [TABLES parameter] [USING parameter] [CHANGING parameter].

1. ... TABLES itab1 ... itabn
2. ... USING [VALUE(p1)| p1] ... [VALUE(pn) |pn]
3. ... CHANGING [VALUE(p1(| p1] ... [VALUE(pn) |pn]

Effect

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.

Example

PERFORM WELCOME. 
 
FORM WELCOME. 
  WRITE / 'Hello world'. 
ENDFORM.

The subroutine WELCOME called by the PERFORM statement outputs 'Hello world'.

Subroutines defined by FORM can have parameters and local fields. These parameters and local fields shadow global fields. Their visibility begins at their declaration, and ends at the ENDFORM statement.

Effect

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.

Example

DATA: BEGIN OF X OCCURS 0. 
		INCLUDE STRUCTURE SFLIGHT. 
DATA:   ADDITION(8) TYPE C, 
	END OF X. 
... 
PERFORM U TABLES X. 
... 
FORM U TABLES X STRUCTURE SFLIGHT. 
  WRITE: X-FLDATE. 
ENDFORM.

Effect

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.

Note

Passing methods:

Example

TYPES: BEGIN OF FLIGHT_STRUC, 
		 FLCARRID LIKE SFLIGHT-CARRID, 
		 PRICE	LIKE  SFLIGHT-FLDATE, 
	 END   OF FLIGHT_STRUC. 
 
DATA: MY_FLIGHT TYPE FLIGHT_STRUC OCCURS 0, 
	IBOOK1	LIKE SBOOK		OCCURS 0, 
	IBOOK2	LIKE IBOOK1	 OCCURS 0, 
	STRUC	 LIKE 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.

Addition 3

... CHANGING [VALUE(p1) |(p1)] ... [VALUE(pn) |(pn)]

Effect

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.

Example

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'

Note

In subroutines, you are recommended to use the following procedure: