Why use a template?

Typically, data sets containing application data have a well-defined structure, where each record in the data set consists of several fields. Each field contains a discrete item of data, such as a person's name, a product code or a currency amount (depending on the application). This data can be of various types: some fields contain character data, others contain numeric data (perhaps encoded in binary format to conserve storage space).

To work efficiently with these data sets, you need tools that recognize record structure, allowing you to selectively process individual fields.

For example, if you use a text editor (such as the ISPF editor) to display an application data set, then each record appears as a string of characters, with no indication that the records consist of individual fields. Fields containing numeric data encoded in binary or packed decimal format are represented by their (typically “non-displayable”) character values, rather than their numeric values.

Even if you know the column boundaries of each field, editing an application data set in a text editor can be difficult and tedious:
  • If you want to find and replace data in a specific field, then you have to be careful not to change the field length; otherwise, you could move the boundaries of subsequent fields, and corrupt the record structure.
  • If you want to find and replace data in numeric fields where the data has been encoded in binary or packed decimal format, then you have to specify the find and replace values in that format (typically, as hexadecimal values), rather than as numeric values.
  • If the file you are editing contains several record types (each with its own structure), and you only want to find and replace data in one record type, then you have to exclude other record types from editing.

To illustrate, here are some records containing a mixture of alphanumeric and numeric fields displayed in the ISPF editor:

 EDIT       USERID.FMDATA(DATA2) - 00.02                    Columns 00001 00072
 000013 01Grant Smith              Í
 000014 01Andrew Apple         5   Ì&
 000015 01Graham Prestcott     õ   ç

The Grant Smith record contains the numeric value “94”, stored in a binary numeric field. To change this from 94 to 48, without using a template, you would need to:

  1. Display the hexadecimal values of the record data.
  2. Determine the column positions occupied by the field.
  3. Convert the numeric value 48 into its hexadecimal equivalent (X'30').
  4. Overtype the old hexadecimal value of the numeric field (X'5E') with the new value, or use a CHANGE command with the old and new hexadecimal values.

Here is the same record displayed in the File Manager editor using a template:

REC-TYPE NAME                 EMPLOYEE-NO     AGE   SALARY  MONTH(1)  MONTH(2)
#2       #3                            #4      #5       #6        #7        #7
AN 1:2   AN 3:20                  BI 23:2 BI 25:2  PD 27:4   BI 31:4   BI 35:4
<>       <---+----1----+---->     <---+-> <---+-> <---+--> <---+---> <---+--->
01       Grant Smith                 7712      94    75000         6        15

To change the value of the AGE binary numeric field from 94 to 48, you can simply overtype 94 with 48, or enter the following command (where #5 is the “field reference” for the AGE field):

CHANGE 94 48 #5

Another situation in which you might want to use a template is when you are copying data. When you use a copy utility that does not recognize record structure, you are often limited to copying an entire data set, or a number of records. If you want to copy only records with particular field values, or only particular fields, then you must write a custom program.

When using templates with File Manager, you can specify criteria to select only the records you want to copy, and to select the fields you want from the list of fields in the record.