SBMJOB, CALL, And Decimal Parameters
February 23, 2016 Ted Holt
In spite of my great admiration for the IBM i operating system, I have to admit it has its idiosyncrasies. One of them, which has been there since Day 1, is the way the Submit Job (SBMJOB) command reformats decimal parameters of the CALL command. Fortunately, a relatively recent addition to CL provides an easy way to deal with this quirk.
Assume a CL program calls an RPG program, passing along two decimal variables and a character variable.
dcl &Option *char 1 dcl &Account *dec 5 dcl &ThruDate *dec 7 call AR100R (&Account &ThruDate &Option)
One day you are told to change this program so that it submits program AR100R to the batch subsystem. You could embed the call within a SBMJOB command, like this:
sbmjob cmd(call AR100R (&Account &ThruDate &Option)) + job(AR100) jobd(ARJOBD)
But that would cause a decimal data error the first time the RPG program accessed the account number or date.
Instead, overlay the decimal variables with character variables of the same size, like this:
/* parameters for the submitted program */ dcl &cAccount *char 3 stg(*defined) defvar(&Account) dcl &cThruDate *char 4 stg(*defined) defvar(&ThruDate)
&Account is five digits packed decimal, which occupies three bytes, so &cAccount is defined as a three-byte character variable that overlays &Account. The &ThruDate variable occupies four bytes of memory, so &cThruDate is defined as a four-byte character variable. (To find the number of bytes of storage that a packed decimal variable occupies, add 1 to the number of digits and divide by 2. If the answer is not a whole number, round up. Another method is to add 2 to the number of digits, divide by 2, and throw away the remainder.)
Use these character variables instead of the decimal variables in the SBMJOB command.
sbmjob cmd(call AR100R (&cAccount &cThruDate &Option)) + job(AR100) jobd(ARJOBD)
There you have it: an easy solution to an old problem!