You use the PARM option of the CL CALL command to pass parameters to the ILE program when you run it.
CALL PGM(program-name)
PARM(parameter-1 parameter-2 ... parameter-n)
You can also type the parameters without specifying any keywords:
CALL library/program-name (parameter-1 parameter-2 ... parameter-n)
Each parameter value can be specified as a CL program variable or as one of the following:
If you are passing parameters to a program where an ILE RPG procedure is the program entry procedure, then that program must have one and only one *ENTRY PLIST specified. The parameters that follow (in the PARM statements) should correspond on a one-to-one basis to those passed through the CALL command.
Refer to the CALL Command in the section on "Passing Parameters between Programs" in the CL Programming manual for a full description of how parameters are handled.
For example, the program EMPRPT2 requires the correct password to be passed to it when it first started; otherwise it will not run. Figure 48 shows the source.
CRTBNDRPG PGM(MYLIB/EMPRPT2)
CALL MYLIB/EMPRPT2 (HELLO)
When the CALL command is issued, the contents of the parameter passed by the command is stored and the program parameter PSWORD points to its location. The program then checks to see if the contents of PSWORD matches the value stored in the program, ('HELLO'). In this case, the two values are the same, and so the program continues to run.
*===============================================================*
* PROGRAM NAME: EMPRPT2 *
* RELATED FILES: EMPMST (PHYSICAL FILE) *
* PRINT (PRINTER FILE) *
* DESCRIPTION: This program prints employee information *
* stored in the file EMPMST if the password *
* entered is correct. *
* Run the program by typing "CALL library name/ *
* EMPRPT2 (PSWORD)" on the command line, where *
* PSWORD is the password for this program. *
* The password for this program is 'HELLO'. *
*===============================================================*
FPRINT O F 80 PRINTER
FEMPMST IP E K DISK
IEMPREC 01
*-----------------------------------------------------------------*
* The entry parameter list is specified in this program. *
* There is one parameter, called PSWORD, and it is a *
* character field 5 characters long. *
*-----------------------------------------------------------------*
C *ENTRY PLIST
C PARM PSWORD 5
*-----------------------------------------------------------------*
* The password for this program is 'HELLO'. The field PSWORD *
* is checked to see whether or not it contains 'HELLO'. *
* If it does not, the last record indicator (LR) and *IN99 *
* are set on. *IN99 controls the printing of messages. *
*-----------------------------------------------------------------*
C PSWORD IFNE 'HELLO'
C SETON LR99
C ENDIF
OPRINT H 1P 2 6
O 50 'EMPLOYEE INFORMATION'
O H 1P
O 12 'NAME'
O 34 'SERIAL #'
O 45 'DEPT'
O 56 'TYPE'
O D 01N99
O ENAME 20
O ENUM 32
O EDEPT 45
O ETYPE 55
O D 99
O 16 '***'
O 40 'Invalid Password Entered'
O 43 '***'
Figure 49 shows the DDS that is referenced by the EMPRPT2 source.
A*****************************************************************
A* DESCRIPTION: This is the DDS for the physical file EMPMST. *
A* It contains one record format called EMPREC. *
A* This file contains one record for each employee *
A* of the company. *
A*****************************************************************
A*
A R EMPREC
A ENUM 5 0 TEXT('EMPLOYEE NUMBER')
A ENAME 20 TEXT('EMPLOYEE NAME')
A ETYPE 1 TEXT('EMPLOYEE TYPE')
A EDEPT 3 0 TEXT('EMPLOYEE DEPARTMENT')
A ENHRS 3 1 TEXT('EMPLOYEE NORMAL WEEK HOURS')
A K ENUM