RPG/400 Help

CALL (Call a Program)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| CALL    |               | Program name    | Plist          |   _ ER LR     |
|         |               |                 | name           |               |
*---------*---------------*-----------------*----------------*---------------*

The CALL operation passes control to the program specified in factor 2.

Factor 2 must contain a character entry specifying the name of the program to be called. If you specify the library name, it must be immediately followed by a slash and then the program name (for example, 'LIB/PROG'.). Factor 2 must contain the name of a field, a literal, a named constant, or an array element that contains the name of the program to be called and that optionally contains the name of the library in which the program is located. If a library is not specified, the library list is used to find the program.

The total length of a literal, including the slash, cannot exceed 8 characters. The total length of a field or named constant, including the slash, cannot exceed 21 characters. If either the program or the library name exceeds 10 characters, it is truncated to 10 characters. The program name is used exactly as specified in the literal, field, named constant, or array element to determine the program to be called. Any blanks found before or after the slash are included in the program or library name. If the first or last character in the entry is a slash, a blank library or program name, respectively, is assumed. (Lowercase characters are not shifted to uppercase. A name enclosed in quotation marks, for example, "ABC", always includes the quotation marks as part of the name of the program to be called.) *LIBL and *CURLIB are not supported.

Program references are grouped to avoid the overhead of resolving to the target program. All references (using a CALL or FREE operation) to a specific program using a named constant or literal are grouped so that the program is resolved to only once, and all subsequent references to that program (by way of named constant or literal only) do not cause a resolve to recur.

The references are grouped if both the program and the library name are identical. All program references by variable name are grouped by the variable name. When a program reference is made with a variable, its current value is compared to the value used on the previous program reference operation that used that variable. If the value did not change, no resolve is done. If it did change, a resolve is done to the new program specified. If your program depends on a resolve taking place on a reference by variable name, code a FREE operation using that variable name. This causes a subsequent reference, using that variable, to resolve to the program whether or not the value has changed. Note that this rule applies only to references using a variable name. References using a named constant or literal are never re-resolved, and they do not affect whether or not a program reference by variable is re-resolved. Figure "Example of Grouping of Program References" illustrates the grouping of program references.

CALL Example

Figure 10. Example of Grouping of Program References

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
I..............Namedconstant+++++++++C.........Fldnme......... ....
I              'LIB1/PGM1'           C         CALLA
I              'PGM1'                C         CALLB
I              'LIB/PGM2'            C         CALLC
I*
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C                     CALL CALLA
C*
C* The following two calls will be grouped together because both
C* have the same program name (PGM1) and the same library name
C* (none).  Note that these will not be grouped with the call using
C* CALLA above because CALLA has a different library name specified
C* (LIB1).
C*
C                     CALL 'PGM1'
C                     CALL CALLB
C*
C* The following two program references will be grouped together
C* because both have the same program name (PGM2) and the same
C* library name (LIB).
C*
C                     CALL 'LIB/PGM2'
C                     FREE CALLC
C*
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C* The first call in the program using CALLV below will result in
C* a resolve being done for the variable CALLV to the program PGM1.
C* This is independent of any calls by a literal or named constant
C* to PGM1 that may have already been done in the program.  The
C* second call using CALLV will not result in a resolve to PGM1
C* because the value of CALLV has not changed.  The call following
C* the free operation will result in a resolve taking place because
C* the free operation will force that to occur.  Note that the free
C* operation itself will not result in a resolve occurring. (That
C* is, that operation will use the current program object pointer
C* for calls using variable CALLV.)
C*
C                     MOVE 'PGM1'    CALLV  21
C                     CALL CALLV
C                     CALL CALLV
C                     FREE CALLV
C                     CALL CALLV

In the result field, specify the name of a PLIST to communicate values between the calling program and the called program. The result field can be blank if the called program does not access parameters or if the PARM statements directly follow the CALL operation.

Positions 54 and 55 must be blank. Any valid resulting indicator can be specified in positions 56 and 57 to be set on for an error returned from the called program and in positions 58 and 59 to be set on if the called program is an RPG/400 program that returns with the LR indicator on.

The DSPPGMREF command is a CL command that is used to display information about the external references made by a program. A referenced program is referenced on a CALL operation only. Using DSPPGMREF, you can query the names of programs called by way of named constants or literals. To make this information available to DSPPGMREF, recompile your program.

Figure 11. CALL Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*  The CALL operation calls PROGA and allows PROGA to access
C*  FLDA and FLDB, defined elsewhere. PROGA is processed using the
C*  contents of FLDA and FLDB.  After PROGA is processed, control
C*  returns to the next statement to be processed after the last
C*  PARM statement.
C*
C*
C                     CALL 'PROGA'
C                     PARM           FLDA
C                     PARM           FLDB


[ Top of Page | Previous Page | Next Page | Table of Contents ]