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
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.