CSV

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

JCL blogs – Click Here SYNCSORT Manual: Click Here

Scroll to Top