null date values on CSV output

I’m writing a CSV which contains a D-format field. Occasionally the date field is empty. Here is the output.

1,08/14/2012,0
2,,0
3,08/16/2012,0
4,,0
5,08/18/2012,0

I find it interesting that Natural writes “0” for an empty packed numeric, but writes a true null for an empty date field.

Natural fails with an error 1143 (input does not correspond to input edit mask) when it encounters the null date value in a READ WORK. I would expect him to be able to read what he himself has written. Is there a NatParm or other option that I’m overlooking?

Here is the code that produced the output, above.

DEFINE DATA LOCAL
1 #D (D)  INIT <*DATX>
1 #P (P3)
1 #I (I4)
END-DEFINE
FORMAT ZP=T
DEFINE WORK FILE 1 'C:\rgz.txt' TYPE "CSV"
FOR #I = 1 5
  IF  #I / 2 * 2 = #I
    THEN
      RESET #D
    ELSE
      RESET INITIAL #D
      ADD #I TO #D
  END-IF
  WRITE WORK 1 #I #D #P
END-FOR
*
READ WORK 1 #I #D #P
  DISPLAY #I #D #P
END-WORK
END

Maybe this corresponds to the behaviour of DISPLAY. An empty date is never displayed, but an empty time field is.

But in both cases a NAT1143 during READ WORK occurs. Seems like only redefine helps. Like that:

1 #D (P7)  INIT <*DATX>
1 redefine #d
  2 #date (D)
...
READ WORK 1 #I #D #P
  DISPLAY #I #Date #P
END-WORK

No, there isn’t, not even ZP=ON applies for a “true null” date field.

It doesn’t even help to specify an EM explicitly, Natural will still output just nuffin.

Messy workaround. How about something like

1 #DATE (D)
1 REDEFINE #DATE
2 #DATE-B (B4)

IF #DATE-B = H’00000000’
MOVE something TO #DATE

WHERE “something” is a “valid” date for Natural, but invalid for the application. Then, when reading the file test for the invalid date.

The more I look at it the more I want to start happy hour now.

steve