ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Problem in invoking a QCMDSRC command string from my CL program - INT4 type

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

  • Problem in invoking a QCMDSRC command string from my CL program - INT4 type

    I have a QCMDSRC command source with following fields -

    PARM KWD(FIELD1) TYPE(MYOWNTYPE) MIN(0) MAX(5)
    MYOWNTYPE: ELEM1 TYPE(*NAME) LEN(10) MIN(1)
    ELEM2 TYPE(*INT4) RANGE(1 99999)
    ELEM3 TYPE(*INT4) VALUES(100 200)

    As you can see, a FIELD1 of type MYOWNTYPE and that MYOWNTYPE has 3 elements in it - 1 of NAME type and 2 of INT4 type

    Now, i am developing a CL program in which I will have to invoke the command. So, i am defining my CL program as -

    DCL VAR(&FIELD1) TYPE(*CHAR) LEN(100)
    DCL VAR(&ELEM1) TYPE(*CHAR) STG(*DEFINED) LEN(10) DEFVAR(&FIELD1 1)
    DCL VAR(&ELEM2) TYPE(*INT) STG(*DEFINED) LEN(4) DEFVAR(&FIELD1 11)
    DCL VAR(&ELEM3) TYPE(*INT) STG(*DEFINED) LEN(4) DEFVAR(&FIELD1 15)

    CHGVAR VAR(&FIELD1) VALUE(&FILEFIELD1) // Assigning file field1 which is of character length 10 to field1 variable which is of CHAR type
    CHGVAR VAR(&FIELD2) VALUE(&FILEFIELD2) // Assigning file field2 which is of character length 4 to field2 variable which is of INT type
    CHGVAR VAR(&FIELD3) VALUE(&FILEFIELD3) // Assigning file field3 which is of character length 4 to field3 variable which is of INT type

    But, when i perform QCMDEXC on command string, it fails. Can someone guide me what i am making wrong here? Is the problem with the

    1. *INT field definitions in CL program or
    2. with the CL data structure usage or
    3. with the way CHGVAR is performed in CL program?

  • #2
    Since you are using QCMDEXC to execute the command, rather than directly executing the command, your command string needs to look like what you would type at a command line. Everything should be character, not INT.

    If you show us the call to QCMDEXC and the lines that build the command-string variable in the first parameter, we may be able to help more.

    Comment


    • #3
      Originally posted by TedHolt View Post
      Since you are using QCMDEXC to execute the command, rather than directly executing the command, your command string needs to look like what you would type at a command line. Everything should be character, not INT.

      If you show us the call to QCMDEXC and the lines that build the command-string variable in the first parameter, we may be able to help more.

      Below is the way i am building the string before invoking QCMDEXC call.

      CHGVAR VAR(&FIELD1) VALUE(&FILEFIELD1) // Assigning file field1 which is of character length 10 to field1 variable which is of CHAR type
      CHGVAR VAR(&FIELD2) VALUE(&FILEFIELD2) // Assigning file field2 which is of character length 4 to field2 variable which is of INT type
      CHGVAR VAR(&FIELD3) VALUE(&FILEFIELD3) // Assigning file field3 which is of character length 4 to field3 variable which is of INT type
      CHGVAR VAR(&CMD) VALUE(&CMD *TCAT ' FIELD1(' *CAT &FIELD1 *TCAT ')')

      CALL PGM(QCMDEXC) PARM(&CMD 5000)

      Basically, i am invoking QCMDEXC based on FIELD1 only which is a character. FIELD2, FIELD3, etc are part of FIELD1 data structure and they have been defined as INT type in my CL program

      Comment


      • #4
        Your code looks OK to me.

        Do you have any messages in the job log?

        If you run in the debugger and copy the value of &CMD, then paste what you copied onto a command line, will it run?

        Comment


        • #5
          Since parameter FIELD1 can have a maximum of 5 entries, you have to put each one in it's own set of parenthesis, so it should look like ' FIELD1((' *CAT &FIELD1 *TCAT '))' assuming the variable &FIELD1 is only 10 characters long.

          Comment


          • #6
            Hi TedHolt and Brian, I figured out the command parsing issue. Thanks again. As Brian pointed out, missing the inner paranthesis was the issue.

            But, i have one more problem now. As i mentioned earlier, my QCMDSRC source is defined as *INT4 and the fields in the file are of CHARACTER type with length 4. I am just moving the file field to the command string and it seems to work. But, one issue remain.

            Assume file has value of 100. When i perform CHGVAR VAR(&FIELD1) VALUE(&FILEFIELD1), I get value for FIELD1 as '100 ' ( 100 followed by a blank). But, rather i would like to build it as ' 100'. (blank followed by a 100). Any way to do it?

            Comment


            • #7
              You could just add a space when determining &FIELD1 like so: CHGVAR VAR(&FIELD1) VALUE(' ' *CAT &FILEFIELD1). But rather than do that you could just use the file's variables directly with spaces in between them to build the command string like so: ' FIELD1((' *CAT &FILEFIELD1 *BCAT &FILEFIELD2 *BCAT &FILEFIELD3 *TCAT '))'

              Comment


              • #8
                Thanks again Brian. That solved my issue.

                Comment


                • #9
                  I'm glad you got it working, sri.

                  I completely overlooked the max(5). (Sharp eye, Brian!)

                  I'm curious to know why you're using QCMDEXC to execute the command rather than executing it directly. Are you going to have a varying number of occurrences of the field1 parameter?

                  Comment


                  • #10
                    Originally posted by TedHolt View Post
                    I'm glad you got it working, sri.

                    I completely overlooked the max(5). (Sharp eye, Brian!)

                    I'm curious to know why you're using QCMDEXC to execute the command rather than executing it directly. Are you going to have a varying number of occurrences of the field1 parameter?
                    Hi TedHolt, yes you are correct. The code i showed was just a snippet from a large program. The programs are written 20 years back, and I don't want to change entire functionality. Thats why. Thanks again.

                    Comment

                    Working...
                    X