Author |
Message
|
isaw |
Posted: Tue Mar 31, 2009 4:42 am Post subject: Need some help parsing 'date' in CWF (parsing errors) |
|
|
Apprentice
Joined: 09 May 2007 Posts: 45
|
Hey guys.
I have a flat file of multiple records with various fields, fixed lengths. The records are parsed one by one and inserted into a Database. That's usually fine.
One of the fields in the record is a date in the 'yyyyMMdd' format, located at the end of the record just before some filler whitespace. This needs to go to the database as a date if valid, otherwise NULL is fine.
Code: |
"AAAABBXXX FF183000000000 YNYYYNYNNN 20080909 00000000 " |
The value of the date field can either be a proper date like '20090331' or just zeros '00000000' if no value was set on the originating source (their way of indicating a NULL for that numeric field).
Now, I've got my MRM working with everything but that field at the moment - it throws up a bunch of exceptions leading to this :
Code: |
(0x01000000):Exception = (
(0x03000000):ExceptionType = 'ParserException' (CHARACTER)
(0x03000000):ErrorNumber = 5540 (INTEGER)
(0x03000000):SeverityLevel = 3 (INTEGER)
(0x03000000):ErrorSource = '' (CHARACTER)
(0x03000000):DiagnosticMessage = 'CPI Unable to parse datetime internally' (CHARACTER)
(0x03000000):CauseOfException = '( 00000000, yyyyMMdd, 1 )' (CHARACTER)
|
In my msg def, the field in question is "xsd:date" and has the following props set:
Logical Props : Local Element :
- Default checked
- Nillable checked.
- Min/Max occurance 1
Physical Properties : CWF :
- Physical Type : Fixed Length String
- Length : 8
- Length Units : Bytes
- Justification : Left
- Padding Char : '0'
- DateTime Format : yyyyMMdd
- Encoding Null : NullLiteralFill
- Encoding Null Value : 0
- rest is default
And it fails with that.
I've changed the Encoding Null to "NullLiteralValue" and tried 00000000 as the Encoding Null Value but still it didn't like it.
As a side note, I also have a field earlier on as an "xsd:time" which works fine when either "183000", "000000" or " " (6 spaces) shows up. I have that one set to NullLiteralFill/SPACE as the encoding types for that.
I just can't seem to find the right settings for a Date. Does anyone have any suggestions? |
|
Back to top |
|
 |
isaw |
Posted: Tue Mar 31, 2009 4:52 am Post subject: |
|
|
Apprentice
Joined: 09 May 2007 Posts: 45
|
I suppose the easiest solution is to take it as a plain string and cater for the Date possibilities in the ESQL. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Apr 01, 2009 1:04 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Not sure why NullLiteralValue is not working. It is definitely the correct approach You could try NullLiteralFill/'0' and see whether that does the job. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 01, 2009 2:14 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
kimbert wrote: |
Not sure why NullLiteralValue is not working. It is definitely the correct approach You could try NullLiteralFill/'0' and see whether that does the job. |
So... when does MRM use NullLiteralValue/NullLiteralFill? On writing? On parsing? On both? |
|
Back to top |
|
 |
kimbert |
Posted: Wed Apr 01, 2009 3:36 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Both.
Nulls have a physical (literal) representation in the bit stream, and a logical representation in the message tree ( value IS NULL ). The MRM parser maps between the two when parsing or writing, and uses the Null Handling properties to do so. |
|
Back to top |
|
 |
isaw |
Posted: Wed Apr 01, 2009 5:39 am Post subject: |
|
|
Apprentice
Joined: 09 May 2007 Posts: 45
|
kimbert,
NullLiteralFill / '0' worked!
I think I tried various combinations but that one didn't come up. So now it's parsing the flatfile record and reads in the '00000000' date and the resulting field is NULL as I want.
Funny - I wouldn't have expected that if it was reading it as a String. Had it been read as a numeric, all zeros technically are just '0' so a NULL would go. But i figured that '00000000' != '0' from a String point of view.
Anyhow, thanks for the help. Solved a sticking point for me and is definitely seomthing I need to keep in mind (much more parsing like this to go).
Cheers matey.
EDIT: Looking at my initial attempts, I simply had 0 and not '0' in single quotes. I suppose even tho the field was defined as xsd:date, the parsing was a 'fixed length String' so naturally was looking for the value to be in quotes, to represent a string....? And not a value without single quotes which in this case denoted a numeric...? Or am I barking up the wrong tree? Just trying to figure out my mistake. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Apr 01, 2009 11:35 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Your theory is probably correct, but I don't have time to investigate in detail. Glad it's working now. |
|
Back to top |
|
 |
|