如何列出 journaled File ?(Command LSTJRNFILE with API QjoRetrieveJournalInformation)
應用程式有時會需要針對 PF 執行 Commit 或 Rollback 後,
所以會執行 STRJRNPF 將資料的異動過程紀錄至 journal(日誌)中,
所以 journal 中會記錄哪些 PF 或 Object 被 journal, 可以透過
Journal API QjoRetrieveJournalInformation 取得相關資訊, 此工具
LSTJRNFILE command 會將所指定的 journal file 資訊輸出至報表
File : QCLSRC
Member: LSTJRNFILC
Type : CLP
Usage : CRTCLPGM LSTJRNFILC
/*-------------------------------------------------------------------*/
/* LSTJRNFILE List processing for Journal */
/* */
/*-------------------------------------------------------------------*/
/* Author: Vengoal Chang */
/* 2005/06/13 */
/*-------------------------------------------------------------------*/
PGM (&JRNLIB)
DCL &JRNLIB *CHAR 20
DCL &LIB *CHAR 10
DCL &JRN *CHAR 10
dcl &Abending *lgl
dcl &MsgID *char 7
dcl &MsgDta *char 256
dcl &MsgF *char 10
dcl &MsgFLib *char 10
dcl &MsgKey *char 4
dcl &MsgType *char 10
dcl &RtnType *char 2
dcl &PgmName *char 10
dcl &Sender *char 80
monmsg cpf0000 exec(goto abend)
/* retrieve the program name */
sndpgmmsg msg(' ') topgmq(*same) msgtype(*info) keyvar(&msgkey)
rcvmsg pgmq(*same) msgtype(*info) sender(&sender) rmv(*yes)
chgvar &PgmName %sst(&Sender 56 10)
CHGVAR &JRN %SST(&JRNLIB 1 10)
CHGVAR &LIB %SST(&JRNLIB 11 10)
CHKOBJ OBJ(&LIB/&JRN) OBJTYPE(*JRN)
CALL LSTJRNFILR (&JRNLIB)
/* normal end of job */
sndpgmmsg msgid(cpf9898) msgf(qcpfmsg) msgtype(*comp) +
msgdta('Program' *bcat &PgmName *bcat +
'completed normally')
return
/* Routine to handle unexpected errors */
Abend:
if &Abending then(return)
chgvar &Abending '1'
rcvmsg msgtype(*last) msgdta(&msgdta) msgid(&msgid) +
rtntype(&RtnType) +
msgf(&msgf) sndmsgflib(&msgflib)
if ((&RtnType *eq '15') *or (&RtnType *eq '17')) do /* *escape */
sndpgmmsg msgid(&msgid) msgf(&msgf) msgtype(*diag) +
msgdta(&msgdta)
enddo
Escape:
sndpgmmsg msgid(cpf9898) msgf(qcpfmsg) msgtype(*escape) +
msgdta('Program' *bcat &PgmName *bcat +
'ended abnormally')
endpgm
ENDPGM
File : QRPGLESRC
Member: LSTJRNFILR
Type : RPGLE
Usage : CRTBNDRPG PGM(LSTJRNFILR) SRCFILE(lib/QRPGLESRC) SRCMBR(LSTJRNFILR)
* /// MBR name: LSTJRNFILR QRPGLESRC
*----------------------------------------------------------------
* LSTJRNFILR List journaled File..
*
* This program modify from on Craig Rutledge's LSTJRNA utility
* Modified by Vengoal Chang 2005/06/13
*
* Right now the program is set up to load a subfile with a list of journalled files.
*
* NOTE: the api can return data for more files than there is space in the api variable.
* The limit for the variable is 32767 which allows for 668 files in a single rcvr. I do not
* know why they didn't make this a user space application or give me a continuation handle.
* This will probably not be a problem in most shops anyway, just be aware of it.
*
*
* NOTE : This program MUST be compiled with DFTACTGRP = '*NO'. This is due to the bound
* call to the jrn API. I put the API to get the file text in a function. Some people
* may not need the file text and this will make it easier to remove if desired.
*
* Usage: CALL LSTJRNFILR ('journalNamjournalLib')
* parameter is 20 chars 10 journal name
* 10 journal library
*----------------------------------------------------------------
H DFTACTGRP(*NO) ACTGRP(*CALLER)
* api calls:
*
* api (application program interfaces) used:
* QjoRetrieveJournalInformation
* qbdrtvfd retrieve file description
* see system programmer'S INTERFACE REFERENCE for API detail.
*
*----------------------------------------------------------------
FQSYSPRT O F 132 Printer
*
D jrnlib s 21
D count s 7 0
D KeyOffset s 5 0
D opt s 1 make alpha
D sbfFileLib s 10
D sbfFileNam s 10
D sbfFileTxt s 50
D scrAttRcvL s 10
D scrAttRcvN s 10
D scrJrnLib s 10
D scrJrnName s 10
D scrJrnText s 30
D scrTotFile s 7 0
D scrTotMbrs s 7 0
*
*---------------------------------------------------------------------------------------------
* Prototype for calling Retrieve Journal Attributes API.
*---------------------------------------------------------------------------------------------
D ApiName c 'QjoRetrieveJournalInformation'
*---------------------------------------------------------------------------------------------
D $s s 5 0
D ds
Drtnvarlen 1 4b 0 inz(%size(qjon0100))
*
*---------------------------------------------------------------------------------------------
* These DS are used to map the STUPIDLY hard Journal Info to Retrieve parameter.
* the 2 InfoCount means I want the Journal Receiver AND the journaled file info.
*---------------------------------------------------------------------------------------------
D InfoToRtv ds
D InfoCount 1 4b 0 inz(2)
D InfoVarDS 100
*
D InfoVar ds align
D InfoVLlen 1 4b 0 inz(0) length of VL record
D InfoKey 5 8b 0 inz(0) key of info to retur
D InfoLOD 9 12b 0 inz(0) length of data
D InfoData 38 actual data
*
*---------------------------------------------------------------------------------------------
* The following are from QRPGLESRC in QSYSINC member QJOURNAL.
*---------------------------------------------------------------------------------------------
*
********************************************************************
*Type Definition for the RJRN0100 Format, for the Retrieve
*Journal Information (QjoRetrieveJournalInformation) API
*receiver variable.
********************************************************************
DQJON0100 DS 32767 inz
D QJOBRTN01 1 4B 0 Bytes Returned
D QJOBAVL01 5 8B 0 Bytes Available
D QJOOKI 9 12B 0 Off Key Info
D QJOJN00 13 22 Jrn Name
D QJOJLN 23 32 Jrn Lib Name
D QJOASP 33 36B 0 Aux Stg Pool
D QJOMQN 37 46 Message Queue Name
D QJOMQLN 47 56 Message Queue Lib
D QJOMRO 57 57 Manage Rcvr Option
D QJODRO 58 58 Delete Rcvr Option
D QJONTENT 59 59 Rcv Size Opt
D QJOIXLEN 60 60 Rcv Size Opt
D QJORSV1 61 65 Reserved 1
D QJOJT 66 66 Journal Type
D QJORJT00 67 67 Remote Jrn Type
D QJOJS 68 68 Journal State
D QJOJDM 69 69 Journl Delivery Mode
D QJOLJN 70 79 Lcl Jrn Name
D QJOLJLN 80 89 Lcl Jrn Lib Name
D QJOLJS 90 97 Lcl Jrn System
D QJOSJN 98 107 Src Jrn Name
D QJOSJLN 108 117 Src Jrn Lib Name
D QJOSJS 118 125 Src Jrn System
D QJORRLN 126 135 Redirectd Rcv Lib Nm
D QJOJT00 136 185 Journal Text
D QJORSV2 186 196 Reserved 2
D QJONAJR 197 200B 0 Num Att Jrn Rcvs
D QJOAJRN 201 210 Att Jrn Rcv Name
D QJOAJRLN 211 220 Att Jrn Rcv Lib Name
D QJOSAAJR 221 228 Lcl Jrn Sys Asc Att
D QJOSAAJR00 229 236 Src Jrn Sys Asc Att
D QJOADJRN 237 246 Att Dual JrnRcv
D QJODJRLN 247 256 Att Dual JrnRcvLib
D QJORSV3 257 448 Reserved 3
D QJONOKF 449 452B 0 number keys
*
********************************************************************
*Type Definition for the Repeating Key 1 Output, for the Retrieve
*Journal Information (QjoRetrieveJournalInformation) API
*receiver variable.
********************************************************************
D JONRK1O DS
D QJOJRN 1 10 Jrn Rcv Name
D QJOJRLN 11 20 Jrn Rcv Lib Name
D QJOJRNBR 21 25 Jrn Rcv Number
D QJOJRADT 26 38 Jrn Rcv Att DateTime
D QJOJRS 39 39 Jrn Rcv Status
D QJOJRSDT 40 52 Jrn Rcv Sav DateTime
D QJOJSAJR 53 60 LclJrn Sys AscJrnRcv
D QJOJSAJR00 61 68 SrcJrn Sys AscJrnRcv
D QJOJRS00 69 72B 0 Jrn Rcv Size
D QJOERVED01 73 128 Reserved
*
********************************************************************
*Type Definition for the Key 1 Output Section, for the Retrieve
*Journal Information (QjoRetrieveJournalInformation) API
*receiver variable.
********************************************************************
DQJONK1OS DS
D QJOTNJR 1 4B 0 Tot Num Jrn Rcvs
D QJOTSJR 5 8B 0 Tot Size Jrn Rcvs
D QJOERVED00 9 20
*
********************************************************************
*Type Definition for the Key 2 Output Section, for the Retrieve
*Journal Information (QjoRetrieveJournalInformation) API
*receiver variable.
********************************************************************
DQJONK2OS DS
D QJOTNJF 1 4B 0 Tot Num Jrn Files
D QJOTNJM 5 8B 0 Tot Num Jrn Mbrs
D QJOERVED02 9 36 Reserved
*
********************************************************************
*Type Definition for the Repeating Key 2 Output, for the Retrieve
*Journal Information (QjoRetrieveJournalInformation) API
*receiver variable.
********************************************************************
DQJONRK2O DS
D QJOOBJT00 1 10 Object Type
D QJOOBJN00 11 20 Object Name
D QJOOBJLN 21 30 Object Lib Name
D QJOERVED03 31 48 Reserved
*
*---------------------------------------------------------------------------------------------
* repeat for each key specified. rjrn0100 format. Offsets to key data
*---------------------------------------------------------------------------------------------
D RepeatKey ds align inz
D repKey 1 4b 0 Key value
D repStartOfKey 5 8b 0 Offset to start
D repLenHeader 9 12b 0 length of header dta
D repNumEntries 13 16b 0 number entries
D repLenEntry 17 20b 0 length of entry
*
*---------------------------------------------------------------------------------------------
* Error return code parm for APIs.
*----------------------------------------------------------------
D vApiErrDs ds
D vbytpv 10i 0 inz(%size(vApiErrDs)) bytes provided
D vbytav 10i 0 inz(0) bytes returned
D vmsgid 7 error msgid
D vresvd 1 reserved
D vexdta 50 replacement data
*
*---------------------------------------------------------------------------------------------
* Define function prototype to return file text from API.
*---------------------------------------------------------------------------------------------
D GetFileTxt pr 50
D 10
D 10
*
*
*---------------------------------------------------------------------------------------------
C *entry plist PASSED PARMS
C parm $JrnLib 20 OBJ LIB 20
C RefreshTag tag
*
*---------------------------------------------------------------------------------------------
* Load DS with values to return journaled object info.
* 1 = key value for journal receivers
* 0 = length of object type selector (N/A for receivers)
* *blanks = (N/A for receivers)
*---------------------------------------------------------------------------------------------
C eval InfoKey = 1 journal receivers
C eval InfoLOD = 0
C eval InfoVLlen = 12 length of VL record
C eval InfoData = *blanks
C eval InfoVarDS = InfoVar
*
* 2 = key value for objects
* 10 = length of object type selector *all
* *ALL = return all object types being journaled
C eval InfoKey = 2 files journaled
C eval InfoLOD = 10
C eval InfoVLlen = 22
C eval InfoData = '*FILE '
C eval InfoVarDS = %trimr(InFoVarDS) + InfoVar
*
C callb ApiName LOAD JRN DATA
C parm qjon0100
C parm rtnvarlen
C parm $JrnLib qualifiedJ 20
C parm 'RJRN0100' $fornm 8 TYPE FORMAT
C parm InfoToRtv
C parm vApiErrDs
*
*---------------------------------------------------------------------------------------------
* I am arbitrarily going to show only the
* first attached journal receiver on the screen. All my journals (and probably most of
* everybody elses) only have one receiver attached. If you are interested in multiple
* receivers though, let me know and I can add this code.
*---------------------------------------------------------------------------------------------
C move *blanks scrAttRcvN
C move *blanks scrAttRcvL
C move *blanks scrJrnName
C move *blanks scrJrnLib
C move *blanks scrJrnText
*
C eval scrAttRcvN = qjoajrn Attached Receiver
C eval scrAttRcvL = qjoajrln Attached Rcv Lib
*
C eval scrJrnName = qjojn00 Journal name
C eval scrJrnLib = qjojln Journal library
C eval scrJrnText = qjojt00 Journal text
*
*---------------------------------------------------------------------------------------------
* First we want to get the number of Keys
* that where returned. In this case it should be 2 as that is all I asked for.
*
* Then spin down the key offsets until we find key number 2. That will be the journaled
* files.
*---------------------------------------------------------------------------------------------
C z-add 453 KeyOffset
1B C do qjonokf number of keys
C eval RepeatKey = %subst(qjon0100:KeyOffset:20)
2B C select
2X C when repKey = 1 Journal Receivers
****** exsr GetJrnRcvs
2X C when repKey = 2 Journaled files
C exsr GetFileNames
2X C when repKey = 3 Remote Journal Info
***** exsr GetRemote
2E C endsl
C add 20 KeyOffset
1E C enddo
*
C eval *inlr = *on PROGRAM END
*
*---------------------------------------------------------------------------------------------
* Process the journaled file names. use the offsets to spin through file names.
*---------------------------------------------------------------------------------------------
C GetFileNames begsr
C z-add 0 scrTotFile
C z-add 0 scrTotMbrs
C move *blanks sbfFileNam
C move *blanks sbfFileLib
*
C eval $s=(repStartOfKey + qjooki + 5)
C eval qjonk2os = %subst(qjon0100:$s:repLenHeader)
C z-add QJOTNJF scrTotFile Tot Num Jrn Files
C z-add QJOTNJM scrTotMbrs Tot Num Jrn Mbrs
*
C add repLenHeader $s step over to list
*
C eval JrnLib = %trim(%subst($JrnLib:11:10))+
C '/' +
C %trim(%subst($JrnLib:1:10))
C except HEAD
1B C do repNumEntries count
C eval qjonrk2o = %subst(qjon0100:$s:repLenEntry)
C move qjoobjn00 sbfFileNam
C move qjoobjln sbfFileLib
c* sbfFileNam dsply
*
* ----------------------------------------------------------------
* Execute a function to get the file text.
* ----------------------------------------------------------------
C eval sbfFileTxt =
C GetFileTxt(sbfFileNam:sbfFileLib)
*
C except out LOAD SUBFILE
*
* ----------------------------------------------------------------
C add repLenEntry $s next entry
1E C enddo
C endsr
*
OQSYSPRT E HEAD 1
O 9 'Journal:'
O JrnLib 31
O E HEAD 1
O 5 'File'
O 19 'Library'
O 28 'Text'
O E OUT 1
O sbfFileNam B 11
O sbfFileLib B 22
O sbfFileTxt B 74
*
*---------------------------------------------------------------------------------------------
* Function to return File Text. This was done a function to isolate the D specs from
* the complexity of the Journal API.
*---------------------------------------------------------------------------------------------
PGetFileTxt B Begin Procedure
D GetFileTxt pi 50 Procedure Interface
D sbfFileNam 10 incoming arguement
D sbfFileLib 10 incoming arguement
D fillib s 20 file library
D $fltxt s 50 file library
D$systm$ c const('*FILETYPE')
*
*----------------------------------------------------------------
* this value is used as an offset to the file scope array section
* fhflg = rd bit is used to determine if original file is
* physical or logical file.
* fscope = offset
*----------------------------------------------------------------
D $rcvds ds
D $rcvln 1 4b 0 inz(32000)
D $rcvar ds 32000 inz
D fhflg 9 9 file type bits
D qdbfmtnum 62 63b 0 number record fmts
D qdbfhtxt 85 134 file text
D $flfld$ 207 208b 0 number of fields
D $fllen$ 305 306b 0 file length
D fscope 317 320b 0 offest to file scope
*
*----------------------------------------------------------------
* Error return code parm for APIs.
*----------------------------------------------------------------
D vApiErrDs ds
D vbytpv 10i 0 inz(%size(vApiErrDs)) bytes provided
D vbytav 10i 0 inz(0) bytes returned
D vmsgid 7 error msgid
D vresvd 1 reserved
D vexdta 50 replacement data
*
C eval fillib = sbfFileNam + sbfFileLib
*
*----------------------------------------------------------------
* call API to get file description.
*----------------------------------------------------------------
C call 'QDBRTVFD' LOAD DBR
C parm $rcvar RECEIVER VARIAB
C parm $rcvln RECEIVER LENGTH
C parm $rtnfl 20 RETRN FILE/LIB
C parm 'FILD0100' $fornm TYPE FORMAT
C parm fillib $fillb 20 FILE LIB 20
C parm '*FIRST ' $formt 10 ALL FORMATS
C parm '0' $ovrrd 1 NO OVERRIDES
C parm $systm$ $systm 10 WHICH SYSTEM
C parm '*EXT' $frmtp 10 FORMAT TYPE?
C parm vApiErrDs
*
C eval $fltxt=qdbfhtxt
C return $fltxt return value
PGetFileTxt E End Procedure
File : QCMDSRC
Member: LSTJRNFILE
Type : CMD
Usage : CRTCMD CMD(LSTJRNFILE) PGM( lib/LSTJRNFILC)
/*-------------------------------------------------------------*/
/* Author: Vengoal Chang */
/* 2005/06/13 */
/*-------------------------------------------------------------*/
/* To Compile: */
/* CREATE RPGLESRC PGM --> LSTJRNFILR */
/* CREATE CLP PGM --> LSTJRNFILC CMD PGM */
/* CRTCMD CMD(XXX/LSTJRNFILE) PGM(XXX/LSTJRNFILC) + */
/* SRCFILE(XXX/QCMDSRC) */
/*-------------------------------------------------------------*/
LSTJRNFILE: CMD PROMPT('List Journaled File')
PARM KWD(JOURNAL) TYPE(NAME1) MIN(1) +
PROMPT('Journal name')
NAME1: QUAL TYPE(*NAME) LEN(10) EXPR(*YES)
QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
SPCVAL((*LIBL)) EXPR(*YES) CHOICE('Name, +
*LIBL') PROMPT('Library')
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期二, 11月 07, 2023
2005-06-18 如何列出 journaled File ?(Command LSTJRNFILE with API QjoRetrieveJournalInformation)
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言