Pregunta

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?

¿Fue útil?

Solución

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

Otros consejos

Something is not right with your sample.

First DCL &ENVPORT *CHAR(6) is not valid.

It should be DCL &ENVPORT *CHAR 6 or fully DCL VAR(&ENVPORT) TYPE(*CHAR) LEN(6).

Second JCHKSTS is called once with a constant value of '6500', again with '16500', and your workaround is '6500 ' none of which are a length of 6.

If you set the correct string length it should work as you expect.

I have not seen this type of declaration before

DCL &ENVPORT *CHAR(6)

I'm used to seeing it this way:

DCL VAR(&ENVPORT) TYPE(*CHAR) LEN(6)

or perhaps this way:

DCL &ENVPORT *CHAR LEN(6)

IBM reference

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top