OUTREC: Data Conversion

  • OUTREC used to convert the numeric fields from one type to another type.

Syntax -

OUTREC FIELDS=(starting position of field1, length of field1,
		field1 source format, TO=field1 target format,LENGTH=n,….. )
Starting position of field1Specifies field1 starting position in the input file after sorting.
Length of feild1 Field1 physical length in input file.
Field1 Source format Specifies the field1 source format
TO=field1 target formatSpecifies the field1 target format
n Specifies the field1 target format length

The below are the list of numeric formats -

  • BI format for the field if want to test for binary format(‘0’, ‘1’ every bit).
  • FS format for the field if want to test for character numeric ('0'-'9' inevery byte).
  • ZD format for the field if want to test for zoned decimal numeric ('0'-'9'in all non-sign bytes; X'F0'-X'F9', X'D0'-X'D9' or X'C0'-X'C9' in the sign byte).
  • PD format for the field if want to test for packed decimal numeric (0-9for all digits; F, D or C for the sign).

Example -

Scenario - Convert the first five byte ZD to FS in the input file.

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

********************************* Top of Data **********************************
00001     student1           dept1          560                                 
00003     student3           dept2          520                                 
00004     student4           dept1          540                                 
00005     student5           dept2          500                                 
00002     student2           dept3          510                                 
******************************** Bottom of Data ********************************


***************************** Top of Data ******************************
//* SORT FOR OUTREC STATEMENT                                           
//STEP01   EXEC PGM=SORT                                                
//SORTOUT  DD SYSOUT=*                                                  
//SYSOUT   DD SYSOUT=*                                                  
//SYSIN    DD *                                                         
     SORT FIELDS=(1,5,CH,A)                                             
     OUTREC FIELDS=(1,5,ZD,TO=FS,LENGTH=6,X,6,73)                       
**************************** Bottom of Data ****************************

Output -

********************************* TOP OF DATA **********************************
     1      student1           dept1          560                               
     2      student2           dept3          510                               
     3      student3           dept2          520                               
     4      student4           dept1          540                               
     5      student5           dept2          500                               
******************************** BOTTOM OF DATA ********************************

Explaining Example -

  1. OUTREC FIELDS=(1,5,ZD,TO=FS,LENGTH=6,..) converts the first five bytes ZD from input file to FS of 6 bytes and writes it to output.
  2. 7th byte will be placed as a space in output file.
  3. OUTREC FIELDS=(..,6,73) copies the input file data from 6th byte to the output file from 8th byte onwards as it is.