OUTREC Inserting data


The OUTREC statement with the BUILD or OVERLAY parameter can be used to insert data into records. It can be used to insert the below data types between the fields in the output file. Those are -

  • Binary Zeroes
  • Blanks
  • Strings

Inserting Binary Zeros -


OUTREC inserts binary zeros as placeholders for the new field, and it may be filled in with data at a later date. Z or 1Z is used to code a single binary zero, and nZ is used to code n binary zeros.

Syntax -

//SYSIN    DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(...,nZ,...)
/*
nZSpecifies n number of zeroes.
n can be from 1 to 4095.
If n ignored, n can be treated as 1.
Note! "n" and the length of new field should always match for the accurate results.

Examples -


Scenario1 - Inserting zeros at first 5 positions.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(5Z,1,75)
/*

Inserts zeros in first 5 positions and copes the record of length 75 from input file and places it from 6th position.

Scenario2 - Inserting zeros in the middle of the record.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(1,35,5Z,36,40)
/*

Copies 35 bytes from input to output and inserts zeroes in 5 positions. Then copies 40 bytes from input to output and places from 40th position.

Inserting Blanks -


OUTREC statement used to separate the fields with blanks to create margins. A blank can insert before, between, or after fields. X or 1X used to specify a single blank and nX used to specify n blanks.

Syntax -

//SYSIN    DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(...,nX,...)
/*
nXn is number of spaces.
n can be from 1 to 4095.
If n ignored, n is treated as 1.

Examples -


Scenario1 - Inserting spaces at first 5 positions.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(5X,1,75)
/*

Inserts spaces in first 5 positions and copes the record of length 75 from input file and places it from 6th position.

Scenario2 - Inserting spaces in the middle of the record.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(1,35,5X,36,40)
/*

Copies 35 bytes from input to output and inserts spaces in 5 positions. Then copies 40 bytes from input to output and places from 40th position.

Inserting Strings -


OUTREC can be used to setup a report by inserting strings. The OUTFIL control statement can be used to create complex reports.

Syntax-1: Character strings -

//SYSIN    DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(...,C'xx..xx',...)
/*

Syntax-2: Repeating character strings -

//SYSIN    DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(...,n:C'xx..xx',...)
/*

Syntax-3: Hexa Deciamal strings -

//SYSIN    DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(...,n:X'yy..yy',...)
/*
C'xx..xx'Specifies the character string that needs to be insert.
n:C'xx..xx'n specifies the number of times character string repeats.
X'yy..yy'Hexa decimal string

Examples -


Scenario1 - Inserting HELLO at first 5 positions.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(C'HELLO',1,75)
/*

Inserts HELLO in first 5 positions and copes the record of length 75 from input file and places it from 6th position.

Scenario2 - Inserting spaces in the middle of the record.

//SYSIN    DD *
     SORT FIELDS=(1,5,CH,A)
     OUTREC FIELDS=(1,35,C'HELLO',36,40)
/*

Copies 35 bytes from input to output and inserts HELLO in 5 positions. Then copies 40 bytes from input to output and places from 40th position.