Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

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:-

----+----1----+----2----+----3----+----4----+----5 88888JOHN PURCHASING 08000 11111AKSHAY HR 10000 55555SMITH R&D 25000 99999JOHN ADMIN 28000

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:-

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.INPUT,DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT1, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=30,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTREC FIELDS=(1:6,25,26:46,5) /*

Output file:

----+----1----+----2----+----3 JOHN 08000 AKSHAY 10000 SMITH 25000 JOHN 28000

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:-

----+----1----+----2----+----3 JOHN 08000 AKSHAY 10000 SMITH 25000 JOHN 28000

Requirement: To copy all records and while writing output records, all records should be appended with sequence number

JCL Code:

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.OUTPUT1,DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT2, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=40,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTREC FIELDS=(1:1,30,36:SEQNUM,5,ZD) /*

Output file:

----+----1----+----2----+----3----+----4 JOHN 08000 00001 AKSHAY 10000 00002 SMITH 25000 00003 JOHN 28000 00004

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:

SORT FIELDS=COPY OUTREC FIELDS=(1,5,2X,6,10)

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:

SORT FIELDS=COPY OUTREC FIELDS= (1:1,20,C’TOTAL’,26:5Z,31:21,10)

SYSIN Control card - Solution 2:

SORT FIELDS=COPY OUTREC FIELDS= (1,20,C’TOTAL’,5Z,21,10)

To display hexadecimal representation of input value

Requirement: To display hexadecimal representation of input value.

SYSIN Control card - Solution:

OUTREC BUILD=(1,10,HEX)

Explnation: Above statement will convert data 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:

OUTREC BUILD=(1,20,LTOU)

Explnation: Above statement will convert data 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

----+----1----+----2----+----3 JOHN MON 08000 AKSHAY TUE 10000 SMITH WED 25000 JOHN THU 28000 STEVE MON 20000 VIJAY XXX 24000 VIJAY SUN 30000

JCL Code - Solution:

//SORTSTEP EXEC PGM=SORT //SORTIN DD DSN=DEPT.EMPL.DATA.OUTPUT1,DISP=SHR //SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT2, // DISP=(,CATLG,DELETE), // DCB=(RECFM=FB,LRECL=30,BLKSIZE=0), // UNIT=TEST,SPACE=(CYL,(50,10),RLSE) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD * SORT FIELDS=COPY OUTREC BUILD=(1,10,TRAN=UTOL,11,3, - CHANGE=(10, - C'SUN',C'SUNDAY', - C'MON',C'MONDAY', - C'TUE',C'TUESDAY', - C'WED',C'WEDNESDAY', - C'THU',C'THURSDAY', - C'FRI',C'FRIDAY', - C'SAT',C'SATURDAY'), - NOMATCH=(11,3), - 21,10) /*

Output file:

----+----1----+----2----+----3 john MONDAY 08000 akshay TUESDAY 10000 smith WEDNESDAY 25000 john THURSDAY 28000 steve MONDAY 20000 vijay XXX 24000 vijay SUNDAY 30000

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 input 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.



Advertisements






© copyright mainframebug.com
Privacy Policy