ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

command running environment

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

  • command running environment

    Hi all,

    I am taking a shot at tinkering with a CL program.

    There is a command "ADDMBX" which takes 2 parms, and depending on what those are, it adds ASNs to a mailbox (I am in the EDI field)
    right now, we have to do this multiple times for multiple trading partners (different parms), separated by a time delay, so something like:
    Code:
    ...
    ADDMBX     UFDNAME(*name1) PTNID(*number1)
    DLYJOB     DLY(15)                        
    ADDMBX     UFDNAME(*name2) PTNID(*number2)
    DLYJOB     DLY(15)                        
    ADDMBX     UFDNAME(*name3) PTNID(*number3)
    DLYJOB     DLY(15)                        
    ...
    the issue is that if the delay is too short, the ASNs will be overlapped and go into the wrong mailboxes causing all kinds of problems.
    we could change the time delay to be longer but we want to make this more dynamic, not having to add 2 lines for every trading partner.

    I tried to use the SBMJOB command in a loop to put the ASNs in a job queue so it wouldn't overlap:
    Code:
    //in a loop, untill no more ASNs
    SBMJOB CMD (ADDMBX UFDNAME(field_1) PTNID(field_2))   +
                    JOBQ(LIBNAME/JOBQ_name)
    I thought this would work but I am getting an error:

    Message ID . . . . . . : CPD0031 Severity . . . . . . . : 30
    Message type . . . . . : Diagnostic
    Date sent . . . . . . : 09/27/17 Time sent . . . . . . : 17:36:42

    Message . . . . : Command ADDMBX not allowed in this setting.
    Cause . . . . . : The complete list of settings includes: batch,
    interactive, batch control language (CL) program, interactive CL program,
    batch REXX procedure, interactive REXX procedure, batch CL ILE program,
    interactive CL ILE program, CALL to QCMDEXC, and various types of source
    statements. The Display Command (DSPCMD) command can be used to determine
    the setting in which the command is allowed.
    Recovery . . . : Omit the command.

    the ADDMBX command is only allowed to run in *BPGM and *IPGM? can someone tell me what this means?

  • #2
    I think (I am not sure), it means the command itself cannot be submitted, it always has to be run from within a program
    So you should just be able to create a CLLE program wrapper for the command and submit that

    ADDMBXPGM CLLE program:
    -----------------------------
    PGM (&field1 &field2)
    DCL &field1 *char 10
    DCL &field2 *char 10
    ADDMBX UFDNAME(&field1) PTNID(&field2)
    ENDPGM
    ---------------------------

    Submit command:
    SBMJOB CMD (CALL ADDMBXPGM (field_1 field_2))
    JOBQ(LIBNAME/JOBQ_name)

    Comment


    • #3
      If your goal is to avoid the problem caused by having the ADDMBX command run too soon after the prior run of the command, I don't think that changing it to a batch process will help - the batch jobs will run very quickly. (Another option along these lines would be to issue a CHGCMD CMD(ADDMBX) ALLOW(*ALL))

      Ideally, you should try to determine why the problem occurs when the command is run twice without a delay (ADDMBX doesn't exist on our system).

      Cheers,

      Emmanuel

      Comment


      • #4
        You can do a CHGCMD on the command and specify *BATCH in the ALLOW argument - that would allow the job to be submitted. Whether that helps your problem or not will be determined what was causing the problem to begin with. When you submit you also want to determine if they should run single threaded (one after another) or multiple at the same time.... and make sure your jobq and jobq priorities are properly setup to allow what you're wanting to accomplish.

        Comment


        • #5
          Thank you all for your replies.

          Originally posted by Rocky View Post
          You can do a CHGCMD on the command and specify *BATCH in the ALLOW argument - that would allow the job to be submitted. Whether that helps your problem or not will be determined what was causing the problem to begin with. When you submit you also want to determine if they should run single threaded (one after another) or multiple at the same time.... and make sure your jobq and jobq priorities are properly setup to allow what you're wanting to accomplish.
          Rocky, how might I specify that I want single threaded for the job queue?

          Comment


          • #6
            I used Vectorspace's method of creating a wrapper, then submitting that.
            My code has evolved to meet other criterias:
            Code:
            DCLF   FILE(*LIBL/ZCC) OPNID(ZCC) RCDFMT(*ALL)
            DCL   VAR(&INT)  TYPE(*INT)  LEN(2)           
            DCL VAR(&RCDNBR) TYPE(*DEC) LEN(10)           
            RTVMBRD FILE(*LIBL/ZCC) NBRCURRCD(&RCDNBR)                   
            
            CHGCMD CMD(ADDMBX) ALLOW(*ALL)                                
            DOFOR   VAR(&INT)  FROM(1)  TO(&RCDNBR)                        
            SBMJOB CMD(CALL ADDMBXPGM (&ZCC_CCSDSC &ZCC_CCCODE)) +
            JOBQ(*LIBL/EDIASNCLJQ)                                
            ENDDO
            my question: ZCC is a control table with records that houses control records which other programs use as well. I only want to refer to what I need in the program.
            the section of ZCC that I need to refer to is:
            CCTABL CCCODE CCDESC CCSDSC
            mypgm *details *details *details
            mypgm *details *details *details
            mypgm *details *details *details
            mypgm *details *details *details
            I want to loop over the number of records that CCTABL = mypgm (there are 4). I can't hardcode "4" because we will add more records later.
            For the parameters of the ADDMBX command, I need to specify UFDNAME(CCSDSC) and PTNID(CCCODE)

            Currently, I have it coded so that it loops for the number of the entire ZCC record. I need to loop only four times. This is my 2nd CL program and I am thoroughly confused! Please help

            Comment


            • #7
              Originally posted by Vectorspace View Post
              I think (I am not sure), it means the command itself cannot be submitted, it always has to be run from within a program
              So you should just be able to create a CLLE program wrapper for the command and submit that

              ADDMBXPGM CLLE program:
              -----------------------------
              PGM (&field1 &field2)
              DCL &field1 *char 10
              DCL &field2 *char 10
              ADDMBX UFDNAME(&field1) PTNID(&field2)
              ENDPGM
              ---------------------------

              Submit command:
              SBMJOB CMD (CALL ADDMBXPGM (field_1 field_2))
              JOBQ(LIBNAME/JOBQ_name)
              This method works great. I went with this one! thank you. would creating a wrapper affect other programs using the ADDMBX command? I would think not since we are using a custom made PGM for this specific purpose but just want to make sure.

              Comment


              • #8
                You need to read the ZCC file in your CL program which is done with the RCVF command so that the &ZCC_CCCODE and &ZCC_CCSDSC variables are populated. If you only want to act on certain records, then just perform a test to see if it's a record that you want, like so:

                Code:
                DCLF       FILE(ZCC) OPNID(ZCC)
                
                DOWHILE    COND('1')
                RCVF       OPNID(ZCC)
                MONMSG     MSGID(CPF0864) EXEC(LEAVE)
                
                IF         COND(&ZCC_CCTABL = 'mypgm') THEN(DO)
                SBMJOB     CMD(CALL  ADDMBXPGM PARM(&ZCC_CCSDSC &ZCC_CCCODE)) +
                             JOBQ(EDIASNCLJQ)
                ENDDO
                ENDDO

                Comment


                • #9
                  Originally posted by Brian Rusch View Post
                  You need to read the ZCC file in your CL program which is done with the RCVF command so that the &ZCC_CCCODE and &ZCC_CCSDSC variables are populated. If you only want to act on certain records, then just perform a test to see if it's a record that you want, like so:

                  Code:
                  DCLF FILE(ZCC) OPNID(ZCC)
                  
                  DOWHILE COND('1')
                  RCVF OPNID(ZCC)
                  MONMSG MSGID(CPF0864) EXEC(LEAVE)
                  
                  IF COND(&ZCC_CCTABL = 'mypgm') THEN(DO)
                  SBMJOB CMD(CALL ADDMBXPGM PARM(&ZCC_CCSDSC &ZCC_CCCODE)) +
                  JOBQ(EDIASNCLJQ)
                  ENDDO
                  ENDDO
                  Thank you Brian, the code has been compiled successfully.

                  Another question is, the ZCC record that I am looking at is VERY VERY large. It has over several hundred records. The issue is that the record that I need is at the very bottom. The pointer starts at the top of the table. I am stepping thru in debug, but it is taking a rediculous amount of time to step thru it. Is there a way to have it start at a specific place in the table? I also read that you can use a logical file to only include the records that I need, OR put the records in QTEMP and loop over that instead. Are these good methods? or are there other, more efficient methods?

                  Comment


                  • #10
                    Probably the easiest would be to use an OPNQRYF command, then you wouldn't have to create a temp or logical file.

                    Code:
                    DCLF       FILE(ZCC) OPNID(ZCC)
                    
                    OVRDBF     FILE(ZCC)
                    OPNQRYF    FILE((ZCC)) QRYSLT('CCTABL = "mypgm"')
                    
                    DOWHILE    COND('1')
                    RCVF       OPNID(ZCC)
                    MONMSG     MSGID(CPF0864) EXEC(LEAVE)
                    SBMJOB     CMD(CALL ADDMBXPGM PARM(&ZCC_CCSDSC &ZCC_CCCODE)) +
                                 JOBQ(EDIASNCLJQ)
                    ENDDO

                    Comment


                    • #11
                      Originally posted by Brian Rusch View Post
                      Probably the easiest would be to use an OPNQRYF command, then you wouldn't have to create a temp or logical file.

                      Code:
                      DCLF FILE(ZCC) OPNID(ZCC)
                      
                      OVRDBF FILE(ZCC)
                      OPNQRYF FILE((ZCC)) QRYSLT('CCTABL = "mypgm"')
                      
                      DOWHILE COND('1')
                      RCVF OPNID(ZCC)
                      MONMSG MSGID(CPF0864) EXEC(LEAVE)
                      SBMJOB CMD(CALL ADDMBXPGM PARM(&ZCC_CCSDSC &ZCC_CCCODE)) +
                      JOBQ(EDIASNCLJQ)
                      ENDDO
                      Thank you, however, I am getting a
                      Code:
                      Message ID . . . . . . :   CPF4174       Severity . . . . . . . :   40        
                      Message type . . . . . :   Escape                                             
                      Date sent  . . . . . . :   10/11/17      Time sent  . . . . . . :   14:16:48  
                      
                      Message . . . . :   OPNID(ZCC) for file ZCC already exists.                   
                      Cause . . . . . :   File ZCC in library *LIBL cannot be opened with the       
                        OPNID(ZCC) parameter specified on either the OPNDBF command or OPNQRYF      
                        command because another file is already open with this parameter.  If a     
                        member was specified, it was *FIRST.                                        
                      Recovery  . . . :   Either specify a unique identifier in the OPNID parameter 
                        value or close the file that was previously opened with this parameter (CLOF
                        command).  Then try your request again.
                      I think it is because I am doing DCLF FILE(ZCC) OPNID(ZCC) at the beginning. But if I take out the OPNID(ZCC), I get another error saying the &ZCC_CC*** are referred to but not declared...

                      Comment


                      • #12
                        It will work if you take out the OPNID parameters and change the variable names to remove the ZCC_ because that is also related to the open ID. Also, I forgot to include the SHARE(*YES) parameter on the OVRDBF command. Here is the corrected code:

                        Code:
                        DCLF       FILE(ZCC)
                        
                        OVRDBF     FILE(ZCC) SHARE(*YES)
                        OPNQRYF    FILE((ZCC)) QRYSLT('CCTABL = "mypgm"')
                        
                        DOWHILE    COND('1')
                        RCVF
                        MONMSG     MSGID(CPF0864) EXEC(LEAVE)
                        SBMJOB     CMD(CALL ADDMBXPGM PARM(&CCSDSC &CCCODE)) +
                                     JOBQ(EDIASNCLJQ)
                        ENDDO

                        Comment


                        • #13
                          Originally posted by Brian Rusch View Post
                          It will work if you take out the OPNID parameters and change the variable names to remove the ZCC_ because that is also related to the open ID. Also, I forgot to include the SHARE(*YES) parameter on the OVRDBF command. Here is the corrected code:

                          Code:
                          DCLF FILE(ZCC)
                          
                          OVRDBF FILE(ZCC) SHARE(*YES)
                          OPNQRYF FILE((ZCC)) QRYSLT('CCTABL = "mypgm"')
                          
                          DOWHILE COND('1')
                          RCVF
                          MONMSG MSGID(CPF0864) EXEC(LEAVE)
                          SBMJOB CMD(CALL ADDMBXPGM PARM(&CCSDSC &CCCODE)) +
                          JOBQ(EDIASNCLJQ)
                          ENDDO
                          this will only work the very first time. when I try to run the program again, it gives the same "OPNID(ZCC) for file ZCC already exists. "
                          error. Do I need to close the file before exiting the program to prevent this?

                          EDIT: it looks like I need to close it before I exit the program: CLOF OPNID(ZCC)

                          Comment


                          • #14
                            does anyone know how to convert from GRAPHIC to CHAR?

                            the &CCSDSC field is a graphic, and when I did DCLF FILE(ZCC), it automatically created these fields as CHAR, but when I run debug, the &CCSDSC value is shown as graphic. I tried to convert it like so:
                            Code:
                            DCL &CHCCSDSC *CHAR                
                            CHGVAR VAR(&CHCCSDSC) VALUE(&CCSDSC)
                            and when I debug this line,
                            Code:
                            SBMJOB  CMD(CALL ADDMBXPGM (&CHCCSDSC &CCCODE)) +
                                    JOBQ(*LIBL/EDIASNCLJQ)
                            I get &CHCCSDSC = '_______________'
                            (empty spaces, this editor won't let me include empty spaces in between single quotes)

                            **this program is a CLP** if that is important.
                            any ideas?

                            CCSDSC GRAPHIC 15 30 119 Both Short Description
                            Field text . . . . . . . . . . . . . . . : Short Description
                            Coded Character Set Identifier . . . . . : 13488
                            UCS2 or Unicode conversion . . . . . . . : *CONVERT

                            Comment


                            • #15
                              Originally posted by skwon9642 View Post

                              this will only work the very first time. when I try to run the program again, it gives the same "OPNID(ZCC) for file ZCC already exists. "
                              error. Do I need to close the file before exiting the program to prevent this?

                              EDIT: it looks like I need to close it before I exit the program: CLOF OPNID(ZCC)
                              Sorry, yes the file needs to be closed before exiting the program which you already found out.

                              Comment

                              Working...
                              X