# SMF Records/How to Extract Values from SMF Record Fields
## How to Extract Values from SMF Record Fields
### Summary

Processing the SMF record data with a REXX program in a batch environment consists roughly of the following steps:
* Read the original SMF dataset (DUMPIN DD) with the IBM IFASMFDP program (see L11 or L12 )
* Select the SMF record data you would like to process with a corresponding SYSIN DD Statement (see L11 or L12 for parameters)
* Write formatted output into a new temporary dataset (DUMPOUT DD)
* Convert the DUMPOUT dataset with the IBM IDCAMS REPRO Command into a readable format for REXX using a work dataset (WORKSMF DD)
* Read all records from the WORKSMF dataset into a stem. variable in the memory of the REXX program
* Process the required data and put the resulting comma-separated values file into another stem. variable for output
* After finishing processing write this stem. variable into an output dataset (OUTDS DD) to store the resulting report

### The Job Control Language

To process SMF record data with a REXX program in a batch environment there are a couple of prerequisites. First of all a formatted dump from the SMF dataset is needed, which can be produced with the IBM IFASMFDP program (see L11 or L12 ). Be sure to have at least read access to the SMF datasets in your installation. Unfortunately the resulting dataset from IFASMFDP has a RECFM(VBS) and is not readable directly in REXX. It has to be converted into another work dataset with RECFM(VB) and a suitable LRECL and BLKSIZE. This is done with the IBM IDCAMS REPRO command. Both the IFASMFDP and the REPRO commands are called from within the REXX script while the necessary DD statements are in the JCL itself.
Chart 1: JCL for Data Selection and REXX Execution
In the example provided the first step KILL01 just deletes the work dataset and the resulting report dataset, because they are defined in the READSMF step as DISP=(NEW,CATLG).
In the READSMF step the program IKJEFT01 is executed to provide the necessary TSO/ISPF environment for calling the REXX program in batch.
* All ISP* DD Statements belong to this environment.
* The DD statements DUMPIN, DUMPOUT, SYSPRINT and SYSIN belong to the program IFASMFDP called at the beginning of the process_smf_data procedure in the REXX script.
** In particular the SYSIN DD statement provides the possibility of shrinking the data to only the really necessary amount for processing. In this example data is limited to only the SMF19 Records of day 334 in 2013 within the timeframe 00:00 AM to 01:00 AM. To avoid too long execution times and errors because of redundant data or insufficient storage, it is strongly recommended to reduce the amount of data processed at this point to the data really needed.
** The DUMPOUT DD statement defines only a temporary dataset with DSN=&&DP, because as mentioned before it is only needed for convertion into a work dataset with the REPRO Command called from within the REXX Script with "REPRO IFILE(DUMPOUT) OFILE(WORKSMF)".
** The SYSPRINT DD statement is used to show the number of read and written SMF records by the program IFASMFDP in the job output
* The SYSEXEC DD statement defines the dataset which contains the REXX script.
* The WORKSMF DD statement defines the source dataset for the REXX processing. All SMF records contained in this dataset are put into the stem variable SMF.. SMF. is then processed by the REXX code and the resulting values are written into another stem variable DASD_OUT. in comma-separated values format. In fact here they are actually semicolon-separated values because of the spreadsheet number format in some countries.
* The OUTDS DD statement defines the output dataset where the stem variable DASD_OUT. is written at the end of the REXX processing with the command "Execio * Diskw OUTDS (finis stem dasd_out."
* The SYSTSPRT DD statement defines the part in the job output where the REXX script can write out messages i.e. with the say command. This is extremely useful for both documentation and debugging purposes.
* The SYSTSIN DD statement contains the ISPSTART CMD(SMF19) command to start the REXX script with the member name SMF19

### The REXX Script

The REXX scripts in this book are all more or less built on the same structure:
* Part 1 consists of a initialize procedure which only writes a border line into the job output and a process_smf_data procedure which is the main program of the REXX
* Part 2 consists of a function to compute the field offsets relative to the beginning of the record and some functions to convert different data formats into processable formats for output.
Because the function part (Part 2) is the same in all following examples it is only shown once in this complete example. It is not necessary to repeat it in all following examples. Nevertheless the universal function part is necessary and should be copied at the end of each following REXX example where indicated.
Chart 2: REXX SMF19 to create a .csv file with the values of interest
Let's now go through the main procedure process_smf_data.
* As described in the JCL part the program IFASMFDP is called to get a formatted dump and the REPRO command is used to convert the dump output into the correct dataset format.
* "EXECIO * DISKR WORKSMF ( FINIS STEM SMF." read all records of the working dataset into memory
* The drop DASD_OUT. just clears the output variable DASD_OUT.
* The counter variables count and j are then initialized to a value of 1 and a header with date, time and the number of read SMF records is written into the job output (SYSTSPRT).
* After this initial work processing a conditional loop for each record begins
At this point you should check the description of the SMF19 record mapping(see L11 or L12 ) to track the different offsets and length of the used record fields. In most cases we used the field names from this description.
* Now for each record the record header and type is extracted and a line is written to the job output containing the line number and the record type
* If the record type is 19 some directly usable values such as Time, Date, SYSID, Volser, UCB Number, the unallocated cylinders and tracks and the total tracks on the volume can be extracted using appropriate conversion functions
* From the total tracks on the volume one can derive the total cylinders used with the following formula:
* From the size of SMF19TRK it can also be concluded to which DASD Model the volume belongs. The variable dasd_model is filled in the appropriate select statement.
* Knowing that a 3390 device contains 849960 bytes per cylinder the total gigabytes of the volume can be obtained with the formula:
* The following translate function in the REXX is used to mask the decimal point with a comma. REXX needs to compute with decimal points but the output dataset should contain a comma instead because of the spreadsheet number format in many countries.
* The GB free and GB allocated of the volume can be derived from these formulas:
* Here we finish the record processing, increment the counter j by 1, write all native and derived values into the stem. variable dasd_out.j and increment the counter count by 1.
* After processing the last record the value of count is written to dasd_out.0 and the report header line is written to dasd_out.1.
* With "Execio * Diskw OUTDS (finis stem dasd_out." the whole report is then written to the output dataset defined for OUTDS.
← Preface · SMF Type 19 Direct Access Volume →