This installment of APIs by Example shows how to use API QGYOLJBL to retrieve job log messages. This API lists messages from the specified job's job log in sending date and time order. Replies to any inquiry messages are listed immediately after the inquiry message with which they are associated.
In addition to API QGYOLJBL, service program CBX007 uses API QGYCLST to close the open list of job log messages. Like all other open list APIs, these APIs are located in library QGY. You must, therefore, ensure that library QGY is in your library list at execution time.
Service program CBX007 encapsulates the function of API QGYOLJBL into procedure GetLogMsg. You can bind your application programs to service program CBX007 and invoke procedure GetLogMsg to retrieve job log messages.
You should note a couple of security requirements for listing job log messages. *JobCtl special authority is required to list the job log messages of another user. Additionally, to list the job log of a user with a user class of *SecOfr, *AllObj special authority is required.
Here are the calling parameters for procedure GetLogMsg:
Parameters:
PxJobId INPUT
Qualified job name of the job whose job log messages are to be listed. The following format applies:
| 1-10 | Char 10 | Job name |
| 11-20 | Char 10 | Job user |
| 21-26 | Char 6 | Job number |
The special value '*' is allowed. This value identifies the current job.
PxMsgOpt INPUT
List message option. The following special values are allowed:
| *FIRST | Retrieve the first (oldest) message |
| *LAST | Retrieve the last (newest) message |
| *NEXT | Retrieve the message following that identified by PxMsgKey |
| *PRV | Retrieve the message previous to that identified by PxMsgKey |
PxMsgKey INPUT
Optional parameter holding the message key value used to position the list prior to the retrieval of the message requested by the PxMsgOpt parameter's relative special values.
Return Value:
FdData
Job log message text. Other available message value attributes could be added to or replace this value.
There are five main steps performed by procedure GetLogMsg:
You can find detailed information on QGYOLJBL at
http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/info/apis/QGYOLJBL.htm.
You can find detailed information on QGYCLST at
http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/info/apis/qgyclst.htm.
The source for service program CBX007 appears below:
* ================================================================== * = Service program... CBX007 = * = Description....... Job log message routines = * = = * = CrtRPGMod Module( CBX007 ) = * = CrtSrvPgm SrvPgm( CBX007 ) Module( CBX007 ) Export( *All ) = * ================================================================== H NoMain Option( *SrcStmt ) *-- API error data structure D ApiError Ds D AeBytPrv 10i 0 Inz( %Size( ApiError )) D AeBytAvl 10i 0 D AeExcpId 7a D 1a D AeExcpDta 128a *-- Get joblog message procedure prototype D GetLogMsg Pr 512a Varying D PxJobId 26a Const D PxMsgOpt 6a Const D PxMsgKey 4a Options( *NoPass ) *-- Get joblog message procedure P GetLogMsg B Export D Pi 512a Varying D PxJobId 26a Const D PxMsgOpt 6a Const D PxMsgKey 4a Options( *NoPass ) *-- API parameters D JlMsgInfLen s 10i 0 Inz( %Size( JlMsgInf )) D JlSltInfLen s 10i 0 Inz( %Size( JlSltInf )) D JlGetRcdNbr s 10i 0 D JlRtnRcdNbr s 10i 0 D JlSltInf Ds D SiRtvDrc 10a D SiJobId 26a Inz( '*' ) D SiIntJobId 16a D SiStrKey 4a D SiStrKeyN 10i 0 Overlay( SiStrKey ) D SiMsgLenMax 10i 0 Inz( -1 ) D SiHlpLenMax 10i 0 Inz( 0 ) D SiFldIdsOfs 10i 0 Inz( 84 ) D SiFldIdsNbr 10i 0 Inz( %Elem( SiFldIds )) D SiCalMsqOfs 10i 0 Inz( 88 ) D SiCalMsqLen 10i 0 Inz( 1 ) D 4a D SiFldIds 10i 0 Dim( 1 ) Inz( 302 ) D SiCalMsq 10a Inz( '*' ) D JlLstInf Ds D LiRcdNbrTot 10i 0 D LiRcdNbrRtn 10i 0 D LiHandle 4a D LiRcdLen 10i 0 D LiInfSts 1a D LiDts 13a D LiLstSts 1a D 1a D LiInfLen 10i 0 D LiRcd1 10i 0 D 40a D JlMsgInf Ds D MiNxtMsgOfs 10i 0 D MiFldDtaOfs 10i 0 D MiFldNbrOfs 10i 0 D MiMsgSev 10i 0 D MiMsgId 7a D MiMsgTyp 2a D MiMsgKey 4a D MiMsgF 10a D MiMsgFlib 10a D MiDatSnt 7a D MiTimSnt 6a D MiFldDta 32767a D JlFldDta Ds Based( pJlFldDta ) D FdNxtFldOfs 10i 0 D FdFldDtaLen 10i 0 D FdFldId 10i 0 D FdDtaTyp 1a D FdDtaSts 1a D 14a D FdDtaLen 10i 0 D FdDta 1024a *-- Get joblog message C Eval SiJobId = PxJobId C Eval SiStrKey = x'00000000' C Select C When PxMsgOpt = '*FIRST' C Eval SiRtvDrc = '*NEXT' C When PxMsgOpt = '*LAST' C Eval SiRtvDrc = '*PRV' C Eval SiStrKey = x'FFFFFFFF' C When PxMsgOpt = '*NEXT' Or C PxMsgOpt = '*PRV' C Eval SiRtvDrc = PxMsgOpt C If %Parms = 3 C Eval SiStrKey = PxMsgKey C EndIf C EndSl C Select C When PxMsgOpt = '*NEXT' C Eval SiStrKeyN = SiStrKeyN + 1 C When PxMsgOpt = '*PRV' C Eval SiStrKeyN = SiStrKeyN - 1 C EndSl C Call 'QGYOLJBL' C Parm JlMsgInf C Parm JlMsgInfLen C Parm JlLstInf C Parm 1 JlGetRcdNbr C Parm JlSltInf C Parm JlSltInfLen C Parm ApiError C If AeBytAvl = *Zero And C LiRcdNbrRtn = 1 C Eval pJlFldDta = %Addr( JlMsgInf ) + C MiFldDtaOfs C If %Parms = 3 C Eval PxMsgKey = MiMsgKey C EndIf C Else C Eval FdDta = *Blanks C EndIf C Call 'QGYCLST' C Parm LiHandle C Parm ApiError C Return FdDta P GetLogMsg E
Program CBX007T shows how your application code can use procedure GetLogMsg in service program CBX007 to retrieve job log messages. The program appears below:
* ================================================================== * = Program....... CBX007T = * = Description... Sample code using procedure GetLogMsg = * = = * = CrtRPGMod Module( CBX007T ) = * = CrtPgm Pgm( CBX007T ) Module( CBX007T ) BndSrvPgm( CBX007 )= * ================================================================== H Option( *SrcStmt ) *-- API error data structure D ApiError Ds D AeBytPrv 10i 0 Inz( %Size( ApiError )) D AeBytAvl 10i 0 D AeExcpId 7a D 1a D AeExcpDta 128a *-- Get joblog message prototype D GetLogMsg Pr 512a Varying D PxJobId 26a Const D PxMsgOpt 6a Const D PxMsgKey 4a Options( *NoPass ) *-- Data definitions D JobId s 26a D Msg s 256a D MsgKey s 4a C Eval JobId = '*' C Eval Msg = GetLogMsg( JobId C : '*LAST' C ) C Eval Msg = GetLogMsg( JobId C : '*LAST' C : MsgKey C ) C Eval Msg = GetLogMsg( JobId C : '*PRV ' C : MsgKey C ) C Eval Msg = GetLogMsg( JobId C : '*PRV ' C : MsgKey C ) C Eval Msg = GetLogMsg( JobId C : '*FIRST' C : MsgKey C ) C Eval Msg = GetLogMsg( JobId C : '*NEXT' C : MsgKey C ) C Eval Msg = GetLogMsg( JobId C : '*NEXT' C : MsgKey C ) C Eval *InLr = *On
The above tip was written by Carsten Flensburg. For questions regarding this tip, contact Carsten at mailto:flensburg@novasol.dk.