Let’s say your input file has data that is delimited by PIPE or COMMA e.g. you have uploaded a CSV file to a mainframe or you extract database variable fields to a CSV or PIPE separated file. To open this file in a copybook or use it in the program it needs to be reformatted to a fixed-length file. This reformatting can be done by using PARSE with the BUILD parameter.
PARSE operand can be used with INREC, OUTREC, or OUTFIL to define rules that tell DFSORT how to extract the relevant data from each variable input field into a fixed parsed field
CSV or PIPE to FIXED length conversion
INPUT
N12345¦HMOMEDICAL¦P1234¦103¦ABCDE¦SAM DAVID¦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.
PARSE Parameters
Below are the parameters in PARSE for extracting variable position/length data to %nn fixed parsed fields, where nn can be 00 to 99: Each %nn parsed field must be defined only once. FIXLEN=m: Specifies the length (m) of the fixed area to contain the extracted variable data for this %nn fixed parsed field.
- ABSPOS=p: Start extracting data at input position p.
- ADDPOS=x: Start extracting data at the current position + x.
- SUBPOS=y: Start extracting data at the current position – y.
- STARTAFT=string: Start extracting data at the byte after the end of the character or hexadecimal string.
- STARTAFT=BLANKS: Start extracting data after the end of the next group of blanks.
- STARTAT=string: Start extracting data at the first byte of the character or hexadecimal string.
- STARTAT=BLANKS: Start extracting data at the start of the first group of blanks.
- STARTAT=NONBLANK: Start extracting data at the next nonblank.
- ENDBEFR=string: Stop extracting data at the byte before the start of the character or hexadecimal string.
- ENDBEFR=BLANKS: Stop extracting data at the byte before the next group of blanks.
- ENDAT=string: Stop extracting data at the last byte of the character or hexadecimal string.
- ENDAT=BLANKS: Stop extracting data at the end of the next group of blanks.
- PAIR=APOST: Do not search for strings or blanks between apostrophe (‘) pairs.
- PAIR=QUOTE: Do not search for strings or blanks between quote (“) pair