ContentsIndexPreviousNext

5.3.3.4 Date Directive

The DATE directive instructs the runtime to store a field in the database as a date. Because there's no COBOL syntax that identifies a field as a date, you may want to add this directive to differentiate dates from other numbers, so that they enjoy the properties associated with dates in the RDBMS. Note that Acucorp's record editor, alfred, does not validate the data you enter into date fields.

Syntax

$XFD DATE=date-format-string

or

*(( XFD DATE=date-format-string ))

The date-format-string is a description of the desired date format in the COBOL program, composed of characters from the following list:

M
month (01 - 12)
Y
year (2 or 4-digit)
D
day of month (01 - 31)
J
Julian day (00000000 - 99999999)
E
day of year (001 - 366)
H
hour (00 - 23)
N
minute
S
second
T
hundredths of a second

Any other characters cause the date format string to be invalid, and result in a "corrupt XFD" error or a compile-time warning.

Each character in a date format string can be considered a place holder that represents the type of information stored at that location. The characters also determine how many digits will be used for each type of data.

For example, although you would typically represent the month with two digits, if you specify MMM as part of your date format, the resulting date will use three digits for the month, left-zero-filling the value. If the month is given as M, the resulting date will use a single digit, and will truncate on the left.

If you do not specify a date-format-string, the default is YYMMDD if the field has six digits, or YYYYMMDD if the field has eight digits.

Julian dates

Because the definition of Julian day varies, the DATE directive offers a great deal of flexibility for representing Julian dates. Many source books define the Julian day as the day of the year, with January 1st being 001, January 2nd being 002, and so forth. If you want to use this definition for Julian day, simply use EEE (day of year) in your date formats.

Other reference books define the Julian day as the number of days since some specific "base date" in the past. This definition is represented in the DATE directive with the letter J (for example, a six-digit date field would be preceded with the directive "$XFD DATE=JJJJJJ"). The default "base date" for this form of Julian date is 12/31/4714 BC.

You may define your own base date for Julian date calculations by setting the runtime configuration variable "4GL-JULIAN-BASE-DATE." The value of this variable must have the format "YYYYMMDD". See the Acu4GL User's Guide for more information.

Using group items

You may place the DATE directive in front of a group item, so long as you also use the USE GROUP directive (see Example 2 below).

Example 1

$xfd date
    03 date-hired     pic 9(8).
    03 pay-scale      pic x(3).

The column date_hired will have eight digits and will be type DATE in the database, with a format of YYYYMMDD.

Example 2

*(( XFD DATE, USE GROUP ))
    03  date-hired.
      05   yyyy    pic 9(4).
      05   mm      pic 9(2).
      05   dd      pic 9(2).

This also will produce a column named date_hired with eight digits and type DATE in the database, format YYYYMMDD.

Example 3

*(( XFD DATE=EEEYYYY))
    03  date-sold      pic 9(7).
    03  sales-rep      pic x(30).

This will produce a column named date_sold with seven digits and type DATE in the database. The date will contain the day of the year (for example, February 1st would be 032), followed by the four-digit year, such as 1999).