ibm-midrangecontrol-language

Type of a passed parameter in a CL CALL statement


On my iSeries running i/OS 6.1, I have a CL program that I'm cleaning up a bit. In this program there is a bunch of Cut-and-paste code of the form:

IF COND(&ENV='PRD') THEN(DO)
    CALL JCHKSTS PARM(&RS '127.0.0.1' '6500')
    /* more junk here */
ENDDO
IF COND(&ENV='TST') THEN(DO)
    CALL JCHKSTS PARM(&RS '127.0.0.1' '16500')
    /* more junk here, same as in the first block */
ENDDO
/* repeat for several more &ENV values */

Naturally when I saw this, my first thought is, let's move that port number into a variable and eliminate all the duplicate blocks of code, so I ended up with:

DCL &ENVPORT *CHAR(6)
IF COND(&ENV='PRD') THEN(CHGVAR VAR(&ENVPORT) VALUE('6500'))
IF COND(&ENV='TST') THEN(CHGVAR VAR(&ENVPORT) VALUE('16500'))
CALL JCHKSTS PARM(&RS '127.0.0.1' &ENVPORT)
/* more junk here, but only one copy of it now. */

When I run this code, it fails, because as it turns out the JCHKSTS program expects a string as its third parameter (which it converts to an integer internally), and the &ENVPORT variable, despite being declared as a string and initialized with a string value, is apparently not being passed as a string. (checking the parameters from within JCHKSTS shows a value of MAXINT for the port value.)

I worked around this by the cheap expedient of changing the value from '6500' to '6500 ', but I don't understand why it didn't work right in the first place; the IBM documentation says:

A program variable can be passed if the call is made from a CL program or ILE CL procedure, in which case the receiving program must declare the field to match the variable defined in the calling CL program or ILE CL procedure.

And that sure reads to me like, the receiving program expects a string, I declared the variable as a 6-character string, it should work.

So, did I miss something? How should I declare the variable in order for the receiving program to see it as a string representation of a number, instead of as an actual number?


Solution

  • The default length for a character variable passed as a literal is 32. My guess is that JCHKSTS is expecting a 32 byte variable. Try DCL &ENVPORT *CHAR 32