INREC

The INREC control statements allow users to reformat an input record before processing. The user can 

  • Define the parts of an input record to be included in the reformatted input record. 
  • Denote the order they are to appear.
  • How they are to be aligned.
  • Insert blanks and binary zeros as separators before, between, and after the fields in the reformatted input records.

The reformatted input record Consists only of the user-specified fields in the order denoted, and are aligned on the boundaries or in the columns indicated.

INREC Explanation

You can create the reformatted INREC records in one of the following ways using unedited, edited, or converted input fields and a variety of constants:

  • BUILD: 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)
  1. LTOU operand can be used to change lower-case EBCDIC letters (a-z) to upper-case EBCDIC letters (A-Z) anywhere in a field.
  2. UTOL operand can be used to change upper-case EBCDIC letters to lower-case  EBCDIC letters anywhere in a field.
  • FINDREP: Reformat each record by doing various types of find and replace operations. Example:  
INREC FINDREP=(IN=C’Mr.',OUT=C'Mister')
  • IFTHEN: Reformat different records in different ways by specifying how to 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'))

INREC Notes

  • In general, OUTREC should be used rather than INREC so your SORT and SUM statements can refer to fields in the original input records.
  • If you use locale processing for SORT, MERGE, INCLUDE, or OMIT fields, you must not use INREC. Use the OUTREC statement or the OUTFIL statement instead of INREC.
  • When you specify INREC, you must be aware of the change in record size and layout of the resulting reformatted input records.
  • Performance can be improved if you can significantly reduce the length of your records with INREC. INREC and OUTREC should not be used unless they are actually needed to reformat your records.
  • For variable-length records, the first entry in the FIELDS, BUILD, or IFTHEN BUILD parameter must specify or include the unedited 4-byte record descriptor word (RDW), that is, the first field must be 1,4 or 1,m with m greater than 4. DFSORT sets the length of the reformatted record in the RDW. If the first field in the data portion of the input record is to appear unedited in the reformatted record immediately following the RDW, the entry in the FIELDS, BUILD, or IFTHEN BUILD parameter can specify both RDW and data field in one (1,m,…). Otherwise, the RDW must be specifically included in the reformatted record (for example, 1,4,1,4,HEX).
  • For variable-length records, OVERLAY, IFTHEN OVERLAY or IFTHEN PUSH items must not overlay the RDW in bytes 1-4. You must ensure that 1:, 2:, 3: or 4: is not specified or defaulted for any OVERLAY or PUSH item. Note that the default for the first OVERLAY or PUSH item is 1:, so you must override it.
  • If the SORTOUT LRECL is specified or available, DFSORT will use it even if it does not match the reformatted INREC record length; this can cause padding or truncation of the reformatted INREC records, or termination. If the SORTOUT LRECL is not specified or available, DFSORT can automatically use the reformatted INREC record length as the SORTOUT LRECL, when appropriate. See the discussion of the SOLRF and NOSOLRF options in OPTION control statement.For VSAM data sets, the maximum record size defined in the cluster is equivalent to the LRECL when processing fixed-length records, and is four bytes less than the LRECL when processing variable-length records.
  • With FIELDS, BUILD, or IFTHEN BUILD, the variable part of the input record (that part beyond the minimum record length) can be included in the reformatted record, and if included, must be the last part. In this case, a value must be specified for pn that is less than or equal to the minimum record length (see L4 of the RECORD control statement) plus 1 byte; mn and an must be omitted. For example: INREC FIELDS=(1,8,20C’*’,9)
    With OVERLAY, the variable part of the input record must not be included in the reformatted record.
  • If INREC with FIELDS or BUILD and OUTREC with FIELDS and BUILD are specified, either both must specify position-only for the last part, or neither must specify position-only for the last part. For example:  
     INREC BUILD=(1,8,20C'*',9)
     OUTREC BUILD=(1,4,3Z,5)
     or
     INREC FIELDS=(1,40,45,5)    
     OUTREC FIELDS=(1,45,C'****')

OVERLAY or IFTHEN, and FIELDS or BUILD, can differ with respect to position-only. For example:   

    INREC BUILD=(1,24,32:25)
    OUTREC IFTHEN=(WHEN=(8,1,ZD,GT,+5),
    BUILD=(1,24,25:C'Yes',28,10)),
    IFTHEN=(WHEN=NONE,BUILD=(1,24,25:C'No ',28,10))
    or:   
    INREC FIELDS=(1,18,8C'*',23)
    OUTREC OVERLAY=(24:C'A')
  • If the reformatted record includes only the RDW and the variable part of the input record, “null” records containing only an RDW could result.
  • The input records are reformatted before processing, as specified by INREC. The output records are in the format specified by INREC, unless OUTREC is also specified.
  • Fields referenced in INREC statements can overlap each other and control fields or both.
  • If input is variable records, the output is also variable. This means that each record is given the correct RDW by DFSORT before output.
  • If overflow might occur during summation, INREC can be used to create a larger SUM field in the reformatted input record (perhaps resulting in a larger record for sorting or merging) so that overflow does not occur.
  • DFSORT issues a message and terminates if an INREC statement is specified for a tape work data set sort or conventional merge application.
  • If SZERO is in effect, -0 is treated as negative and +0 is treated as positive for edited or converted input fields, decimal constants, and the results of arithmetic expressions. If NOSZERO is in effect, -0 and +0 are treated as positive for edited or converted input fields, decimal constants, and the results of arithmetic expressions.
  • If SZERO is in effect, -0 compares as less than +0 when numeric fields and constants are used. If NOSZERO is in effect, -0 compares as equal to +0 when numeric fields and constants are used.Note: OPTION SZERO or OPTION NOSZERO is ignored for INREC IFTHEN=(WHEN=(logexp),…) unless the OPTION statement is found in a higher source (for example, DFSPARM is a higher source than SYSIN) or before the INREC statement in the same source. For example, NOSZERO will be used in both of the following cases:

Example 1: 

 //DFSPARM DD *
   OPTION COPY,NOSZERO
 /*
 //SYSIN DD *
   INREC IFTHEN=(WHEN=(1,2,FS,EQ,+0),OVERLAY=(22:C'Yes')),
         IFTHEN=(WHEN=NONE,OVERLAY=(22:C'No '))
 /*

Example 2: 

 //SYSIN DD *
   OPTION COPY,NOSZERO
   INREC IFTHEN=(WHEN=(1,2,FS,EQ,+0),OVERLAY=(28:C'A')),
         IFTHEN=(WHEN=NONE,OVERLAY=(28:C'B'))
 /*

INREC statement with Examples

Example 1

In this example, three fixed-length input files are sorted and reformatted for output. Unnecessary fields are eliminated from the output records.

The input record size is 80 bytes, with three records per block. The INCLUDE control statement includes or excludes records while the SUM control statement sums them. Reformatted input records are fixed-length; record size is 23 bytes.

 INCLUDE COND=(5,1,GE,C'M'),FORMAT=CH
 INREC FIELDS=(10,3,20,8,33,11,5,1)
 SORT FIELDS=(4,8,CH,A,1,3,FI,A),WORK=1,FILES=3 
 SUM FIELDS=(17,4,BI)
 RECORD TYPE=F,LENGTH=80
 INPFIL BLKSIZE=240
 OUTFIL BLKSIZE=230

Output: 

  • 1–3 position input positions 10 through 12. 
  • 4–11 position input positions 20 through 27. 
  • 12–22 position input positions 33 through 43. 
  • 23 position input position 5.

For INREC, the INCLUDE COND operands must refer to the fields of the original input records: The OUTFIL indicates the 23-byte records are written as ten records per block in the output file.

  INCLUDE COND=(5,1,GE,C'M'),FORMAT=CH
  OUTREC FIELDS=(10,3,20,8,33,11,5,1)
  SORT FIELDS=(20,8,CH,A,10,3,FI,A)
  SUM FIELDS=(38,4,BI)

Identical results are achieved with INREC or OUTREC. However, the use of OUTREC makes it easier to code the SORT and SUM statements. In either case, the INCLUDE COND parameters must refer to the fields of the original input records. However, with INREC, the SUM, and SORT FIELDS parameters must refer to the fields of the reformatted input records, while with OUTREC, the SUM and SORT FIELDS parameters must refer to the fields of the original input records.

Example 2

This example shows how the overflow of a summary field can be prevented when three fixed-length files are sorted and reformatted for output. The input record size is 80 bytes.

 INREC FIELDS=(1,35,2Z,36,45)
 SORT FIELDS=(20,4,CH,D,10,3,CH,D),WORK=1,FILES=3 
 SUM FIELDS=(36,4,BI,40,8,PD)
 RECORD TYPE=F,LENGTH=80
 INPFIL BLKSIZE=240
 OUTFIL BLKSIZE=246

Output:

  • 1–35 position contains input positions 1 through 35.
  • 36–37 position contains binary zeros; used to prevent overflow.
  • 38–82 position contains input positions 36 through 80.

SORT and SUM statements must refer to fields of the reformatted input records.

Reformatted output records are identical to reformatted input records.

To prevent overflow of the summary field, the two-byte summary field at positions 36 and 37 in the original input records expands to a four-byte summary field in positions 36 through 39 of the reformatted input/output record before sorting.

The OUTFIL maintains the three records per block but with a record length of 82 instead of 80.

Note: Do not use this method with negative FI summary fields as padding with zeros rather than ones changes the sign.

Example 3

This example illustrates how the overflow of a summary field can be prevented when three fixed-length data sets are merged and reformatted for output. The input record size is 80 bytes. To illustrate the use of the RECORD statement, assume that SORTIN and SORTOUT are not present (that is, all input/output is handled by user exits).

  INREC FIELDS=(1,35,2Z,36,45)
  MERGE FIELDS=(20,4,CH,D,10,3,CH,D),FILES=3
  SUM FIELDS=(36,4,BI,40,8,PD)
  RECORD TYPE=F,LENGTH=(80,,82)

The reformatted input records are fixed-length with a record size of 82 bytes (an insignificant increase from the original size of 80 bytes). They look as follows:

  • 1-35       Input positions 1 through 35
  • 36-37    Binary zeros (to prevent overflow)
  • 38-82    Input positions 36 through 80

The MERGE and SUM statements must refer to the fields of the reformatted input records. The reformatted output records are identical to the reformatted input records.

Thus, the 2-byte summary field at positions 36 and 37 in the original input records expands to a 4-byte summary field in positions 36 through 39 of the reformatted input/output record before merging. This prevents overflow of this summary field.

Restriction: If OUTREC were used instead of INREC, the records would be reformatted after merging, and the 2-byte summary field might overflow.

Example 4

This example illustrates how a fixed-length input data set can be sorted and reformatted for output. A more efficient sort is achieved by using INREC before sorting to reduce the input records as much as possible, and using OUTREC after sorting to add padding, the current date, and repeated fields. The SORTIN LRECL is 80 bytes.

   INREC BUILD=(20,4,12,3)
   SORT FIELDS=(1,4,D,5,3,D),FORMAT=CH
   OUTREC BUILD=(5X,1,4,H,19:1,2,5,3,DATE1(-),80X'FF')

The reformatted input records are fixed-length and have a record size of seven bytes (a significant reduction from the original size of 80 bytes). They look as follows:

  • 1-4       Input positions 20 through 23
  • 5-7       Input positions 12 through 14

The SORT and OUTREC statements must refer to the fields of the reformatted input records.

The reformatted output records are fixed lengths with a record size of 113 bytes. SOLRF (the IBM-supplied default) is in effect, so unless the SORTOUT LRECL is specified or available, it will automatically be set to the reformatted record length of 113. The reformatted output records look as follows:

  • 1-5         EBCDIC blanks
  • 6            Binary zero (for H alignment)
  • 7-10       Input positions 20 through 23
  • 11-18     EBCDIC blanks
  • 19-20    Input positions 20 through 21
  • 21-23    Input positions 12 through 14
  • 24-33   The current date in the form C’yyyy-mm-dd’
  • 34-113  Hexadecimal FF’s

Thus, the use of INREC and OUTREC allows sorting of 7-byte records rather than 80-byte records, even though the output records are 113 bytes long.

Example 5

This example illustrates how a sequence number can be generated, how values in one numeric or date format can be converted to another format, and how a lookup table can be used.

  OPTION COPY,Y2PAST=1985
  INREC FIELDS=(SEQNUM,4,BI,
                8,5,ZD,TO=PD,
                31,2,PD,TO=FI,LENGTH=2,
                15,6,Y2TP,25,3,
  CHANGE=(1,C'L92',X'01',C'M72',X'02',C'J42',X'03'),
                 NOMATCH=(X’FF'))

The reformatted input records will look as follows:

  • 1-4 position contains a binary sequence number that starts at 1 and increments by 1.
  • 5–7 position contains a PD field containing the converted ZD field from input positions 8 through 12.
  • 8–9 position contains  an FI field containing the converted PD field from input positions 31 through 32.
  • 10–14 position contains a P’yyyymmdd’ date field containing the C’yymmdd’ date field from input positions 15-20 transformed according to the specified century window of 1985-2084.
  • 15 position contains a BI field containing X’01’, X’02’, X’03’ or X’FF’ as determined by using a lookup table for the input field in positions 25-27.

The SORT statement can now refer to the “sort” field in the reformatted input records. The OUTREC statement is used to restore the records to their original format.

Example 6

This example illustrates how you can use the OVERLAY parameter with INREC and OUTREC to change certain columns in your records without affecting other columns.

INREC OVERLAY=(61:21,11,SFF,ADD,41,11,SFF,TO=PD,LENGTH=5)
SORT FIELDS=(61,5,PD,A)
OUTREC OVERLAY=(61:61,5,PD,EDIT=(SIII,IIT.TT),SIGNS=(+,-))
  • Positions 61-65 of the reformatted input records are overlaid with a 5-byte PD value derived from adding the sddd,ddd.dd field at positions 21-31 to the sddd,ddd.dd field at positions 41-51. 
  • The records are then sorted by this 5-byte PD field. 
  • Positions 61-71 of the reformatted output records are overlaid with an sddd,ddd.dd field derived from the 5-byte PD value. 
  • The data before positions 61-71 and after positions 61-71 are not affected

Example 7

This example illustrates how you can use IFTHEN clauses with INREC to reformat different records in different ways. IFOUTLEN=57 is used to set the reformatted record length to 57.

   OPTION COPY
   INREC IFTHEN=(WHEN=(5,2,CH,EQ,C'GP',AND,2,1,BI,EQ,+1),
             BUILD=(1,6,16,20,C'T1',X'0003',1,7,20C'1')),
         IFTHEN=(WHEN=(5,2,CH,EQ,C'GP',AND,2,1,BI,EQ,+2),
            BUILD=(1,6,45,20,C'T2',X'0008',16,7,20C'2')),
         IFTHEN=(WHEN=(5,2,CH,EQ,C'GP',AND,2,1,BI,EQ,+3),
            BUILD=(1,6,31,20,C'T3',X'0005',25,7,20C'3')),
         IFTHEN=(WHEN=NONE,OVERLAY=(27:C'00',X'FFFF')),
    IFOUTLEN=57

Records with ‘GP’ in positions 5-6 and X’01’ in position 2 are reformatted as follows:

  • 1-6 position contains input positions 1-6
  • 7-26 position contains input positions 16-35
  • 27-28 position contains ‘T1’
  • 29-30 position contains X’0003′
  • 31-37 position contains input positions 1-7
  • 38-57 position contains 20 ‘1’s

Records with ‘GP’ in positions 5-6 and X’02’ in position 2 are reformatted as follows:

  • 1-6 position contains input positions 1-6
  • 7-26 position contains input positions 45-64
  • 27-28 position contains ‘T2’
  • 29-30 position contains X’0008′
  • 31-37 position contains input positions 16-22
  • 38-57 position contains 20 ‘2’s

Records with ‘GP’ in positions 5-6 and X’03’ in position 2 are reformatted as follows:

  • 1-6 position contains input positions 1-6
  • 7-26 position contains input positions 31-50
  • 27-28 position contains ‘T3’
  • 29-30 position contains X’0005′
  • 31-37 position contains input positions 25-31
  • 38-57 position contains 20 ‘3’s

Records without ‘GP’ in positions 5-6 or without X’01’, X’02’, or X’03’ in position 2 are reformatted as follows:

  • 1-26 position contains input positions 1-26
  • 27-28 position contains ’00’
  • 29-30 position contains X’FFFF’
  • 31-57 position contains input positions 31-57

Example 8

This example illustrates how you can left-justify characters in an input field so they can be sorted without regard to the leading blanks.

 INREC OVERLAY=(16:1,15,JFY=(SHIFT=LEFT))
 SORT FIELDS=(16,15,CH,A)
 OUTREC BUILD=(1,15)
 
 Input: 
    CARRIE
    VICKY
    FRANK
    SAM
    DAVID
    MARTIN
 
 Output:
    CARRIE
    DAVID
    FRANK
    MARTIN
    SAM
    VICKY

If we wanted the output to contain the sorted left-justified fields, we could use these control statements:

INREC BUILD=(1,15,JFY=(SHIFT=LEFT))
SORT FIELDS=(1,15,CH,A)
 
 Output:
 CARRIE
 DAVID
 FRANK
 MARTIN
 SAM
 VICKY

Example 9

This example illustrates how you can sort FB input records with variable position/length fields, such as comma-separated values.

INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=11),
             %01=(ENDBEFR=C',',FIXLEN=5),
             %02=(FIXLEN=6)),
      OVERLAY=(31:%00,42:%01,47:%02)
SORT FIELDS=(31,11,CH,A,42,5,UFF,A,47,6,SFF,D)
OUTREC BUILD=(1,30)

 Input: 
 Marketing,96218,+27365
 Development,3807,+1275
 Research,7283,+5001
 
 Output:
 Development,3807,+1275
 Marketing,96218,+27365
 Research,7283,+5001

Example 10

This example illustrates how you can sort VB input records with variable position/length fields, such as comma-separated values. This example is very similar to the previous example for FB records, except that with VB records we need to copy the fixed parsed fields after the 4-byte RDW rather than at the end of the records.

 INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=11),
              %01=(ENDBEFR=C',',FIXLEN=5),
              %02=(FIXLEN=6)),
       BUILD=(1,4,5:%00,16:%01,21:%02,27:5)
 SORT FIELDS=(5,11,CH,A,16,5,UFF,A,21,6,SFF,D)
 OUTREC BUILD=(1,4,27)
 
 Input:
 Length|Data
     26|Marketing,96218,+27365
     26|Development,3807,+1275
     23|Research,7283,+5001
 
 Output:
 Length|Data
     26|Development,3807,+1275
     26|Marketing,96218,+27365
     23|Research,7283,+5001

Example 11

This example illustrates how you can remove characters from FB or VB records.

 OPTION COPY
 INREC FINDREP=(IN=(X’00’,X'FF'),OUT=C'')
 
 Input:
 RDW----|Data
 000F0000D1E4D5C500C1D7D9C9D3FF
 00100000C2C5E3E3E800C4C1C9E2E8FF

 Output:
 RDW----|Data
 000D0000D1E4D5C5C1D7D9C9D3
 000E0000C2C5E3E3E8C4C1C9E2E8

Note that the X’00’ and X’FF’ characters have been removed and the RDW length decreased accordingly. For VB input records, FINDREP processing automatically starts at position 5 after the RDW so the X’00’ characters in the RDW are not affected.

Example 12

This example illustrates how you can find a value in FB or VB records and overlay it with a larger value without shifting other bytes in the records.

 OPTION COPY
 INREC FINDREP=(IN=C'BALANCE', 
                OUT=C'BALANCE 1000',SHIFT=NO,DO=1)
 Input:
 CUSTOMER1 10100
 MNTHLY STMT BALANCE 2000
 CUSTOMER2 11100
 
 Output:
 CUSTOMER1 10100
 MNTHLY STMT BALANCE 1000
 CUSTOMER2 11100

Example 13

This example illustrates how you can SORT and INCLUDE groups of FB records depending on a value in the first record of each group. We propagate the value in the first record of the group to every record of the group, SORT and INCLUDE on the value, and then remove it.

INREC IFTHEN=(WHEN=GROUP,BEGIN=(2,4,CH,EQ,C'RPT.'),PUSH=(31:6,8))
OPTION EQUALS
SORT FIELDS=(31,8,CH,A)
OUTFIL INCLUDE=(31,8,CH,EQ,C'FRANK',OR,
                31,8,CH,EQ,C’SRIHARI’),BUILD=(1,30)
 
 Input:
 1RPT.SRIHARI
  LINE  1 FOR REPORT 1
  LINE  2 FOR REPORT 1
  ...
 1RPT.VICKY
  LINE  1 FOR REPORT 2
  LINE  2 FOR REPORT 2
 
 Output:
 1RPT.SRIHARI
  LINE  1 FOR REPORT 1
  LINE  2 FOR REPORT 1
  ...

Example 14

This example illustrates how to convert a mmddyy date to a ccyyddd date and a 3-character weekday string, and how to convert a ccyyddd date to a ccyy/mm/dd date and 1-digit weekday string.

OPTION COPY,Y2PAST=1996                   
INREC BUILD=(1,6,Y2W,TOJUL=Y4T,X,         
             1,6,Y2W,WEEKDAY=CHAR3,X,     
             9,7,Y4T,TOGREG=Y4T(/),X,     
             9,7,Y4T,WEEKDAY=DIGIT1) 
 
 Input:
 120409  1999014
 051895  2003235
 999999  0000000
 013099  1992343

 Output: 
 2009338 FRI 1999/01/14 5
 2095138 WED 2003/08/23 7
 9999999 999 0000/00/00 0
 1999030 SAT 1992/12/08 3 

The Y2PAST=1996 option sets the century window to 1996-2095. The century window is used to transform yy in the Y2W field to ccyy.

Note: Date conversion is not performed for the special indicators (all 9s and all 0s); the special indicator is just used appropriately for the output date field.

Example 15

This example illustrates how you can add and subtract days, months, and years from date fields.

 OPTION COPY                                                
 INREC OVERLAY=(11:1,8,Y4T,ADDDAYS,+50,TOGREG=Y4T,          
                21:1,8,Y4T,SUBMONS,+7,TOGREG=Y4T,            
                31:1,8,Y4T,ADDYEARS,+2,TOGREG=Y4T)           
 OUTFIL REMOVECC,                                           
 HEADER1=('Input     +50 days  -7 months +2 years') 
 
 Input: 
 20070305
 20071213
 20080219
 20080901
 20091122
 20090115
 20100915
 20100630
 99999999

Processing:

  • Add 50 days, subtract 7 months and add 2 years.
  • 1,8,Y4T for the input field to match the C’ccyymmdd’ input date.
  • TOGREG=Y4T to give us a C’ccyymmdd’ output date.
Output: 
 Input     +50 days  -7 months +2 years
 20070305  20070424  20060805  20090305
 20071213  20080201  20070513  20091213
 20080219  20080409  20070719  20100219
 20080901  20081021  20080201  20100901
 20091122  20100111  20090422  20111122
 20090115  20090306  20080615  20110115
 20100915  20101104  20100215  20120915
 20100630  20100819  20091130  20120630
 99999999  99999999  99999999  99999999

Note: ‘99999999’ input value is treated as a special indicator for output.

IBM Reference : Click Here

Scroll to Top