OUTREC Justifying Data


  • OUTREC statement can be used to justify the content in the file while sorting.

Syntax-1 -


OPTION COPY
OUTREC FIELDS=(Starting position of field1, Length of field1,
	JFY=(SHIFT=LEFT/RIGHT,LEAD=charset,TRAIL=charset),…)
Starting position of field1Specifies field1 starting position in the input file after sorting.
Length of feild1Field1 physical length in input file.
SHIFTSpecifies the justification

SHIFT=LEFT indicates that you want to left-justify
SHIFT=RIGHT indicates that you want to right-justify
LEAD=charsetSpecifies the leading characters/string adding to data
TRAIL=CharsetSpecifies the trailing characters/strings adding to data

Syntax-2 -


OPTION COPY
OUTREC FIELDS=(Starting position of field1, Length of field1,
	JFY=(SHIFT=LEFT/RIGHT, PREBLANK=charset),…)
Starting position of field1Specifies field1 starting position in the input file after sorting.
Length of feild1Field1 physical length in input file.
SHIFTSpecifies the justification

SHIFT=LEFT indicates that you want to left-justify
SHIFT=RIGHT indicates that you want to right-justify
PREBLANK=charsetSpecifies the characters that replaced or blank out as leading and trailing to data
PREBLANK=list specifies a list of characters to replace with blanksbefore DFSORT starts to justify the data.
The list can be specified as a character orhexadecimal constant (1 to 10 bytes).
Note! The each character in the list isindependent of the other characters.

Syntax-3 -


OPTION COPY
OUTREC FIELDS=(Starting position of field1, Length of field1,
	JFY=(SHIFT=LEFT/RIGHT, 
	PREBLANK=charset,LEAD=charset,TRAIL=charset),…)

Example -


Scenario - Align the data in first 29 bytes to LEFT and replace () with <>.

Input File - MTHUSER.SORT.INPUT01 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
  (student1)                 dept1          560       01012015                  
     (student2)              dept2          520       03032015                  
          (student3)         dept1          540       06022015                  
(student4)                   dept2          500       09202015                  
       (student5)            dept3          510       05182015                  
******************************** Bottom of Data ********************************

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card 
//**********************************************************************
//* SORT FOR OUTREC STATEMENT                                           
//**********************************************************************
//STEP01   EXEC PGM=SORT                                                
//SORTIN   DD DSN=MTHUSER.SORT.INPUT03,DISP=SHR                    
//SORTOUT  DD SYSOUT=*                                                  
//SYSOUT   DD SYSOUT=*                                                  
//SYSIN    DD *                                                         
     OPTION COPY                                                        
     OUTREC FIELDS=(1,29,JFY=(SHIFT=LEFT,PREBLANK=C'()',                
                    LEAD=C'<',TRAIL=C'>'),30,30)                        
/*                                                                      
**************************** Bottom of Data ****************************

Output -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
<student1>                   dept1          560       01012                     
<student2>                   dept2          520       03032                     
<student3>                   dept1          540       06022                     
<student4>                   dept2          500       09202                     
<student5>                   dept3          510       05182                     
******************************** BOTTOM OF DATA ********************************

Explaining Example -

  1. OUTREC FIELDS=(1,29,JFY=(SHIFT=LEFT,..),..) - Justifies the data in the first 29 bytes to left.
  2. OUTREC FIELDS=(1,29,JFY=(..,PREBLANK=C'()',..),..) - blank out the ().
  3. OUTREC FIELDS=(1,29,JFY=(.., LEAD=C'<',TRAIL=C'>'),..) - adds the C’<’ as a lead and C’>’ as a trail.
  4. OUTREC FIELDS=(..,30,30) - Copies the input file data from 30th byte of length 30 copies to output as it is.