Difference between revisions of "Get Last Joblog Messages"
From MidrangeWiki
DaveLClarkI (talk | contribs) (→Service Procedure) |
DaveLClarkI (talk | contribs) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:RPG Examples]] | ||
[[Category:Sample Code]] | [[Category:Sample Code]] | ||
[[Category:Service Procedures]] | [[Category:Service Procedures]] | ||
Line 13: | Line 14: | ||
//****************************************************************************** | //****************************************************************************** | ||
// Get information about the last nn messages in the current joblog. | // Get information about the last nn messages in the current joblog. | ||
+ | // If the requested message count is zero, then only the last exception | ||
+ | // message is retrieved from the joblog. | ||
//****************************************************************************** | //****************************************************************************** | ||
dcl-pr GenUtl_GetLastJoblogMessages; | dcl-pr GenUtl_GetLastJoblogMessages; | ||
Line 42: | Line 45: | ||
//****************************************************************************** | //****************************************************************************** | ||
// Get information about the last nn messages in the current joblog. | // Get information about the last nn messages in the current joblog. | ||
+ | // If the requested message count is zero, then only the last exception | ||
+ | // message is retrieved from the joblog. | ||
//****************************************************************************** | //****************************************************************************** | ||
dcl-proc GenUtl_GetLastJoblogMessages export; | dcl-proc GenUtl_GetLastJoblogMessages export; |
Latest revision as of 19:54, 26 December 2018
Summary
The following are the RPG/LE fully free-form definitions and instructions needed for using the Get Last Joblog Messages service procedure. This service procedure simply allows the caller to get the last nn messages from the current joblog.
By Dave Clark
Service Prototype
Place the following in a separate copybook for inclusion in both the caller and the service program source members.
**free //****************************************************************************** // Get information about the last nn messages in the current joblog. // If the requested message count is zero, then only the last exception // message is retrieved from the joblog. //****************************************************************************** dcl-pr GenUtl_GetLastJoblogMessages; pMsgCnt packed(5:0); pMsgInfo likeds(GenUtl_MsgInfo) dim(%elem(GenUtl_MsgInfo)) options(*varsize); end-pr; /include qsysinc/qrpglesrc,qgyoljbl // QGYOLJBL API structures // data structure to return message information dcl-ds GenUtl_MsgInfo qualified dim(20); Id char(7); Type char(10); File char(10); FLib char(10); Data varchar(3000) inz; end-ds;
Service Procedure
Place the following in a service program source member.
**free ctl-opt NoMain AlwNull(*UsrCtl) Debug Option(*SrcStmt:*NoDebugIo) DatFmt(*ISO) TimFmt(*ISO); //****************************************************************************** // Get information about the last nn messages in the current joblog. // If the requested message count is zero, then only the last exception // message is retrieved from the joblog. //****************************************************************************** dcl-proc GenUtl_GetLastJoblogMessages export; dcl-pi *n; pMsgCnt packed(5:0); pMsgInfo likeds(GenUtl_MsgInfo) dim(%elem(GenUtl_MsgInfo)) options(*varsize); end-pi; dcl-s iMsgCnt like(pMsgCnt); dcl-s curmsg like(pMsgCnt); dcl-s idx like(pMsgCnt); dcl-s ofs int(10); dcl-s ofs2 like(ofs); dcl-s iCaller char(10); dcl-s msgtyp char(10); dcl-s msgfile char(10) inz('QCPFMSG'); dcl-s ListRcvr char(32767); dcl-ds selinfo qualified; MSI likeds(QGYOMSI); QGYFID int(10) dim(1); QGYCMQN char(10); end-ds; iMsgCnt = pMsgCnt; // number of messages requested if iMsgCnt < 1; // if last *EXCP message requested iMsgCnt = 1; // default to 1 message endif; GenUtl_CSTKE = GenUtl_FindCallStackEntry('*PRV':PROC_PGM); iCaller = GenUtl_CSTKE.QWVPGMN; // save caller name clear selinfo; // clear selection information ds selinfo.MSI.QGYLD = '*PRV'; // get most recent messages first selinfo.MSI.QGYJN = '*'; // from this job's joblog selinfo.MSI.QGYSMK = *hival; // starting at end of joblog selinfo.MSI.QGYIDO = %len(selinfo.MSI); // offset to selection criteria selinfo.MSI.QGYNBRF00 = 1; // number of field id's selinfo.MSI.QGYQO = selinfo.MSI.QGYIDO + %size(selinfo.QGYFID:*ALL); // offset to message queue name selinfo.MSI.QGYMQNS = %len(selinfo.QGYCMQN); // length of message queue name selinfo.QGYFID(1) = 0201; // replacement data or impromptu message text selinfo.QGYCMQN = '*'; // call stack message queue name callp IBMAPI_ListJobLogMessages( ListRcvr: %len(ListRcvr): QGYOLI : 1: selinfo: %len(selinfo): ApiErrC ); if ApiErrC.BytAvail > *zero; // if API error, report it if %subst(ApiErrC.MsgId:1:3) = 'GUI'; // different msgfile? msgfile = 'QGUIMSG'; // supply it endif; callp GenUtl_Escape( ApiErrC.MsgId : %subst(ApiErrC.MsgData: 1: ApiErrC.BytAvail - 16) : msgfile: *omit: iCaller ); endif; curmsg = 1; // set message counter idx = *zero; // set message index dow idx < iMsgCnt // load requested number of messages and ApiErrC.MsgId <> 'GUI0006'; // unless end of message list exceeded QGYORV = %subst(ListRcvr: 1: %len(QGYORV)); // map message header ofs = QGYOTFR + 1; // set offset to field identifier (FID) QGYOIDFI = %subst(ListRcvr: ofs: %len(QGYOIDFI)); // map FID header ofs2 = ofs + %len(QGYOIDFI); // set offset to data associated with FID select; // interpret message type when QGYMT = '01'; // completion msgtyp = '*COMP'; when QGYMT = '02'; // diagnostic msgtyp = '*DIAG'; when QGYMT = '04'; // informational msgtyp = '*INFO'; when QGYMT = '05'; // inquiry msgtyp = '*INQ'; when QGYMT = '06'; // sender's copy msgtyp = '*COPY'; when QGYMT = '08'; // request msgtyp = '*RQS'; when QGYMT = '10'; // request with prompting msgtyp = '*RQS'; when QGYMT = '14'; // notify, exception already handled msgtyp = '*NOTIFY'; when QGYMT = '15'; // escape, exception already handled msgtyp = '*ESCAPE'; when QGYMT = '16'; // notify, exception not yet handled msgtyp = '*NOTIFY'; when QGYMT = '17'; // escape, exception not yet handled msgtyp = '*ESCAPE'; other; // unknown msgtyp = '*MT' + QGYMT; endsl; if pMsgCnt > *zero // if all msg types requested and (QGYMID > *blank // and msg id present or msgtyp <> '*RQS') // or not request-type message or pMsgCnt = *zero // or only exception messages and msgtyp = '*ESCAPE'; // and this is an exception msg idx += 1; // then increment message index pMsgInfo(idx).Id = QGYMID; // and load message id pMsgInfo(idx).Type = msgtyp; // message type pMsgInfo(idx).File = QGYMFILN; // message file name pMsgInfo(idx).FLib = QGYML; // message file library name pMsgInfo(idx).Data = %trimr(%subst(ListRcvr: ofs2: QGYDL)); // repl. data if QGYML <= *blanks or QGYML = '*LIBL'; select; // if message file library is missing when QGYMFILN = 'CP_MSGF'; // if a known message file pMsgInfo(idx).FLib = 'COOLSPV7R1'; // supply the library name when QGYMFILN = 'QZSHMSGF'; // if a known message file pMsgInfo(idx).FLib = 'QSHELL'; // supply the library name other; // else pMsgInfo(idx).FLib = '*LIBL'; // hope it is in the liblist endsl; endif; endif; if idx < iMsgCnt; // max requested not exceeded? curmsg += 1; // increment message counter callp IBMAPI_GetListEntries( ListRcvr: %len(ListRcvr): QGYRH00 : QGYOLI: 1: curmsg: ApiErrC ); // get prev. msg if ApiErrC.BytAvail > *zero // if API error, report it and ApiErrC.MsgId <> 'GUI0006'; // unless it is end of list if %subst(ApiErrC.MsgId:1:3) = 'GUI'; // different msgfile? msgfile = 'QGUIMSG'; // supply it endif; callp GenUtl_Escape( ApiErrC.MsgId : %subst(ApiErrC.MsgData: 1: ApiErrC.BytAvail - 16) : msgfile: *omit: iCaller ); endif; endif; enddo; // loop on message count callp IBMAPI_CloseList(QGYRH00: ApiErrC); // close the list if ApiErrC.BytAvail > *zero; // if API error, report it if %subst(ApiErrC.MsgId:1:3) = 'GUI'; // different msgfile? msgfile = 'QGUIMSG'; // supply it endif; callp GenUtl_Escape( ApiErrC.MsgId : %subst(ApiErrC.MsgData: 1: ApiErrC.BytAvail - 16) : msgfile: *omit: iCaller ); endif; pMsgCnt = idx; // pass back no. of messages retrieved return; // return to caller end-proc;
References
- API Error Code Structure (ApiErrC)
- Escape service procedure
- Find Call Stack Entry service procedure
- IBMAPI_ListJobLogMessages API
- IBMAPI_GetListEntries API
- IBMAPI_CloseList API