Reformatting with fixed fields


This topic describes how the records with fixed fields/fixed length reformatted. Reformat records can be done in data sets by using the INREC, OUTREC and OUTFIL control statements.

INREC, OUTREC, and OUTFIL control statements can be used separately or together.

Using INREC, OUTREC, and OUTFIL while sorting, copying, or merging the below list of tasks can be performed -

  • Delete fields.
  • Reorder fields.
  • Insert separators like blanks, zeros, strings, current date, future date, past date, and current time.
  • Translate data from uppercase to lowercase, lowercase to uppercase, EBCDIC toASCII and ASCII to EBCDIC.
  • Translate data to hexadecimal and bit representation.
  • Convert date fields from one data type to another data type.
  • Convert numeric values to different types which also printable with or without thousands separators, decimal point, leading or suppressed zeros and signs.
  • Convert numeric values from one format to another format.
  • Perform arithmetic operations using numeric values and decimal constants.
  • Perform arithmetic operations on date fields.
  • Change values using a lookup table.
  • Replace or remove data using find and replace operations.
  • Insert sequence numbers.
  • Left-justify data, right-justify data, left-squeeze data, and right-squeeze data.
  • Perform various operations on groups of records.

The INREC, OUTREC, and OUTFIL statements perform almost all same functions. The INREC statement reformats records before they are sorted, copied or merged.

The OUTREC statement reformats records after they are sorted, copied or merged.

The OUTFIL statement can reformat records after they are sorted, copied or merged for OUTFIL output data sets. Different reformatting parameters can be used for different OUTFIL data sets.

Reformat records can be done in one of the following ways -

  • BUILD - Reformat each record by specifying all of its items one by one. Build gives full control over the items that required in reformatted records and the order in which they appear.
    User can delete, rearrange and insert fields and constants by using BUILD.
  • OVERLAY - Reformat each record by specifying the items that overlay specific columns.
  • FINDREP - Reformat each record by doing various types of finds and replace operations.
  • IFTHEN clauses - Reformat different records in different ways. Reformat records by specifying how to build, overlay, find/replace, or group operation items.

    Note! For INREC and OUTREC, either the BUILD parameter or theFIELDS parameter can be used. For OUTFIL, either the BUILD parameter or the OUTREC parameter can be used.
  • Reformatting records after sorting with BUILD or FIELDS - The fields which are not needed can be deleted by using the FIELDS or BUILD parameter of the OUTREC statement.

Syntax -


OUTREC FIELDS=(starting position of field1, length of field1,….. )
Starting position of field1Field1 starting position in the input file after sorting.
Length of feild1Field1 physical length in input file.

Example -


Scenario - Ignore the std-dept from the input and the std-marks to be copied in the place of dept. The new output record layout would be -

01 OUTPUT-REC.
  	05 STD-ID			PIC X(05).
	05 FILLER			PIC X(05).
	05 STD-NAME			PIC X(15).
	05 FILLER			PIC X(03).
	05 STD-MARKS		PIC 9(03).    
	05 FILLER			PIC X(49).

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* 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 ********************************

Input Record Layout -

01 INPUT-REC.
  	05 STD-ID			PIC X(05).
	05 FILLER			PIC X(05).
	05 STD-NAME			PIC X(15).
	05 FILLER			PIC X(05).
	05 STD-DEPT	 		PIC X(10).
	05 FILLER			PIC X(05).
	05 STD-MARKS		PIC 9(03).    
	05 FILLER			PIC X(32).

Job -

//Job-card 
//**********************************************************************
//* SORT FOR OUTREC STATEMENT                                           
//**********************************************************************
//STEP01   EXEC PGM=SORT                                                
//SORTIN   DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR                    
//SORTOUT  DD SYSOUT=*                                                  
//SYSOUT   DD SYSOUT=*                                                  
//SYSIN    DD *                                                         
     OPTION COPY                                                        
     OUTREC FIELDS=(1,28,45,3)                                          
/*                                                                      
**************************** Bottom of Data ****************************

Output -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
00001     student1          560                                                 
00003     student3          520                                                 
00004     student4          540                                                 
00005     student5          500                                                 
00002     student2          510                                                 
******************************** BOTTOM OF DATA ********************************

Explaining Example -

  1. Output file has been formed up with 1 to 28 bytes and 45 to 48 bytes from the input file.
  2. Those two are added adjacent in the output file as 1 to 32 bytes(1 to 29, 30 to 32).