A FORMAT clause defines an implicit PICTURE clause. Although there is no PICTURE character-string that can easily describe a date or time item, for some formats, an approximate definition does exist. For example, a date item with a FORMAT '%y,%m,%d' is similar to the PICTURE 99/99/99, where the '/' PICTURE symbol is replaced with a ','.
The LOCALE phrase specifies the culturally-appropriate format of the date, time, or timestamp item.
When the LOCALE phrase is specified, without literal-2, the format and separator used for the date and time items is completely based on the locale.
When the LOCALE phrase is specified with literal-2, literal-2 determines the format of the item, but the conversion specifications are replaced with items based on the locale.
The LOCALE OF special register returns the equivalent of a locale mnemonic-name associated with the specified data item. If the data item does not have a locale associated with it, the keyword COBOL is returned. The LOCALE OF special register cannot be modified, and can only be specified in the PROCEDURE DIVISION where a locale mnemonic-name is allowed.
A date-time data item can be used in expressions using the LOCALE OF special register.
In DDS, a date data type's format is specified with the DATFMT parameter. Valid DATFMT parameters include *MDY and *ISO. Along with the DATFMT keyword, a DATSEP keyword specifies a one-character value to be used as a separator between the month, day, and year value. A complete list of DATFMT parameters and their allowed DDS Date separators, along with their COBOL format literal equivalents, is shown in Table 10.
In DDS, a time data type's format is specified with the TIMFMT
parameter. Valid TIMFMT parameters include *HMS and *ISO. Along
with the TIMFMT keyword, a TIMSEP keyword specifies a one-character value to
be used as a separator between the hours, minutes, and second value. A
complete list of TIMFMT parameters and their allowed DDS Time separators,
along with their COBOL format literal equivalents, is shown in Table 11.
Table 10. DDS Date Data Types and Their Equivalent ILE COBOL Format
| OS/400 Format | COBOL-Generated Format | Description | Format | Valid Separators | Length |
|---|---|---|---|---|---|
| *MDY | %m/%d/%y | Month/Day/Year | mm/dd/yy | /-.,space | 8 |
| *DMY | %d/%m/%y | Day/Month/Year | dd/mm/yy | /-.,space | 8 |
| *YMD | %y/%m/%d | Year/Month/Day | yy/mm/dd | /-.,space | 8 |
| *JUL | %y/%j | Julian | yy/ddd | /-.,space | 6 |
| *ISO | @Y-%m-%d | International Standards Organization | yyyy-mm-dd | - | 10 |
| *USA | %m/%d/@Y | IBM USA Standard | mm/dd/yyyy | / | 10 |
| *EUR | %d.%m.@Y | IBM European Standard | dd.mm.yyyy | . | 10 |
| *JIS | @Y-%m-%d | Japanese Industrial Standard Christian Era | yyyy-mm-dd | - | 10 |
Table 11. DDS Time Data Types and Their Equivalent ILE COBOL Format
| OS/400 Format | COBOL-Generated Format | Description | Format | Valid Separators | Length |
|---|---|---|---|---|---|
| *HMS | %H:%M:%S | Hours:Minutes:Seconds | hh:mm:ss | :.,space | 8 |
| *ISO | %H.%M.%S | International Standards Organization | hh.mm.ss | . | 8 |
| *USA | %I:%M @p | IBM USA Standard. AM and PM can be any mix of upper and lower case. | hh:mm AM or hh:mm PM | : | 8 |
| *EUR | %H.%M.%S | IBM European Standard | hh.mm.ss | . | 8 |
| *JIS | %H:%M:%S | Japanese Industrial Standard Christian Era | hh:mm:ss | : | 8 |
The FORMAT OF phrase of the PROCEDURE DIVISION creates an implicit special register, called the FORMAT OF special register, whose contents equal the FORMAT literal of the data item referenced by the identifier. The FORMAT OF special register can only be specified for data items of class date-time. The length of this special register depends on the literal or locale specified in the FORMAT phrase for the data item.
The FORMAT OF special register has the implicit definition:
USAGE DISPLAY, PICTURE X(n)
where n equals the number of bytes of the implicit or explicit
FORMAT literal.
For example, consider the following data description entry for date data item date2:
05 date2 FORMAT DATE IS '%d,%m,%y'.
The following MOVE statement uses the intrinsic function CONVERT-DATE-TIME to convert date data item date3 into the format of date data item date2. The FORMAT OF phrase creates an implicit special register whose content would be %d,%m,%y.
MOVE FUNCTION CONVERT-DATE-TIME(date3, DATE, FORMAT OF date2)
TO alpha-num-date.
The length of the special register in this example is 8.
The following rules apply:
+----------------------------End of IBM Extension----------------------------+
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.