Example - Wait a Specified Time Interval

This article describes how to use READA to wait a specified time interval.
One way to use READA is to set a timer and have your exec wake up after a specified interval. The following example runs five times, waking up every 15 seconds to obtain trace data collected by Db2 during the previous 15-second interval. Each time the exec resumes execution, it issues a READA request to obtain the accumulated trace data. This exec, named RIFSAMP2, can be found in the CRAIEXEC library.
/* REXX */ address IFI
(1)
Signal on error name Terminate
(2)
Signal on syntax name Terminate
(2)
dsn = '' /* Specify Db2 subsystem name */ plan = '' /* Specify RLX plan name */ wbufsize = 8 /* size of the trace buffer */ wbuffmt = 'DEFAULT' /* map all ifcids */ "caf activate thread(:t1) system(:dsn) plan(:plan)"
(3)
if rc <> 0 then return "-start trace (perfm) class(30) IFCID(65)",
(4)
"dest(opx) bufsize("wbufsize")" if ifcarc1 > 0 then return do 1 x = wait( SEC ,15)
(5)
"READA"
(6)
say 'READA completed, IFCA RC1='ifcarc1 'RC2='ifcarc2 if ifcabm > 0 then
(7)
call Display_trace else say 'No data received' end Terminate : "-stop trace(perfm) tno("ifcatnor")"
(8)
"caf remove thread(:t1)"
(9)
return Display_trace : Say '>>>Total number of IFCIDs received' ifc.0 do i = 1 to ifc.0
(10)
Say ' ' Say '>>>Record' i 'IFCID =' ifcid.i Say Product_headers() if ifcid.i <> 65 then iterate
(11)
do j = 1 to ifc.i.0
(12)
do k = 1 to ifc.i.j.0
(13)
call Display_ifcid0065 end end end Return Display_ifcid0065 :
(14)
Say 'Location name =' QW0065LN.i.j.k Say 'Package Collection =' QW0065PC.i.j.k Say 'Program name =' QW0065PN.i.j.k Say 'Time stamp =' QW0065TS.i.j.k Say 'Statement Number =' QW0065SN.i.j.k Say 'Statement Type =' QW0065ST.i.j.k Say 'Cursor name =' QW0065CL.i.j.k Return Product_headers :
(15)
headers = '>>> Products headers:' if qwhs.i.0 > 0 then headers = headers 'QWHS=YES' if qwhc.i.0 > 0 then headers = headers 'QWHC=YES' if qwhu.i.0 > 0 then headers = headers 'QWHU=YES' if qwhd.i.0 > 0 then headers = headers 'QWHD=YES' if qwht.i.0 > 0 then headers = headers 'QWHT=YES' Return headers
Notes:
(1)
Establish IFI as the default REXX host command environment
(2)
If an error occurs, make sure execution resumes at the Terminate label.
(3)
Connect to the Db2 subsystem whose name is the REXX variable DSN. Open a monitor application plan whose name is in the REXX variable PLAN.
(4)
Issue a -START TRACE command to create and claim ownership of a Db2 trace buffer of 8K bytes. The Trace command identifies which IFCIDs (trace events) to collect in the buffer. This example traces execution of OPEN cursor statements (IFCID 65). Also, since this is a Performance trace and not a Monitor trace, the trace command must also specify an explicit TRACE destination of OPX.
(5)
the WAIT service of the
RLX
/Software Development Kit puts the exec in a wait state for 15 seconds.
(6)
The READA command obtains the accumulated trace data and maps it into REXX variables.
(7)
If some bytes were moved into the return area by the READA command, display REXX variables that are populated with data from the return buffer.
(8)
Stop the Db2 trace
(9)
Remove the monitor thread
(10)
Process every IFCID record
i
in the returned buffer, up to the maximum of records stored in the counter IFC.0.
(11)
Process only IFCID 0065, skip other IFCID processing. If you must select other IFCIDs, first collect them. Then determine the names of the variables comprising the IFCID map. Then write REXX code to process them.
(12)
Process each section
j
in the IFCID record
i,
up to the maximum number of data records stored in the counter IFC.i.0.
(13)
For every occurrence
k
of the data section
j
of the IFCID record
i,
display the data section occurrences. In the case of IFCID 0065, there is always one data section which occurs only once. But for some other IFCIDs -- such as 0124, 0148, 0058, and others -- there are multiple data sections which may occur many times. This section of REXX code can handle any of the complex IFCID maps
.
(14)
Display the REXX variables created by the READA service for IFCID 0065
(15
) Determine what Product Headers are present in the IFCID being processed. The presence of the Header is controlled by the TDATA parameter of the trace command.