Description: Calls an external program.

Legacy RPG400 Example:

C      CALL    'PROGNAME'
C      PARM    Param1

Modern RPGLE Example:

callp PROGNAME(Param1);

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:

DCL-PR PROGNAME EXTPGM;
  *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):

DCL-PR call_progname EXTPGM('MYLIB/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"

call_progname(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:

DCL-PR get_customer_address EXTPGM('CUS045R');
  *N CHAR(10) CONST;
END-PR;

Then in my mainline I would get the customer address for a variable called "customer" like this:

get_customer_address(customer);

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   *ENTRY PLIST
C          PARM CustNo
C          PARM CustName

Here, the program expects two parameters: CustNo and CustName.

Usage in Calling Program:

  • The calling program defines a PLIST with the parameters it wants to send.

  • Then it uses the CALL operation to invoke the target program, referencing the PLIST.

  • Example:

C   MyPlist PLIST
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, PLIST and PARM were 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:

DCL-PR get_customer_address EXTPGM('CUSTPGM');
  *N CHAR(5) CONST;   // define the size of parameter for 'customernumber'
  *N CHAR(10) CONST;   // and for 'customername'
END-PR;

get_customer_address(customernumber:customername);
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>