ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

passing parameter from CL to Cobol

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing parameter from CL to Cobol

    Hi,

    I have this in CL:

    DCL VAR(&PARM) TYPE(*CHAR) LEN(16)
    DCL VAR(&STRING) TYPE(*CHAR) LEN(500)
    DCL VAR(&STATUZ) TYPE(*CHAR) LEN(4)

    CHGVAR VAR(&PARM) VALUE('DROPTESTING12301')
    CALL PGM(PGM1) PARM(&PARM)
    SNDPGMMSG MSG(&PARM)
    SNDPGMMSG MSG(&STRING)
    SNDPGMMSG MSG(&STATUZ)

    in the linkage of cobol PGM1

    01 TEST-REC.
    03 TEST-PARM PIC X(16).
    03 TEST-STRING PIC X(500).
    03 TEST-STATUZ PIC X(4).

    when i ran the CL
    here's the MSG:
    PARM: DROPTESTING12301
    STRING: /TEMP_TAB01
    STATUS: (spaces)

    i have put a display in cobol.
    PARM: DROPTESTING12301
    STRING: DROP TABLE QTEMP/TEMP_TAB01
    STATUS: (spaces)

    i expected them to be the same.
    then i try to change the TEST-PARM into PIC X(32)

    the display in cobol is still the same.
    but the CL MSG is now correct.
    PARM: DROPTESTING12301
    STRING: DROP TABLE QTEMP/TEMP_TAB01
    STATUS: (spaces)

    can someone explain why? Thanks!

  • #2
    First, you should always ensure that your parameters match in size, type and number. You passing &PARM which is only 16 bytes long but the linkage section has 520 bytes described.
    (16 + 500 + 4). Secondly, if your going to pass multiple parameters via CL, then each parameter in LINKAGE should be a separate 01 level entry - one for each CL variable.

    Comment


    • #3
      Yeah, im just curious though. Thanks

      Comment


      • #4
        It's likely the garbage information being picked up in TEST-STRING is based on the addressing method used by the compiler which is presuming that X number of characters are being passed from the caller. I'm not exactly sure how the compiler allocates memory in the LINKAGE section, but my guess would be that if you tried calling the CL interactively and also submitted it to batch...you might get two different results. There may be more details in the Programmer Guide...it discusses inter-language calls.

        Comment


        • #5
          testingasfourhundred, you are assuming that the three CL variables are contiguous in storage. But there is no guarantee of that. To make them contiguous in storage, you have to define them in the CL program that way, using some top level variable, say &PARMS, and defining your three variables as STG(*DEFINED) DEFVAR(&PARMS ...)

          But Terry's suggestion is easier - define the COBOL program to receive three parameters, and then pass three parameters on the CALL in the CL.

          You can consider yourself lucky that those three CL variables did not happen to be contiguous in storage. If they had been, then you might have developed your application to count on that, and then someday, maybe several years later, those variables would not be contiguous, and your application would start failing in a mysterious and hard-to-debug way.

          Comment


          • #6
            Hi Terry and Barbara,

            I was playing around on how to pass parameter from CL to Cobol, then retrieve those variables back to CL. The examples I saw don't need to retrieve the values back to CL.
            I'll read more about this. Thanks for your input and having time to reply to my queries. I really appreciate it.

            Comment

            Working...
            X