TSO-ISPF JCL COBOL VSAM DB2 CICS IMS-DB Tools Articles Forum Quiz Interview Q&A

JCL - SORT INREC Fields


The INREC control statement allows you to reformat the input records before they are sorted, merged, or copied.

You can create the reformatted INREC records in one of the following ways using unedited, edited, or converted input fields.

BUILD or FIELDS:

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 INREC records and the order in which they appear. You can delete, rearrange and insert fields and constants. Example:

INREC BUILD=(1,20,C'ABC',26:5C'*',
        15,3,PD,EDIT=(TTT.TT),21,30,80:X)

OVERLAY:

Reformat each record by specifying just the items that overlay specific columns. Overlay lets you change specific existing columns without affecting the entire record. Example:

INREC OVERLAY=(45:45,8,TRAN=LTOU)

FINDREP:

Reformat each record by doing various types of find and replace operations. Example:

INREC FINDREP=(IN=C'Mr.',OUT=C'Mister')

IFTHEN clauses:

Reformat different records in different ways by specifying how build, overlay, find/replace, or group operation items are applied to records that meet given criteria. IFTHEN clauses let you use sophisticated conditional logic to choose how different record types are reformatted. Example:

INREC IFTHEN=(WHEN=(1,5,CH,EQ,C'TYPE1'),
           BUILD=(1,40,C'**',+1,TO=PD)),
        IFTHEN=(WHEN=(1,5,CH,EQ,C'TYPE2'),
           BUILD=(1,40,+2,TO=PD,X'FFFF')),
        IFTHEN=(WHEN=NONE,OVERLAY=(45:C'NONE'))

PARSE:

PARSE can be used for many different types of variable fields including delimited fields, comma separated values (CSV), tab separated values, blank separated values, keyword separated fields, null-terminated strings, and so on. You can assign up to 1000 parsed fields (%0-%999) to the variable fields you want to extract.

Note that if all of the fields in your records have fixed positions and lengths, you don't need to use PARSE. But if any of the fields in your records have variable positions or lengths, you can use PARSE to treat them as fixed parsed fields in BUILD or OVERLAY. You can mix p,m fields (fixed fields) and %nn fields (parsed fields) in BUILD and OVERLAY.

INREC PARSE=(%00=(ENDBEFR=C'*',FIXLEN=3),
      %01=(ENDBEFR=BLANKS,FIXLEN=6),
      %02=(STARTAT=C'MAX',FIXLEN=8),
      %03=(STARTAFT=C'(',ENDBEFR=C')',FIXLEN=6),
      %04=(STARTAFT=BLANKS,FIXLEN=5)),
    BUILD=(%03,X,%03,HEX,21:%02,31:%01,SFF,M26,LENGTH=7,
           18,6,%00,UFF,M11,LENGTH=3,%04,JFY=(SHIFT=RIGHT))

Default for PARSE: None; must be specified.


Example 1: Formating a file(USING INREC)

//SYSIN DD *
  SORT FIELDS=COPY
  INREC FIELDS=(7:2,5,20:10,3)
/*

Explanation:

SORT FIELDS=COPY It is for copy records to output file

INREC FIELDS=(7:2,5,20:10,3) - Here we have two formattings,

  1. 7:2,5 - data at 2nd position of input file with length 5 copied to 7th position of output file

  2. 20:10,3 - data at 10th position of input file with length 3 copied to 20th position of output file


Example 2: Generate the sequence numbers to identify the record position before sorting using INREC.

INPUT FILE:

1234567890123456789012345678901234567890 ---> Column
001 studentname1        class1
003 studentname3        class2
004 studentname4        class1
005 studentname5        class2
002 studentname2        class3

SORT JCL:

//STEP01   EXEC PGM=SORT
//SORTIN   DD DSN=userid.SORT.INPUT,DISP=SHR
//SORTOUT  DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
   SORT FIELDS=(1,3,ZD,A)
   INREC FIELDS=(1,20,X,25,6,X,SEQNUM,4,ZD)
/*

OUTPUT FILE:

1234567890123456789012345678901234567890 ---> Column
001 studentname1     class1 0001
002 studentname2     class3 0005
003 studentname3     class2 0002
004 studentname4     class1 0003
005 studentname5     class2 0004

Explanation:

  1. INREC FIELDS=(1,20,X,25,6,X,...) - Reformat the input file of length 1 to 30 bytes(1 to 20 bytes plus 25 to 6 bytes). X represents single space.

  2. INREC FIELDS=(..,SEQNUM,4,ZD) - Generate the sequence number from 29th byte of length 4.

  3. SORT FIELDS=(1,3,ZD,A) - Once the above two tasks done, the file will sorted and the same writes to output after sorting.



If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal