ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

QCMDEXC in a COBOL batch pgm

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

  • QCMDEXC in a COBOL batch pgm

    I haven't done QCMDEXC from a COBOL pgm in a while and I keep getting a length error. Does anyone have an example using QCMDEXC from a cobol program. I am on a AS/400-520.
    thanks,
    -Dan

  • #2
    Re: QCMDEXC in a COBOL batch pgm

    PHP Code:

        1     000100 IDENTIFICATION DIVISION
    .
         
    2     000200 PROGRAM-IDCMDXMPLE.
         
    3     000300 ENVIRONMENT DIVISION.
         
    4     000400 CONFIGURATION SECTION.
         
    5     000500   SOURCE-COMPUTERIBM-AS400.
         
    6     000600   OBJECT-COMPUTERIBM-AS400.
         
    7     000700 DATA DIVISION.
         
    8     000800 WORKING-STORAGE SECTION.
         
    9     000900 01  PROGRAM-VARIABLES.
        
    10     001000     05  CL-CMD       PIC X(33)
               
    001100                      VALUE "ADDLIBLE COBOLTEST".
        
    11     001200     05  PACK-VAL     PIC 9(10)V9(5COMP-3
               001300                      VALUE 18.
        12     001400 PROCEDURE DIVISION
    .
               
    001500 MAINLINE.
        
    13     001600     CALL "QCMDEXC" USING CL-CMD PACK-VAL.
        
    14     001700     STOP RUN.
               
    001800 
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: QCMDEXC in a COBOL batch pgm

      Thanks for the code, I got everything you had but it wasn't working and when I saw COMP-3 I knew right away that's what I forgot. It's been awhile for me to do COBOL on a 400, been doing mostly RPG.

      Thanks again!
      -Dan

      Comment


      • #4
        Re: QCMDEXC in a COBOL batch pgm

        Your welcome - Ive never done cobol

        take care and stay active in the forums

        jamie
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: QCMDEXC in a COBOL batch pgm

          Hi again

          My CL program looked like this:
          Code:
          PGM PARM(&MSG &TXT)                                     
          DCL VAR(&MSG) TYPE(*CHAR) LEN(7)                   
          DCL VAR(&TXT) TYPE(*CHAR) LEN(35)                  
          RTVMSG     MSGID(&MSG) MSGF(PGM/MGKMSG01) MSG(&TXT)
          RETURN
          but now looks like this:
          Code:
          RETURN
          My COBOL program has this (you can see what it WAS also):
          Code:
           01  A00-CMD.                                            
               05  FILLER   PIC X(15)              VALUE "JACCO21".
          *    05  A00-MSG  PIC X(7)               VALUE SPACES.   
          *    05  FILLER   PIC X(6)               VALUE ") TXT(". 
          *    05  A00-VAL  PIC X(35)              VALUE ALL "D".  
          *    05  FILLER   PIC X(1)               VALUE ")".      
           01  A00-LENGTH   PIC S9(10)V9(5) COMP-3 VALUE 7.
          During Debug, it claimed the field a00-val is not defined but during dump it contains the correct value. Go figure.

          At the moment it still gives me the same error CPF0006... Now as I understand it that means syntax error, right? How can "QCMDEXC JACCO21" possibly have syntax errors??????

          Comment


          • #6
            Re: QCMDEXC in a COBOL batch pgm

            Pls paste here all the new CL program.
            Philippe

            Comment


            • #7
              Re: QCMDEXC in a COBOL batch pgm

              The new CL program:
              Code:
              RETURN
              ... that's it!

              What I WANTED it to do was this:
              Accept a message id as input parameter, read the relevant value from the MGKMSG01 message file and return the DESCRIPTION.

              Since I struggled in calling it (my first ever CL program and thus my first attempt at calling a CL program from COBOL) I tried reducing the params to 1 and thus had to delete the definitions of the fields as they no longer existed. As such I had to delete the commands that used those fields... So I ended up with one field being accepted and declared right before the program quits.

              That still didn't work so I removed that field and definition also leaving only the RETURN command and that STILL doesn't work. Still gives me a CPF0006...
              Last edited by CryingRaven; January 26, 2009, 06:36 AM.

              Comment


              • #8
                Re: QCMDEXC in a COBOL batch pgm

                Look at the QMHRTVM sample member in the QLBLSRC file in QSYSINC. There's a full definition of QMHRTVM API (RETRIEVE MESSAGE API) that does what you want and is fairly straightforward. There's no need to call a CL program.
                Another example using this API in Cobol :
                Philippe

                Comment


                • #9
                  Re: QCMDEXC in a COBOL batch pgm

                  Originally posted by CryingRaven View Post
                  During Debug, it claimed the field a00-val is not defined but during dump it contains the correct value.
                  If your using ILE/Cobol, the best method is to populate the length value using an intrinsic function:

                  compute A00-LENGTH = function length(A00-CMD)

                  Terry

                  Comment


                  • #10
                    Re: QCMDEXC in a COBOL batch pgm

                    I must be really slow. i had a look at the at sample and started by just copying the three COPY commands into my program and it fails telling me it could not find the files to copy.

                    I then tried entering the QMHRTVM on the command line and it is reported as non-existing. I did a search for all Q* commands and found only 7 in QSYS and that is that. It seems that API is not installed on our system or I am not given access to it. Either way, none of the relevant files or commands seem to be available to me...

                    If this is something simple that I need to do to access these files, please bear with me as I have only been working in COBOL (and AS/400) for little over 2 months total so far. Still trying to get my hear around this abbreviated commands and library file system...

                    As I understand it we have the open file system installed on here, but nobody works with it so I have received zero training in it.

                    Comment


                    • #11
                      Re: QCMDEXC in a COBOL batch pgm

                      Originally posted by Terry Wincheste View Post
                      If your using ILE/Cobol, the best method is to populate the length value using an intrinsic function:

                      compute A00-LENGTH = function length(A00-CMD)

                      Terry
                      I could give that a go and see what happens, but this val field that was giving the problem was the second parameter being passed to the CL function. It is a pic x(35) field that is to contain the return value of the call. I.e. I send it "mgk1252" and it returns the value "There is no data in the file".

                      I figured that since it is initialized to spaces it means I am passing spaces as a parameter so filled it (at first) with high-values and then then as "12314513481364513613481939". Didn't really care since the returned value was what I was interested in.

                      What really confused me, though, was how to pass variables to the CL program and how to get the result. The QCMDEXC takes 2 params: The program to call and the length of the first param. The first param is then a string containing the values to pass to the program... but herein lies the problem. If you pass a value as part of a string, how do you then get any return values from the program?

                      Also, if the CL program is defined as "PGM PARAM(&fld1 &fld2)" do I call it as MYCLPROG fld1(msg000) fld2(dadfa) or as MYCLPROG DFA ASDF or as MYCLPROG fld1("msg000") fld2("asdfadfs")???

                      Comment


                      • #12
                        Re: QCMDEXC in a COBOL batch pgm

                        Hmmm... Is Cobol the required language ? Would you go for RPG examples ?
                        Philippe

                        Comment


                        • #13
                          Re: QCMDEXC in a COBOL batch pgm

                          COBOL all the way, I'm afraid...
                          Know 0 about RPG

                          Comment


                          • #14
                            Re: QCMDEXC in a COBOL batch pgm

                            Also, if the CL program is defined as "PGM PARAM(&fld1 &fld2)" do I call it as MYCLPROG fld1(msg000) fld2(dadfa) or as MYCLPROG DFA ASDF or as MYCLPROG fld1("msg000") fld2("asdfadfs")???
                            just call the CL from the Cobol pgm as below.

                            PHP Code:
                            CALL "MYCLPGM" USING fld1 fld2
                            Obviously fld1 and fld2 must be defined in the Cobol program. fld1 is the MsgID and fld2 the return msgtxt value.

                            Use QCMDEXC if you merely need to run a CL command other than call.
                            Last edited by Mercury; January 26, 2009, 08:46 AM.
                            Philippe

                            Comment


                            • #15
                              Re: QCMDEXC in a COBOL batch pgm

                              I must be really slow. i had a look at the at sample and started by just copying the three COPY commands into my program and it fails telling me it could not find the files to copy.
                              Check if you can display the below source member using SEU
                              PHP Code:
                              STRSEU SRCFILE(QSYSINC/QLBLSRCSRCMBR(QMHRTVMOPTION5
                              If so add the QSYSINC library in your JOBD to correctly compile the sample.

                              I then tried entering the QMHRTVM on the command line and it is reported as non-existing. I did a search for all Q* commands and found only 7 in QSYS and that is that. It seems that API is not installed on our system or I am not given access to it. Either way, none of the relevant files or commands seem to be available to me...
                              QMHRTVM, QLG and QUSEC are programs residing in QSYS lib not commands.
                              Last edited by Mercury; January 26, 2009, 09:18 AM. Reason: QLG, QUSEC added
                              Philippe

                              Comment

                              Working...
                              X