How to run a command that submit a JOB to QBATCH then get JOB number for later use in CL PGM

656 views Asked by At

I try to create a command that submit a JOB to QBATCH, after that I want to get the returned JOB number for next command

I try RTVJOBA but it's not right

RTVJOBA retrieve my current USER JOB while the submitted command has different job number

Please help me resolve

I attach code here

           PGM
           DCL        VAR(&TEMPFILE)             TYPE(*CHAR) LEN(10)
           DCL        VAR(&LEVEL)                TYPE(*CHAR) LEN(10)
           DCL        VAR(&USER )                TYPE(*CHAR) LEN(10)
           DCL        VAR(&JOB  )                TYPE(*CHAR) LEN(10)
           DCL        VAR(&NBR  )                TYPE(*CHAR) LEN(06)
           DCL        VAR(&SBMMSGQ)              TYPE(*CHAR) LEN(10)
           DCLF       FILE(MLIB/PGM_LIST)
           RTVJOBA    USER(&USER)
           RTVJOBA    NBR(&NBR )
           CHGVAR     VAR(&TEMPFILE)  VALUE(&USER || '01')
           CHKOBJ     OBJ(TEMPLIB/&TEMPFILE) OBJTYPE(*FILE)
           MONMSG     MSGID(CPF9801) +
                           EXEC(GOTO CMDLBL(NEXT1))
           DLTF       TEMPLIB/&TEMPFILE
NEXT1:       CPYF       FROMFILE(LIB/PGM_TEMP)     +
                      TOFILE(TEMPLIB/&TEMPFILE) +
                      CRTFILE(*YES)
     /*    ADDLIBLE   &LEVEL              */
           MONMSG     MSGID(CPF2110) EXEC(GOTO CMDLBL(ERRMSG1))
           MONMSG     MSGID(CPF2103)
READ:        RCVF       RCDFMT(RECORD1)
           MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(CLOSE))
           COBLIST    (&PGM_NAME)   LEVEL(*FULL) /* submit a job to QBATCH */                    
           RTVJOBA    NBR(&NBR)
           CPYSPLF    FILE(&PGM_NAME) TOFILE(TEMPLIB/&TEMPFILE)      +
                      JOB(&NBR/&USER/&PGM_NAME)                       +
                       MBROPT(*ADD)  SPLNBR(*LAST)
           GOTO READ
CLOSE:       CLOSE
        /* RMVLIBLE   &LEVEL    */
           GOTO RETURN
ERRMSG1:     SNDPGMMSG  MSG('LIB NOT FOUND')
           GOTO CLOSE
RETURN:      RETURN
           ENDPGM
2

There are 2 answers

0
Barbara Morris On

After the SBMJOB, you can receive the completion message that gives the submitted job number. You can try this little program to see how it works.

     /* Data structure with the first three replacement */  
     /* values of CPC1221                               */  
     DCL        VAR(&CPC1221MSG) TYPE(*CHAR) LEN(26)        
        DCL     VAR(&jobname1) TYPE(*CHAR) STG(*DEFINED) +  
                  LEN(10) DEFVAR(&CPC1221MSG 1)             
        DCL     VAR(&jobuser2) TYPE(*CHAR) STG(*DEFINED) +  
                  LEN(10) DEFVAR(&CPC1221MSG 11)            
        DCL     VAR(&jobnum3) TYPE(*CHAR) STG(*DEFINED) +   
                  LEN(6) DEFVAR(&CPC1221MSG 21)             

     SBMJOB     CMD(DSPJOB OUTPUT(*PRINT)) JOBQ(QINTER)     
     RCVMSG     PGMQ(*SAME) MSGTYPE(*COMP) RMV(*NO) +       
                  MSGDTA(&CPC1221MSG)                       
     sndpgmmsg (&jobname1 *cat &jobuser2 *cat &jobnum3)       

          
0
Jairo R. Flores On

the only way I've used to achieve this is using the spawn API, maybe you should take a look of it.

Return Value
value spawn() was successful. The value returned is the process ID of the child process.
-1 spawn() was not successful. The errno variable is set to indicate the error.

I'm sorry I can't bring you an example, 'cause the only code I made with this API is for my company. But the whole idea is you can spawn several process and get those process id. With this process id you can see if still active.