Value An Expression? *YES!
July 24, 2013 Ted Holt
I find it ironic that the most commonly used CL command suffers from an annoying (if not aggravating) limitation that does not afflict many less-used commands. Fortunately, the commands you and I write do not have to have this limitation.
The command to which I refer is CALL. The limitation is that the parameters must be literals or variables, never expressions. To see what I mean, look at this CALL command.
call somepgm parm(%sst(&Data 5 4))
Doesn’t that make sense to you? The first parameter consists of bytes 5 through 8 of a variable named &DATA. The compiler complains, expressing its displeasure by means of diagnostic message CPD0105 (Built-in function not allowed for parameter PARM).
To make this code work, you must declare another variable, copy the required four bytes into it, and use that variable in the parameter list.
dcl &SomeVar *char 4 chgvar &SomeVar %sst(&Data 5 4) call somepgm parm(&SomeVar)
I’m sure there is a good reason for this limitation. I just don’t know what that good reason is.
Consider two commands, DOTHIS and DOTHAT.
CMD PROMPT('Do this') PARM KWD(RATE) TYPE(*CHAR) LEN(4) RSTD(*YES) + VALUES(SLOW FAST) MIN(1) EXPR(*YES) + PROMPT('How fast?') PARM KWD(TIMES) TYPE(*INT2) MIN(1) EXPR(*YES) + PROMPT('How many times?') CMD PROMPT('Do that') PARM KWD(INTERVAL) TYPE(*DEC) LEN(7 0) MIN(1) + PROMPT('How frequently?') PARM KWD(UNIT) TYPE(*CHAR) LEN(9) RSTD(*YES) + VALUES(HOURS MINUTES SECONDS DAYS MONTHS + YEARS DECADES CENTURIES MILLENNIA EONS) + PROMPT('Unit of time')
They are similar in that both of them accept two parameters: a character parameter and a numeric parameter. But they differ in that the parameters of DOTHIS include the keyword EXPR(*YES). A parameter that is defined to allow expressions may include concatenation operators, as well as built-in functions %SUBSTRING (%SST), %BIN, %TRIM, %TRIML, %TRIMR, %SCAN, and %CHECK.
Now look at a program that calls these commands.
dcl &Settings *char 48 dcl &Interval *char 3 dcl &Units *char 9 RtvDtaAra dtaara(DoDahData (1 48)) rtnvar(&Settings) DoThis rate(%sst(&Settings 1 4)) times(%sst(&Settings 5 3)) ChgVar &Units %sst(&Settings 11 9) ChgVar &Interval %sst(&Settings 20 3) DoThat interval(&Interval) unit(&Units)
Since DOTHAT does not allow expressions, the programmer had to declare and load two variables, &INTERVAL and &UNITS. DOTHIS requires no such variables.
For this reason, I make it a habit to include EXPR(*YES) when defining command parameters.