Placing Required Parms After Optional
Most programmers who have worked with command definitions for very long have probably discovered that creating a parameter with a default value forces that parameter to be optional. Once a parameter is defined as optional (MIN value of 0), no parameter defined after it can be made mandatory (MIN value greater than 0). This requirement often causes a programmer to make a parameter optional that should be mandatory. There is a workaround for this problem although it may not be that obvious.
For example, let's say you want to create a command with two parameters. The first parameter is FROMDATE, for which you want to supply a default value of *CURRENT. The second parameter is TODATE, which must be entered. Since FROMDATE is optional (has a default value), we can't make TODATE mandatory.
To get around this problem, in the PROMPT parameter of the PARM statement, you can specify a display position relative to the other parameters. The display position is specified as the second element of the PROMPT parameter, immediately after the prompt text. For an example of how this is done, look at the following command:
CMD PROMPT('Example Command') PARM KWD(TODATE) TYPE(*DATE) MIN(1) PROMPT('To + date' 2) PARM KWD(FROMDATE) TYPE(*DATE) (DFT(*CURRENT) + SPCVAL((*CURRENT 000000)) PROMPT('From + date' 1)
In the example given above, we can define TODATE first as mandatory parameter with a relative display position value of 2. We can then define FROMDATE using a relative display position of 1. This way, we are satisfying the command compiler's requirement of mandatory parameter definition ahead of optional parameter definition. At the same time, we are also causing the parameter display to appear to the order we want as shown below:
Example command (EXMCMD) Type choices, press Enter From date . . . . . . . . . . . FROMDATE *CURRENT To date . . . . . . . . . . . . TODATE _______