# null date values on CSV output

**URL:** <https://techcommunity.softwareag.com/t/null-date-values-on-csv-output/101207>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Linux\
**Created:** [August 14, 2012, 1:07am UTC](https://techcommunity.softwareag.com/t/null-date-values-on-csv-output/101207 "2012-08-14T01:07:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 14, 2012, 1:07am UTC](https://techcommunity.softwareag.com/t/null-date-values-on-csv-output/101207/1 "2012-08-14T01:07:50Z")

</div>

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

```auto
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.

```auto
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
```

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [August 14, 2012, 8:29am UTC](https://techcommunity.softwareag.com/t/null-date-values-on-csv-output/101207/2 "2012-08-14T08:29:00Z")

</div>

> [@Ralph Zbrog](#):
>
> I find it interesting that Natural writes “0” for an empty packed numeric, but writes a true null for an empty date field.

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:

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [August 14, 2012, 9:51am UTC](https://techcommunity.softwareag.com/t/null-date-values-on-csv-output/101207/3 "2012-08-14T09:51:08Z")

</div>

> [@Ralph Zbrog](#):
>
> Is there a NatParm or other option that I’m overlooking?

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.

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [August 16, 2012, 10:53pm UTC](https://techcommunity.softwareag.com/t/null-date-values-on-csv-output/101207/4 "2012-08-16T22:53:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:02pm UTC](https://techcommunity.softwareag.com/t/null-date-values-on-csv-output/101207/5 "2021-04-02T15:02:17Z")

</div>


