OUTREC control statement is used to reformat (adds, deletes, or reformats fields) each record after they are sorted, merged, or copied by specifying all of its items one by one. This statement supports a wide variety of parsing, editing, and reformatting tasks. We can even add spaces/zeroes/any character into the output record based on the requirement.
.-,----------. V | >>-OUTREC--+-PARSE=(---definition-+-)--------------------+->< | .-,----. | | V | | '---+-+-FIELDS=-+-(---item-+-)------------+---' | '-BUILD=--' | | .-,----. | | V | | +-OVERLAY=(---item-+-)----------------+ | .-,----. | | V | | +-FINDREP=(---item-+-)----------------+ | .-,---------------. | | V | | '---IFTHEN=(clause)-+--+------------+-' ‘-IFOUTLEN=n-'
INREC and OUTREC do the same, but the only difference is the way reformatting is done.
INREC: Specifies how records are reformatted before they are sorted, copied, or merged. INREC is useful in case of the large input files. When INREC is used reformatting of records is done BEFORE the sort.
OUTREC: Specifies how records are reformatted after they are sorted, copied, or merged. The final output will be the same. When it is used reformatting of records is done AFTER the sort.
You can create the reformatted OUTREC records in one of the following ways using unedited, edited, or converted input fields.
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 OUTREC records and the order in which they appear. You can delete, rearrange, and insert fields and constants.
SORT FIELDS=(1,5,CH,A) OUTREC FIELDS=(1,39,40,8,ZD,EDIT=(SII,III,IIT),SIGNS=(,-))
Remove the “()” from data in the first 29 bytes, remove spaces between the data, and separate the data with ‘,’.
OPTION COPY OUTREC FIELDS=(1,80,SQZ=(SHIFT=LEFT,PREBLANK=C’()',MID=C','))
Explanation:
Align the data in the first 29 bytes to LEFT and replace () with <>.
OPTION COPY OUTREC FIELDS=(1,29,JFY=(SHIFT=LEFT,PREBLANK=C'()', LEAD=C'<',TRAIL=C'>'),30,30)
Explanation:
Replace the “math” with “mathematics”.
SORT FIELDS=(1,5,CH,A) OUTREC FIELDS=(1,29,30,4,CHANGE=(11,C'math',C'mathematics'), 4X,45,30)
Explanation:
Convert the date from mmddccyy to ccyymmm(julian date).
SORT FIELDS=(1,5,CH,A) OUTREC FIELDS=(1,54,55,8,Y4W,TOJUL=Y4T)
Explanation:
Add two days, two years to the date in the input file.
SORT FIELDS=(1,5,CH,A) OUTREC FIELDS=(1,54,55,8,Y4W,ADDDAYS,+2,TOJUL=Y4T(/), 5X,55,8,Y4W,ADDYEARS,+2,TOJUL=Y4T(/))
Explanation:
Multiply the marks with 10 and store them in the same record.
SORT FIELDS=(1,5,CH,A) OUTREC FIELDS=(1,48,45,3,ZD,MUL,+10)
Explanation:
Convert the first five bytes ZD to FS in the input file.
SORT FIELDS=(1,5,CH,A) OUTREC FIELDS=(1,5,ZD,TO=FS,LENGTH=6,X,6,73)
Explanation:
Let’s insert the below data types between the fields in the output file.
You can use Z or 1Z to specify a single binary zero. You can use nZ to specify n binary zeros.
SORT FIELDS=(1,5,CH,A) OUTREC BUILD=(1,5,4Z,6,4)
Explanation:
This sort card will insert 4 binary zeroes between the first and second fields of your output file.
You can insert blanks before, between, or after fields. You can use X or 1X to specify a single blank. You can use nX to specify n blanks. To insert 10 blanks, write 10X before the first field. To insert 5 blanks, write 5X between the two fields.
SORT FIELDS=(1,5,CH,A) OUTREC BUILD=(20X,1,5,10X,6,4)
Explanation:
This sort card will insert spaces in the first 20 bytes, then the fields 1 to 5 from the input file are moved to 21 thru 25, 26 thru 36 will have blanks and then input file fields from position 6 to 10 is moved to output file positions 37 to 41.
To insert a character string to your output include C ‘ your string ’ as part of your OUTREC, you can include any EBCDIC character between single quotes. To include a single apostrophe in the string, you must specify it as two single apostrophes example, to include the word “Tom’s” you need to specify C’Tom”s’.
SORT FIELDS=(1,5,CH,A) OUTREC BUILD=(C'Run Date:',1,10,C'|',C'Run Time:’,11,4)
Explanation:
If your input file record is ‘2015/04/0415:30′ the output will be “Run Date:2015/04/04|Run Time:13:30″.
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:
OPTION COPY OUTREC OVERLAY=(30:30,4,TRAN=LTOU, 45:45,3,ZD,MUL,+10,TO=ZD,LENGTH=4)
Explanation:
The below OVERLAY will extend the records.
OPTION COPY OUTREC OVERLAY=(30:30,4,TRAN=LTOU, 85:45,3,ZD,MUL,+10,TO=ZD,LENGTH=4)
Explanation:
SORT FIELDS=(1,5,ZD,A) OUTREC OVERLAY=(60:SEQNUM,2,ZD,START=5,INCR=5)
Explanation:
SORT FIELDS=(1,5,ZD,A) – The input file will be sorted first and written to the output.
OUTREC OVERLAY=(60:SEQNUM,2,ZD,START=5,INCR=5) – Generates the sequence number of length 2 from 60th byte. The sequence number starts at 5 and is incremented by 5 each time.
If you want to replace or remove data anywhere in records, the FINDREP parameter of the OUTREC statement needs to use instead. FINDREP indicates doing a find and replace operation. IN identifies the constant (the “find” constant) and OUT identifies the constant (the “replace” constant). Example:
OPTION COPY OUTREC FINDREP=(IN=C'small',OUT=C'SMALL')
Explanation:
OUTREC FINDREP=(IN=C’small’,OUT=C’SMALL’) – finds the text “small” in the entire input file with the “SMALL” and writes to the output.
Reformat different records in different ways by specifying how 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:
OPTION COPY OUTREC IFTHEN=(WHEN=INIT,BUILD=(1:1,80)), IFTHEN=(WHEN=(30,5,CH,EQ,C'small'),OVERLAY=(45:C'***')), IFTHEN=(WHEN=NONE,BUILD=(1:1,80))
Explanation:
PARSE can be used for many different types of variable fields including delimited fields, comma-separated values (CSV), tab-separated values, blank-separated values, keyword-separated fields, null-terminated strings, and so on. You can assign up to 1000 parsed fields (%0-%999) to the variable fields you want to extract.
Note that if all of the fields in your records have fixed positions and lengths, you don’t need to use PARSE. But if any of the fields in your records have variable positions or lengths, you can use PARSE to treat them as fixed parsed fields in BUILD or OVERLAY. You can mix p,m fields (fixed fields), and %nn fields (parsed fields) in BUILD and OVERLAY.
INPUT FILE N12345¦HMOMEDICAL¦P1234¦103¦ABCDE¦SAMDAVID¦CA¦20210101¦99991231¦A N11133¦PPO¦A1200¦123¦ABCDE¦KIM DAVID¦CA¦20210101¦99991231¦T N12399¦CALCARE¦P1001¦199¦ABC¦ANNA DAVID¦CA¦20210101¦99991231¦A N00300¦DENTAL¦P1299¦999¦XYZ¦CHERYL CHRIS¦CA¦20210101¦99991231¦A
//STEP01 EXEC PGM=SORT //SORTIN DD DISP=SHR,DSN=I/P File //SORTOUT DD DSN=O/P File, // DISP=(NEW,CATLG,DELETE), // UNIT=TESTDA,SPACE=(TRK,(10,10),RLSE) // DCB=(LRECL=80,BLKSIZE=0,RECFM=FB,DSORG=PS) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SORTWK01 DD SPACE=(CYL,20),UNIT=SYSDA //SORTWK02 DD SPACE=(CYL,20),UNIT=SYSDA //SORTWK03 DD SPACE=(CYL,20),UNIT=SYSDA //SYSIN DD * SORT FIELDS=COPY OUTREC PARSE=(%01=(ENDBEFR=C'¦',FIXLEN=5), %02=(ENDBEFR=C'¦',FIXLEN=10), %03=(ENDBEFR=C’¦’,FIXLEN=05), %04=(ENDBEFR=C’¦',FIXLEN=03), %=(ENDBEFR=C’¦’), ……… ……… ……… %10=(ENDBEFR=C'¦',FIXLEN=1)), BUILD=(%01,%02,%03,…,%10) /*
OUTPUT N12345HMOMEDICALP1234103SAM DAVID CA 20210101 99991231 A N11133PPO A1200123KIM DAVID CA 20210101 99991231 T N12399CALCARE P1001199ANNA DAVID CA 20210101 99991231 A N00300DENTAL P1299999CHERYL CHRIS. CA 20210101 99991231 A
The %01 parsed field is used to extract the first variable field into a 5-byte fixed parsed field. ENDBEFR=C’¦’ tells DFSORT to stop extracting data at the byte before the next comma (the comma after the first variable field). FIXLEN=5 tells DFSORT that the %01 parsed field is 5 bytes long.
The % parsed field is used to skip the variable field without extracting anything for it. BUILD operand is used to construct the output record.
The following control statements will transform records containing a field of format cyymmdd to the format yyymmdd.
SORT FIELDS=(1,7,BI,A) OUTFIL OUTREC=(1,1,CHANGE=(2, * change C'c' as follows: C'0',C'19', * C'0' to C'19' C'1',C'20', * C'1' to C'20' C'2',C'21'), * C'2' to C'21' NOMATCH=(C'99') 2,6) * copy C'yymmdd'
The OUTREC control statement in SORT is a powerful tool for customizing the output of a sort operation. It enables data professionals to manipulate records, rearrange fields, and perform calculations, all within the sorting process. As with any tool, it’s essential to practice and experiment with different scenarios to fully grasp the potential of OUTREC in SORT. Whether you’re reformatting dates, concatenating fields, or performing conditional replacements, OUTREC empowers you to mold your data exactly as needed.
A well-maintained product backlog is crucial for successful product development. It serves as a single…
Incremental value to the customer refers to the gradual delivery of small, functional parts of…
A Product Market refers to the group of potential customers who might be interested in…
The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…
The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…
Choosing the right Scrum Master Certification depends on your current experience and career goals. If…