You can call any RPG program that receives parameters, with or without actually passing parameters to the program - by using the program status data structure and the *PARMS keyword within your I-specs. The program status data structure is set up like any other data structure except you specify an 'S' in column 18. The subfields of the data structure are defined by special keywords. In this case we use the keyword *PARMS (see Figure 1). We assign field name INPARM to contain the value that is returned through the *PARM keyword. Whatever the field name assigned to the *PARM keyword, it will be a three-digit numeric field. It will contain the number of parameters that are passed to your RPG program from the calling program. If the value is zero (no parameters passed), you cannot access the name of the field that is in your *ENTRY-PLIST.
To get around this you can simply check whether the value is zero or not, then take the proper action (such as MOVE *BLANKS) to another field to use in your program. This will bypass the error message 'Reference to unpassed parameter.' This message is saying that you are trying to use a field that you did not receive any data for (and you should have). So you are bypassing the use of the field but you are taking the appropriate action if no parameters were passed. Let's look at an example in 1.
To get around this you can simply check whether the value is zero or not, then take the proper action (such as MOVE *BLANKS) to another field to use in your program. This will bypass the error message 'Reference to unpassed parameter.' This message is saying that you are trying to use a field that you did not receive any data for (and you should have). So you are bypassing the use of the field but you are taking the appropriate action if no parameters were passed. Let's look at an example in Figure 1.
On line 1000 we define the program status data structure. On line 1300 we define the field INPARM for the keyword *PARMS. On line 1500 we define the field PARTNO that we should receive a value in from the calling program. On line 1700 we check INPARM to see if we were passed a parameter and if we were, we move it into SCPART to be used in our program. If we were not passed a parameter, INPARM will have a value of zero and we will move blanks into SCPART.
If INPARM is zero, the program will never execute statement 2000 and we will not receive the message 'Reference to unpassed parameter'. This way the program will run perfectly.
You can use this for programs that are looking for any number of parameters to be passed or you can do any processing that you wish based on the value of INPARM (as long as you do not use the field name of the variable for which you did not receive data).
We have used this technique for all of our inquiry programs. They can be called from a menu (without parameters), from another RPG program (to select and return parameters), or from a CL program. We have found that we can use this technique to eliminate the need for many three-line CL programs that do nothing more than CALL the RPG program and pass a blank parm to it. So you can cut down on the number of CL programs, and make your RPG programs more flexible at the same time. Plus you can have one RPG program handle both your viewing data function and selecting data function.
Bruce Knoll Kentwood, Michigan
TechTalk: Make Your RPG Programs More Flexible
Figure 1 RPG program accessing parameter count
Figure 1: RPG Program Accessing Parameter Count .... ....1.... ....2.... ....3.... ....4.... ....5.... ....6.... ....7 1000 ISDS SDS 1100 I 244 253 WSID 1200 I 254 263 USER 1300 I *PARMS INPARM 1400 C *ENTRY PLIST 1500 C PARM PARTNO 5 1600 C* 1700 C INPARM IFEQ 0 1800 C MOVE *BLANKS SCPART 5 1900 C ELSE 2000 C MOVE PARTNO SCPART 2100 C END 2200 C* .... ....1.... ....2.... ....3.... ....4.... ....5.... ....6.... ....7
LATEST COMMENTS
MC Press Online