SORT – OUTREC – INSERT ZEROES, BLANKS, STRINGS
Using OUTREC parameter in SORT, you can insert zeroes, blanks or strings in any place you require of the output record.
-
Insert Zeroes
Suppose you want to copy first 10 fields then place 10 zeroes and then bytes from 11 to 20 from the input file to output file. Your OUTREC would look like as below.
OUTREC FIELDS=(1,10,10Z,11,10)
Where 10Z means 10 Zeroes
-
Insert Blanks
Suppose you want to copy first 10 fields then place 10 blanks and then bytes from 11 to 20 from the input file to output file. Your OUTREC would look like as below.
OUTREC FIELDS=(1,10,10X,11,10)
Where 10X means 10 Blanks
The above OUTREC can also be written as below:
OUTREC FIELDS=(1,10,21:11,10)
Where 21: would ask the sort to fill the data from 11 to 20 bytes of input into 21 to 30 of the output dataset. SORT will automatically fill in blanks from 11 to 20.
Specifying c:X as your last field is an easy way to increase the record length of your output records to c bytes. For example, if you want to create 80-byte output records containing the first 30 bytes of your input records padded with blanks, you can use this OUTREC statement:
OUTREC BUILD=(1,30,80:X)
-
Insert string
To insert character strings use the below format
OUTREC FIELDS=(1,10,C’AT LAST’)
Here we are inserting the string ‘AT LAST’ once after copying first 10 chars of input record.
OUTREC FIELDS=(1,10,5C’AT LAST’)
Here we are inserting the string ‘AT LAST’ five times after copying first 10 chars of input record.
To insert hexadecimal strings use the below format
OUTREC FIELDS=(1,10,X’yy..yy’)
Here we are inserting the string ‘yy..yy’ once after copying first 10 chars of input record.
OUTREC FIELDS=(1,10,nX’yy..yy’)
Here we are inserting the string ‘yy..yy’ five times after copying first 10 chars of input record.
——————————————————————————————————–
In United States, If you would like to Earn Free Stocks, Credit card Points and Bank account Bonuses, Please visit My Finance Blog
——————————————————————————————————–
You may also like to look at:
Working on Mainframes – Is Change to a different technology necessary
How to insert a blank record using sort?
If you want to just insert a blank record into a file which has record length as 80 bytes, use the below sort card
SORT FIELDS=COPY
OUTREC FIELDS=(80X)
If your requirement is different, please post with an example. Thank you.
I need to know how to increase the lenght of the field. For example, lets suppose i have below record
11223344*556677
Now i want below record i.e increase the lenght of * to *** and write to the output file
11223344***556677
Hi Rajiv,
I have few queries regarding your question. Do we have “*” in all the records of the file. Or do we have different character in different records.
And do you want the solution only in SORT or any other Language is also fine.
Thank you.
Pingback: SORT – PARSE – READ EXCEL (CSV) FILE IN MAINFRAMES | F1 for Mainframe