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

JCL - SORT OUTREC Fields


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

You can create the reformatted OUTREC 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 OUTREC 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 OUTREC)

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=COPY
  OUTREC FIELDS=(1,20,25,6)
/*

OUTPUT FILE:

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

Explanation:

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

OUTREC FIELDS=(1,20,25,6,) - Here we have two formattings,

  1. 1,20 - data at 1st position of input file with length 20 copied to 1st position(if you don't specific position, it will start from 1st position) of output file.

  2. 25,6 - data at 25th position of input file with length 6 copied to 21st position(because 1 to 20 already data copied so it will continue from next position) of output file.


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