How to PARSE delimited file



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

How to PARSE delimited file

Postby shankar_dh » Tue Jul 12, 2016 6:24 pm

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?
shankar_dh
 
Posts: 41
Joined: Fri Mar 22, 2013 1:00 pm
Has thanked: 1 time
Been thanked: 0 time

Re: How to PARSE delimited file

Postby NicC » Tue Jul 12, 2016 7:30 pm

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: How to PARSE delimited file

Postby Aki88 » Tue Jul 12, 2016 7:48 pm

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.
Aki88
 
Posts: 381
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 36 times

Re: How to PARSE delimited file

Postby shankar_dh » Tue Jul 12, 2016 8:16 pm

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.
shankar_dh
 
Posts: 41
Joined: Fri Mar 22, 2013 1:00 pm
Has thanked: 1 time
Been thanked: 0 time

Re: How to PARSE delimited file

Postby BillyBoyo » Tue Jul 12, 2016 11:01 pm

Be aware it will need a little more if you have embedded blanks.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post