Page 1 of 1

How to PARSE delimited file

PostPosted: Tue Jul 12, 2016 6:24 pm
by shankar_dh
Hi All,

I need to skip a column(field) in a delimited file and write the output as is.
For example,
my input file(delimited by pipe)
A1|X1|Y1|Z1
B|X|Y|Z    
C3|X2|Y2|Z2


output file should be(without column 3)
A1|X1|Z1
B|X|Z    
C3|X2|Z2


I am able to get output with below code, but I want my out put should be same as input file but the below code puts each field in a fixed length.
INREC PARSE=(%1=(ENDBEFR=C'|',FIXLEN=2),
             %2=(ENDBEFR=C'|',FIXLEN=2),
             %=(ENDBEFR=C'|'),          
             %4=(FIXLEN=2)),            
BUILD=(%1,C'|',%2,C'|',%4)


Without parameter "FIXLEN" I am getting a syntax error.
Is there a way to achieve it?

Re: How to PARSE delimited file

PostPosted: Tue Jul 12, 2016 7:30 pm
by NicC
use the code tags to present your data/control cards etc.

What syntax error? Show it - using the code tags or the error pointer will not align.

Re: How to PARSE delimited file

PostPosted: Tue Jul 12, 2016 7:48 pm
by Aki88
Hello,

See if this is what you're looking for (the solution though can be tweaked further; also, I've inflated the FIXLEN value, you can reduce it as per your input):


//STEP001  EXEC PGM=SORT                    
//SYSOUT   DD SYSOUT=*                      
//SORTIN   DD *                            
A1|X1|Y1|Z1                                
B|X|Y|Z                                    
C3|X2|Y2|Z2                                
/*                                          
//SORTOUT  DD SYSOUT=*                      
//*                                        
//SYSIN    DD *                            
 INREC PARSE=(%0=(ENDBEFR=C'Y',FIXLEN=30),  
              %2=(STARTAFT=C'|',FIXLEN=30)),
       BUILD=(%0,%2)                        
 SORT FIELDS=COPY                          
 OUTFIL BUILD=(1,60,SQZ=(SHIFT=LEFT))      
/*                                          
 



SORTOUT:


A1|X1|Z1
B|X|Z  
C3|X2|Z2
 



Hope this helps.

Edit: An assumption with this solution, you need to skip values with 'Y' in them.

Re: How to PARSE delimited file

PostPosted: Tue Jul 12, 2016 8:16 pm
by shankar_dh
Hi NicC, sorry for posting the code without TAGs. Will make a practice to post with tags going forward...

Hey Aki88, perfect!! This is what I was looking for. Thanks.

Re: How to PARSE delimited file

PostPosted: Tue Jul 12, 2016 11:01 pm
by BillyBoyo
Be aware it will need a little more if you have embedded blanks.