Module 8: JCL Sort & Merge
OUTREC FILEDS or OUTREC BUILD
It is used to reformat each record by specifying all of its items one by one. BUILD gives you complete control over the items you want in your reformatted OUTREC records and the order in which they appear.
Syntax for using FIELDS parameter in its simplest form:-
OUTREC [FIELDS|BUILD] = (C:P,M,...)
Where,
C ==> indicates the position in output field
P ==> indicates the position of input field
M ==> indicates length of input field
Let’s understand with help of exampleS:-
Example 1:-
Input file:-
Requirement: To copy all the records from input file to output file. However, while writing to output file only fields EMP-NAME (I/P file POSITION 6-25) and EMP-SALARY (I/P file POSITION 46-50) should be written to it
JCL Code:-
Output file:
Explanation:
- Statement ‘SORT FIELDS=COPY’ is coded to specify that all records should be copied from input file to output file.
- Statement ‘OUTREC FIELDS=(1:6,25,26:46,5)‘ is coded to specify that field at position (6 to 30 i.e. length is 25) should be copied at position ‘1’ in output file followed by the field at position (46 to 50 i.es length is 5) should be copied at position 26 of output file. Thus total record length of output file is 30.
Example 2:-
Input file:-
Requirement: To sort input file based on employee name and then while writing output records all records should be appended with sequence number
JCL Code:
Output file:
Explanation:-
- Statement SORT FIELDS=COPY, is used here to indicate that all records should be copied from input file to output file
- Statement OUTREC FIELDS=(1:1,30,36:SEQNUM,5,ZD), is used here to indicate that field at position (1 to 30 i.e. length = 30) should be copied at position ‘1’ in output file followed by the sequence number of 5 digit in Zoned Decimal format should be written at position 36 of output file. Thus total record length of output file is 40.
INSERTING SPACE, ZEROES or CHARACTER String to your output
Requirement 1: Copy input file to output file as it is just add two spaces after writing first field of length (1-5)
SYSIN Control card - Solution:
Explnation: In above case all records will be copied from input file to output file. However while writing to output file, two spaces will be added between fields at position 1-5 and 6-10. 2X in OUTREC FILEDS statement indicates two spaces and thus record length of output file will be 12.
Requirement 2: Copy input file to output file as it is, however, while writing output records, copy field at position 1-20 from input file followed by string ' TOTAL ' followed by 5 zeroes followed by field at position 21-30 from input file.
SYSIN Control card - Solution 1:
SYSIN Control card - Solution 2:
To display hexadecimal representation of input value
Requirement: To display hexadecimal representation of input value.
SYSIN Control card - Solution:
Explnation: Above statement will convert data at field at position (1-10) of input file to Hexa-decimal representation and write it to output file. Since hexadecimal representation occupies two digits for each character, here we will need output file with record length of 20
To covert the input data from lower case to upper case.
TRAN=LTOU, can be used to convert data from lower case to upper case TRAN=UTOL, can be used to convert data from upper case to lower case
Requirement: To convert field at position 1-20 of input file to Upper case characters.
SYSIN Control card - Solution:
Explnation: Above statement will convert data at field at position (1-20) of input file to its uppercase form and write it to output file.
To perform lookup of input data and if it matches then replace it with some other data.
It will be helpful in case where days of week coded as MON, TUE, WED… which needs to be replaced to MONDAY, TUESDAY, WEDNESDAY
Requirement: To replace three char days of week to its fullest form
Input file
JCL Code - Solution:
Output file:
Explnation:
- Statement ‘SORT FIELDS=COPY’ is used here to indicate that all records will be copied from input file to output file.
- OUTREC statement used above will copy first 10 bytes from input file & convert all letters to lowercase letters. In addition to this it will replace 3 letter day-of-week name at position 11 in input file with its full name at position 11. Example MON will be replaced by MONDAY. ‘CHANGE=(10’ indicates that replacing string will occupy 10 letter positions. Data at position 11 in put file will be compared with CHANGE list. If any match found in the list respective data will be moved to output file. If there is no match found ‘NOMATCH=(11,3)’ , data at 11th position of input file will be copied as it is to output file.