Additions
1. ... TABLES itab1 ... itabn
2. ... USING p1 ... pn
3. ... CHANGING p1 ... pn
Effect
Defines a subroutine called by
PERFORM
Example
The subroutine WELCOME called by the PERFORM statement
outputs 'Hello world'
Notes
Subroutines defined by FORM can have parameters
and local fields. These parameters and local fields shadow global
fields.
Any local fields you declare with DATA after a
FORM statement are recreated and initialized for each
PERFORM call. When the call has finished, the memory for local
fields is released again.
FORM statements are not allowed within FORM ... ENDFORM
structures (i.e. no nested definitions).
Nested and recursive calls are possible.
The optional parameters must always be specified in the order
TABLES , USING and CHANGING .
Addition 1
... TABLES itab1 ... itabn
Effect
TABLES allows you to pass internal tables with or
without header lines to subroutines. For information about assigning
types TABLES parameters, see Type assignment
. TABLES parameters are passed by reference.
Example
Example
Addition 2
... USING p1 ... pn
Effect
Defines the formal parameters p1 ,... pn
which are replaced by actual parameters when you call the subroutine.
The formal parameters p1 ,... pn can have a particular type
(see Type assignment ). You can also specify the
transfer type (i.e. how you want to pass them).
Note
Transfer types:
USING ... p ...
Transfer is by reference. This means you can change the transferred
field continually in the subroutine.
USING ... VALUE(p) ...
When you specify VALUE(...) , transfer is by value, i.e. the
field contents are passed to the relevant local field. VALUES
parameters thus behave in the same way as local fields.
Addition 3
... CHANGING p1 ... 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
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:
Pass input parameters as USING parameters and output
parameters as CHANGING parameters. If in doubt, pass the
parameter by VALUE . You should be particularly careful with
passed SY fields. For performance reasons, data objects which
contain tables should not be passed by VALUE if at all possible.
You can protect TABLES parameters whose heasder lines must
remain unchanged with LOCAL .
STATICS allows you to create global
fields with a local visibility area. In the case of local fields which
are initialized on each call, you can replace DATA by
STATICS . With frequently called FORM routines, this can
lead to a noticeable improvement in performance.
To avoid shadowing problems with parameters, you are recommended to
keep to the naming convnetion for fields in subroutines. You should,
for instance, always start FORM parameters with the prefix 'P_'
and local fields with the prefix 'L_' .
Index
© SAP AG 1996