ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

API usage in CL programs

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

  • API usage in CL programs

    Long time viewer...first time poster.

    I have written a CL program which monitors the process of an overnight job that spawns multiple batch jobs. It is for testing on our development system so we can run/simulate multiple days in a row. The purpose is to submit a new overnight job when the previous one is finished, and to know when it can do that. This was accomplished using APIs to 1) Retrieve a list of active batch jobs, and 2) Check if any active batch jobs has a specific library in it. This process works fine, except for when one of those spawned batch jobs goes into a MSGW state.

    What I am looking to accomplish is the following:

    1) When I am looking through the list of batch jobs (using the QUSLJOB API), I want to be able to see if any of the batch jobs I am looking for is sitting in a MSGW state. (I am using JOBI0100; I believe I need JOBI0200 for this information).
    2) If a batch job is found in a MSGW state, I want to know what the Message ID is (e.g. CPF4131).
    3) I then want to respond to the message, or perform some action before responding to the message. (While defaults could be established, since these are spawned jobs from the overnight job, I can't define an automatic response for the message since this could carry over into production.)

    I believe 1) is not that difficult to get the MSGW info; I have found this through other postings...but 2) and 3) I am not sure how to get the information on.

    All of what has been programmed to date has been done in CL; I am working to keep this all in a CL program without having to call another program to handle it. I've mostly had trouble finding anything that can provide this information, but I believe it won't be challenging to code this if I can be pointed in the direction of other APIs that could provide this information/functionality.

  • #2
    Re: API usage in CL programs

    take a look at the List Job Log Messages (QMHLJOBL) API for retrieving the message info. or just use QMHRCVM to check QSYSOPR messages.
    you can use the QMHSNDRM API to send a reply to the message.
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: API usage in CL programs

      Thanks! This is exactly what I was looking for. I have also found some examples for QMHLJOBL (and they're in CL!) which will solve my specific scenario.

      Comment


      • #4
        Re: API usage in CL programs

        Just a quick update (for historical purposes); I was able to get the functionality in place. These are the APIs I used. After creating user spaces, I used the QUSLJOB API to retrieve a list of jobs, subsetting them to just batch jobs, placing into the first user space. I used the QUSRTVUS API to retrieve the header information from the first user space to find out how many records there were, then the same API to retrieve the detail information job by job. When I found an entry in that detail I needed to check further, I used the QUSRJOBI API to get information on the library list (which went into a field instead of a user space), then checked to see if my production library was in it. For those that matched, I also checked if the job was in a MSGW state (from the earlier retrieval of the detail information of a job), and if it was, used the QMHLJOBL API to retrieve the most recent list of messages, up to ten, which were placed in the second user space. I then used the QUSRTVUS API to read each message entry in. I requested additional detail (in this case, the message with data in it), then passed this off to another program to determine what actions to take, eventually using the QMHSNDRM API to send a response back in attempting to get the job it found out of the MSGW state. (This last one, QMHSNDRM, is currently being coded.) All of this was done in CL.

        At some point I will provide some more specifics just how this was done...stay tuned.

        Comment


        • #5
          Re: API usage in CL programs

          As promised, here are the code snippets used to accomplish a lot of things with API in CL. Enjoy.
          Attached Files

          Comment


          • #6
            Re: API usage in CL programs

            Dear
            Koss53044
            Koss53044 no ha iniciado sesión

            I'm new comer in API, When I read your toptic "API usage in CL program". It helps me so much, because my purpose is the same in topic.
            However, Now I need reply one Inquiry Message for my batch job in MSGW ( MESSAGE ID =CPA0701, MESSAGE DATA = File in library *LIBL not found). If I want reply Inquiry Message, I have to know the message key. So that, based on your code, I get the message key (field &RTVMSGKY) as following:


            CALL PGM(QMHLJOBL) PARM(&USRSPCRJMQ &MHLJOBFMT &MHLJOBSEL +
            &MHLJOBSIZ &MHLJOBFMS X'00')
            CHGVAR VAR(&RTVPTRRJMQ) VALUE(X'00000001')
            CHGVAR VAR(&RTVLNGRJMQ) VALUE(X'00000096')
            CALL PGM(QUSRTVUS) PARM(&USRSPCRJMQ &RTVPTRRJMQ &RTVLNGRJMQ +
            &RTVHDRRJMQ)
            CHGVAR VAR(&RTVPTRRJM1) VALUE(%BIN(&RTVHDRRJMQ 133 4))
            IF COND(&RTVPTRRJM1 *NE 0) THEN(DO)
            /* MESSAGES TO SPIN THROUGH; IGNORE BLANK MESSAGE UNTIL WE GET TO THE FIRST MESSAGE THAT +
            WILL BE THE MESSAGE WE NEED TO LOOK AT; ALSO DROP OUT IF WE SCAN ALL AVAILABLE MESSAGES AND +
            CAN'T RESOLVE (WILL REQUIRE MANUAL INTERVENTION) */
            CHGVAR VAR(&RTVPTRRJMQ) VALUE(X'0000007D')
            CHGVAR VAR(&RTVLNGRJMQ) VALUE(X'00000004')
            CALL PGM(QUSRTVUS) PARM(&USRSPCRJMQ &RTVPTRRJMQ +
            &RTVLNGRJMQ &RTVPTRRJM2)
            CHGVAR VAR(&RTVLNGRJMQ) VALUE(X'0000003E')
            SCANMSG:
            CALL PGM(QUSRTVUS) PARM(&USRSPCRJMQ &RTVPTRRJM2 X'0000003E' &RTVDTARJMQ)
            CHGVAR VAR(&RTVPTRRJM2) VALUE(%BIN(&RTVDTARJMQ 2 4))
            CHGVAR VAR(&RTVOFSRJMQ) VALUE(%SST(&RTVDTARJMQ 6 4))
            CHGVAR VAR(&RTVMSGID) VALUE(%SST(&RTVDTARJMQ 18 7))
            CHGVAR VAR(&RTVMSGKY) VALUE(%SST(&RTVDTARJMQ 27 4))
            But when I call QMHSNDRM API with &RTVMSGKY and message queue is QSYSOPR, the system said that "the message key not found". I thinks the message key is not correct.

            Please help me to correct the code and how to call QMHSNDRM API ins this case

            Many thanks and best regards,
            Originally posted by Koss53044 View Post
            Just a quick update (for historical purposes); I was able to get the functionality in place. These are the APIs I used. After creating user spaces, I used the QUSLJOB API to retrieve a list of jobs, subsetting them to just batch jobs, placing into the first user space. I used the QUSRTVUS API to retrieve the header information from the first user space to find out how many records there were, then the same API to retrieve the detail information job by job. When I found an entry in that detail I needed to check further, I used the QUSRJOBI API to get information on the library list (which went into a field instead of a user space), then checked to see if my production library was in it. For those that matched, I also checked if the job was in a MSGW state (from the earlier retrieval of the detail information of a job), and if it was, used the QMHLJOBL API to retrieve the most recent list of messages, up to ten, which were placed in the second user space. I then used the QUSRTVUS API to read each message entry in. I requested additional detail (in this case, the message with data in it), then passed this off to another program to determine what actions to take, eventually using the QMHSNDRM API to send a response back in attempting to get the job it found out of the MSGW state. (This last one, QMHSNDRM, is currently being coded.) All of this was done in CL.

            At some point I will provide some more specifics just how this was done...stay tuned.

            Comment

            Working...
            X