Example: Calling application programs

This example shows how to define and create a CL command to call an application program.

You can create commands to call application programs. If you create a command to call an application program, the IBM® i operating system performs validity checking on the parameters passed to the program. However, if you use the Call (CALL) command to call an application program, the application program must perform the validity checking.

For example, a label writing program (LBLWRT) writes any number of labels for a specific customer on either 1- or 2-part forms. When the LBLWRT program is run, it requires three parameters: the customer number, the number of labels, and the type of form to be used (ONE or TWO).

If the program were called directly from the display, the second parameter would be in the wrong format for the program. A numeric constant on the CALL command is always 15 digits with 5 decimal positions, and the LBLWRT program expects a 3-digit number with no decimal positions. A command can be created that provides the data in the format required by the program.

The command definition statements for a command to call the LBLWRT program are:


CMD PROMPT('Label Writing Program')
PARM  KWD(CUSNBR) TYPE(*CHAR) LEN(5) MIN(1) +
      PROMPT('Customer Number')
PARM  KWD(COUNT) TYPE(*DEC) LEN(3) DFT(20) RANGE(10 150) +
      PROMPT('Number of Labels')
PARM  KWD(FRMTYP) TYPE(*CHAR) LEN(3) DFT('TWO') RSTD(*YES) +
      SPCVAL(('ONE') ('TWO') ('1' 'ONE') ('2' 'TWO')) +
      PROMPT('Form Type')

For the second parameter, COUNT, a default value of 20 is specified and the RANGE parameter allows only values from 10 to 150 to be entered for the number of labels.

For the third parameter, FRMTYP, the SPCVAL parameter allows the display station user to enter 'ONE', 'TWO', '1', or '2' for this parameter. The program expects the value 'ONE' or 'TWO'; however, if the display station user enters '1' or '2', the command makes the necessary substitution for the FRMTYP parameter.

The command processing program for this command is the application program LBLWRT. If the application program were an RPG program, the following specifications would be made in the program to receive the following parameters:


*ENTRY   PLIST
         PARM    CUST   5
         PARM    COUNT  30
         PARM    FORM   3

The Create Command (CRTCMD) command is as follows:


CRTCMD CMD(LBLWRT) PGM(LBLWRT) SRCMBR(LBLWRT)