|
View previous topic :: View next topic
|
| Author |
Message |
joeempson
New User
Joined: 21 Mar 2009 Posts: 11 Location: UK
|
|
|
|
I am parsing a CSV file into a fixed length output. The input file contains a date field with is missing on some records and populated on others:
John Smith,a house,19/04/1980,xxx
john dow,a different house,,yyy
I want to default the date to 12/31/9999 if it is missing.
IFTHEN=WHEN does not seem appropriate because the date field is not at a fixed position.
Is it possible to do this in a single step? |
|
| Back to top |
|
 |
prahalad
New User
Joined: 14 Sep 2010 Posts: 18 Location: Pune
|
|
|
|
You can try with the following SORT job. You can adjust the field position are per your requirement.
| Code: |
INREC PARSE=(%01=(ENDBEFR=C',',FIXLEN=10),
%02=(ENDBEFR=C',',FIXLEN=20),
%03=(ENDBEFR=C',',FIXLEN=10),
%04=(FIXLEN=5)),BUILD=(1:%01,11:%02,31:%03,41:%04)
OPTION COPY
OUTFIL IFTHEN=(WHEN=(31,10,CH,EQ,C' '),
OVERLAY=(31:C'12/31/9999'))
|
InputFile:
| Code: |
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
JOHN SMITH,A HOUSE,19/04/1980,XXX
JOHN DOW,A DIFFERENT HOUSE,,YYY
|
Output file:
| Code: |
----+----1----+----2----+----3----+----4----+
JOHN SMITHA HOUSE 19/04/1980XXX
JOHN DOW A DIFFERENT HOUSE 12/31/9999YYY
|
|
|
| Back to top |
|
 |
joeempson
New User
Joined: 21 Mar 2009 Posts: 11 Location: UK
|
|
|
|
Thanks that worked.
They key thing I missed was the ability to use INREC to parse the record first. |
|
| Back to top |
|
 |
joeempson
New User
Joined: 21 Mar 2009 Posts: 11 Location: UK
|
|
|
|
I found a better solution for the case when there are multiple fields to default.
IFTHEN is not good in this scenario because it can only handle one match per record and if there are multiple fields missing in the input you have to cover every possible combination with complicated IFTHEN statements.
After a quick ssearch through the manual I found the CHANGE statement which suits my purpose perfectly
| Code: |
OUTREC BUILD=(1,53,
54,2,
CHANGE=(2,C' ',C'00'),
NOMATCH=(54,2),
56,3,
59,10,
CHANGE=(10,C' ',C'12/31/9999'),
NOMATCH=(59,10)) |
|
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
| Quote: |
| if there are multiple fields missing in the input you have to cover every possible combination with complicated IFTHEN statements. |
Well, I'm not sure what you mean by that exactly, but I suspect you could use HIT=NEXT to avoid complicated IFTHEN statements. HIT=NEXT continues to the next IFTHEN clause even if the current one is satisfied, so it let's you deal with multiple unrelated fields using simple IFTHEN clauses. |
|
| Back to top |
|
 |
joeempson
New User
Joined: 21 Mar 2009 Posts: 11 Location: UK
|
|
|
|
| Thanks Frank, I didn't know about HIT=NEXT and yes it is an alternative solution to my problem. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|