If a subroutine has a parameter interface, you must supply values to all of the formal parameters in its interface when you call it. You list the actual parameters after the USING or CHANGING additions in the PERFORMstatement.
When you pass the values, the sequence of the actual parameters in the PERFORMstatement is crucial. The value of the first actual parameter in the list is passed to the first formal parameter, the second to the second, and so on. The additions USING and CHANGING have exactly the same meaning. You only need to use one or the other. However, for documentary reasons, it is a good idea to divide the parameters in the same way in which they occur in the interface definition.
Actual parameters can be any data objects or field symbols of the calling program whose technical attributes are compatible with the type specified for the corresponding formal parameter. When you specify the actual parameters, note that those you pass by reference to a formal parameter and those you pass by value to an output parameter can be changed by the subroutine. You should therefore ensure that only data objects that you want to be changed appear in the corresponding position of the actual parameter list.
If a subroutine contains TABLES parameters in its interface, you must call them as actual parameters after the TABLESaddition of the PERFORM statement before the USING and CHANGINGparameters. TABLES parameters are only supported to ensure compatibility with earlier releases, and should no longer be used.
You can use offset addressing for actual parameters in the same way as offset addressing for field symbols. That is, you can select memory areas that lie outside the boundaries of the specified actual parameter.
DATA: a1 TYPE p
a2 TYPE i,
a3 TYPE d,
a4 TYPE spfli-carrid,
a5(1) TYPE c.
PERFORM subr USING a1 a2 a3 a4 a5.
PERFORM subr CHANGING a1 a2 a3 a4 a5.
PERFORM subr USING a1 a2 a3
CHANGING a4 a5.
FORM subr USING
value(f1) TYPE p
value(f2) TYPE i
f3 LIKE a3
value(f4) TYPE spfli-carrid
This example defines a subroutine subr with a parameter interface consisting of five formal parameters, f1 to f5. The subroutine is called internally three times. The actual parameters are the data objects a1 to a5. The three subroutine calls are all equally valid. There are further PERFORMstatements that are also equally valid, so long as the sequence of the actual parameters remains unchanged. In each call, a1 is passed to f1, a2 to f2, and so on. When the subroutine ends, a3, a4, and a5 receive the values of f3, f4, and f5 respectively. The third of the subroutine calls documents in the program what the parameter interface of the subroutine shows, namely that only a4 and a5 are changed. In the case of reference parameter f3, it depends on the programming of the subroutine whether a3 is changed all the same.
The following example shows how generically-typed formal parameters inherit their technical attributes from their corresponding actual parameters.
date1 TYPE d, date2 TYPE t,
string1(6) TYPE c, string2(8) TYPE c,
number1 TYPE p DECIMALS 2, number2 TYPE p DECIMALS 0,
count1 TYPE i, count2 TYPE i.
PERFORM typetest USING date1 string1 number1 count1.
PERFORM typetest USING date2 string2 number2 count2.
FORM typetest USING now
txt TYPE c
value(num) TYPE p
int TYPE i.
DATA: t(1) TYPE c.
DESCRIBE FIELD now TYPE t.
WRITE: / 'Type of NOW is', t.
DESCRIBE FIELD txt LENGTH t IN CHARACTER MODE.
WRITE: / 'Length of TXT is', t.
DESCRIBE FIELD num DECIMALS t.
WRITE: / 'Decimals of NUM are', t.
DESCRIBE FIELD int TYPE t.
WRITE: / 'Type of INT is', t.
This produces the following output:
Type of NOW is D
Length of TXT is 6
Decimals of NUM are 2
Type of INT is I
Type of NOW is T
Length of TXT is 8
Decimals of NUM are 0
Type of INT is I
An internal subroutine typetest is called twice with different actual parameters. All actual and formal parameters are compatible and no error message occurs during the syntax check. Had you declared count2 with type f instead of type i, the syntax check would have returned an error, since the formal parameter INT is specified with type i. The formal parameters with generic types adopt different technical attributes depending on their corresponding technical attributes.