Parsing a CSV file with variable number of fields



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Parsing a CSV file with variable number of fields

Postby Maddynari » Tue Apr 19, 2011 2:29 am

Hi
I'm new to this forum and I have a requirement where I need to Create a sysin from CSV file dynamically.The requirement is We have a file with every FTp transfer characteristics of a report stored in a CSV file and we would parse the file dynamically in a job to creat the file transfer sysins on the fly based on the key value passed in the job(the key name is the name of a sysin its unique and 8 characters at the begining).The input may be something as .there can be a maximum of 10fields per line and the number of fields in per line is variable that means one line can have 3 transfer parametrs defined next can have five and the length of each field is variable and c',' is the only delimiter and ech string would end with -delsrc
key1,-lqm abcd,-dqm fghf,-spath filnm1,-Dpath1 d:\dfg\,-delsrc,
key2,-lqm abcd,-spath filnm2,-dqm fghy,-dpath2 d:\dfg\ghf\,-delsrc,

My requirement is to parse every line with unique key and then the output would be dynamically parsing every line into the following format.Say the parameter passed in the program is sysin name key2,the dynamic sysin created would be
&&temp with
-lqm abc
-dqm fghy
-spath filnm2
-dpath2 d:\dfg\ghf\[filnm2]
-delsrc

I know it can be done through Parse but I'm confused as the no of fileds in one line are not fixed they can have mutiple trasnfer parameters missing or added .any help would be very much appreciated

Thanks much in Advance
Maddy
I
Maddynari
 
Posts: 1
Joined: Tue Apr 19, 2011 1:36 am
Has thanked: 0 time
Been thanked: 0 time

Re: Parsing a CSV file with variable number of fields

 

Re: Parsing a CSV file with variable number of fields

Postby skolusu » Tue Apr 19, 2011 4:51 am

Maddynari,

Your output does NOT match the input. if your intention is to split the records delimited by , into individual records then it is very easy to do with DFSORT/ICETOOL's RESIZE operator

//STEP0100 EXEC PGM=ICETOOL                                         
//TOOLMSG  DD SYSOUT=*                                               
//DFSMSG   DD SYSOUT=*                                               
//IN       DD *                                                     
KEY1,-LQM ABCD,-DQM FGHF,-SPATH FILNM1,-DPATH1 D:\DFG\,-DELSRC,     
KEY2,-LQM ABCD,-SPATH FILNM2,-DQM FGHY,-DPATH2 D:\DFG\GHF\,-DELSRC, 
//OUT      DD SYSOUT=*                                               
//TOOLIN   DD *                                                     
  RESIZE FROM(IN) TO(OUT) TOLEN(80) USING(CTL1)                     
//CTL1CNTL DD *                                                     
  SORT FIELDS=COPY                                                   
  INREC PARSE=(%=(ENDBEFR=C','),                                     
               %01=(ENDBEFR=C',',FIXLEN=80),                         
               %02=(ENDBEFR=C',',FIXLEN=80),                         
               %03=(ENDBEFR=C',',FIXLEN=80),                         
               %04=(ENDBEFR=C',',FIXLEN=80),                         
               %05=(ENDBEFR=C',',FIXLEN=80),                         
               %06=(ENDBEFR=C',',FIXLEN=80),                         
               %07=(ENDBEFR=C',',FIXLEN=80),                         
               %08=(ENDBEFR=C',',FIXLEN=80),                         
               %09=(ENDBEFR=C',',FIXLEN=80),                         
               %10=(ENDBEFR=C',',FIXLEN=80)),                       
        BUILD=(%01,%02,%03,%04,%05,%06,%07,%08,%09,%10)             
                                                                     
  OUTFIL OMIT=(1,1,CH,EQ,C' ')                                       
//*


The output from this job is
-LQM ABCD               
-DQM FGHF               
-SPATH FILNM1           
-DPATH1 D:\DFG\         
-DELSRC         
       
-LQM ABCD               
-SPATH FILNM2           
-DQM FGHY               
-DPATH2 D:\DFG\GHF\     
-DELSRC
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
skolusu
 
Posts: 586
Joined: Wed Apr 02, 2008 10:38 pm
Has thanked: 0 time
Been thanked: 39 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post