Description: Calls an external program.
Legacy RPG400 Example:
C PARM Param1
Modern RPGLE Example:
The callp (CALL PROGRAM) is optional and assumed.
We would define a call to the external program, and its parameters, using the declare statement. The first statement begins with DCL-PR, followed by the name of the prototype, followed by keywords, and finally a semicolon.
note the EXTPGM defines the name of the program (if its different from the name you have defined on the DCL-PR), and can include the library name although is generally frowned up on because we would use our jobs *LIBL to hunt and find the program:
*N CHAR(10) CONST;
END-PR;
My personal standard is to use underscores '_' in procedure names. I could create a procedure called "call_progname" to execute the call to program(PROGNAME):
*N CHAR(10) CONST;
END-PR;
Now you can reference that procedure name and pass a value as the parameter. This example is calling the program and passing the value stored in a variable called "customer"
Use sensible names for the procedure - for example if you are calling a program called "CUS045R" which is performing a search for a customer code and returning an address I might code it like this:
*N CHAR(10) CONST;
END-PR;
Then in my mainline I would get the customer address for a variable called "customer" like this:
Multiple Parameters with a PLIST
Definition: PLIST (Parameter List) is used to group parameters that will be passed between programs.
Usage in Called Program:
- The called program defines its entry point with
*ENTRY PLIST. - Each parameter expected is declared using
PARM. - Example:
C PARM CustNo
C PARM CustName
Here, the program expects two parameters: CustNo and CustName.
Usage in Calling Program:
The calling program defines a
PLISTwith the parameters it wants to send.Then it uses the
CALLoperation to invoke the target program, referencing the PLIST.Example:
C PARM CustNo
C PARM CustName
C CALL 'CUSTPGM' MyPlist
This passes the values of CustNo and CustName to program CUSTPGM.
Key Points
Consistency: The number, order, and type of parameters in the calling program’s PLIST must match those in the called program’s PLIST.
Flexibility: You can pass simple fields, data structures, or arrays.
Legacy vs Modern RPGLE:
- In older fixed-format RPG,
PLISTandPARMwere the standard way to handle parameters. - In modern free-format RPGLE, prototypes (
DCL-PR/DCL-PI) are preferred, but PLIST is still supported for backward compatibility
We can code this using modern RPGLE something like this:
*N CHAR(5) CONST; // define the size of parameter for 'customernumber'
END-PR;
