M |
|||||||||||||
CALLNAT
operand1 |
[USING ]
|
operand2 | (AD =
|
O |
) | ||||||||
A |
|||||||||||||
nX |
|||||||||||||
This document covers the following topics:
For explanations of the symbols used in the syntax diagram, see Syntax Symbols.
Related Statements: CALL
| CALL FILE
|
CALL LOOP
|
DEFINE SUBROUTINE
|
ESCAPE
|
FETCH
|
PERFORM
Belongs to Function Group: Invoking Programs and Routines
The CALLNAT
statement is used to invoke a Natural
subprogram for execution. (A Natural subprogram can only be invoked via a
CALLNAT
statement; it cannot be executed by itself.)
When the CALLNAT
statement is executed, the execution
of the invoking object (that is, the object containing the CALLNAT
statement) will be suspended and the invoked subprogram will be executed. The
execution of the subprogram continues until either its END
statement is reached or processing of the subprogram is stopped by an
ESCAPE ROUTINE
statement being executed. In either case, processing of the invoking object
will then continue with the statement following the CALLNAT
statement.
Notes:
Operand Definition Table:
Operand | Possible Structure | Possible Formats | Referencing Permitted | Dynamic Definition | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operand1 |
C | S | A | yes | no | |||||||||||||||
operand2 |
C | S | A | G | A | U | N | P | I | F | B | D | T | L | C | G | O | yes | yes |
Syntax Element Description:
Syntax Element | Description | |
---|---|---|
operand1 |
Subprogram to be Invoked:
As The subprogram name may contain an ampersand (&); at
execution time, this character will be replaced by the one-character code
corresponding to the current value of the system variable
|
|
operand2 |
Parameters:
If parameters are passed to the subprogram, the structure
of the parameter list must be defined in a By default, the parameters are passed by
reference, that is, the data are transferred via address parameters, the
parameter values themselves are not moved. However, it is also possible to pass
parameters by value, that is, pass the actual parameter values. To do
so, you define these fields in the
Note: For both ways of passing parameters, the following applies: If a group is specified as
In the parameter data area of the invoked subprogram, a
redefinition of groups is only permitted within a If an array is passed, its number of dimensions and
occurrences in the subprogram's parameter data area must be the same as in the
Note: When the option
|
|
AD= |
Attribute Definition:
If |
|
AD=O |
Non-modifiable, see session parameter
Note: |
|
AD=M |
Modifiable, see session parameter
This is the default setting. |
|
AD=A |
Input only, see session parameter
AD=A .
|
|
If
operand2 is a constant,
AD cannot
be explicitly specified. For constants AD=O always
applies.
|
||
nX |
Parameters to be Skipped:
With the notation
A parameter that is to be skipped must be defined with the
keyword |
Dynamic variables may be passed as parameters to a called program
object (CALLNAT
, PERFORM
). A call by reference is
possible because the value space of a dynamic variable is contiguous. A call by
value causes an assignment with the variable definition of the caller as the
source operand and the parameter definition as the destination operand. In
addition, a call by value result causes the movement to change to the opposite
direction. When using a call-by-reference, both definitions must be
DYNAMIC
. If only one of
them is DYNAMIC
, a runtime error is raised. In case of a call by
value (result) all combinations are possible.
The following table illustrates the valid combinations of statically and dynamically defined variables of the caller, and statically and dynamically defined parameters concerning the parameter transfer.
operand2 of caller
|
Parameter definition | |
Static | Dynamic | |
Static | yes | no |
Dynamic | no | yes |
The formats of the dynamic variables A or B must match.
operand2 of caller
|
Parameter definition | |
Static | Dynamic | |
Static | yes | yes |
Dynamic | yes | yes |
Note:
When using static/dynamic or dynamic/static definitions, a
value truncation may occur according to the data transfer rules of the
appropriate assignments.
** Example 'CNTEX1': CALLNAT ************************************************************************ DEFINE DATA LOCAL 1 #FIELD1 (N6) 1 #FIELD2 (A20) 1 #FIELD3 (A10) END-DEFINE * CALLNAT 'CNTEX1N' #FIELD1 (AD=M) #FIELD2 (AD=O) #FIELD3 'P4 TEXT' * WRITE '=' #FIELD1 '=' #FIELD2 '=' #FIELD3 * END
** Example 'CNTEX1N': CALLNAT (called by CNTEX1) ************************************************************************ DEFINE DATA PARAMETER 1 #FIELDA (N6) 1 #FIELDB (A20) 1 #FIELDC (A10) 1 #FIELDD (A7) END-DEFINE * * #FIELDA := 4711 * #FIELDB := 'HALLO' * #FIELDC := 'ABC' * WRITE '=' #FIELDA '=' #FIELDB '=' #FIELDC '=' #FIELDD * END
** Example 'CNTEX2': CALLNAT ************************************************************************ DEFINE DATA LOCAL 1 #ARRAY1 (N4/1:10,1:10) 1 #NUM (N2) END-DEFINE * * CALLNAT 'CNTEX2N' #ARRAY1 (2:5,*) * FOR #NUM 1 TO 10 WRITE #NUM #ARRAY1(#NUM,1:10) END-FOR * END
** Example 'CNTEX2N': CALLNAT (called by CNTEX2) ************************************************************************ DEFINE DATA PARAMETER 1 #ARRAY (N4/1:4,1:10) LOCAL 1 I (I2) END-DEFINE * * FOR I 1 10 #ARRAY(1,I) := I #ARRAY(2,I) := 100 + I #ARRAY(3,I) := 200 + I #ARRAY(4,I) := 300 + I END-FOR * END