Saturday, August 1, 2015

Date functions in cobol. Why and when do we use IGZEDT4 ,CEELOCT , CURRENT-DATE ?

We come across certain instance when we need to get the time/date in certain formats in cobol.
We all know that we can get the dates in cobol using ACCEPT verb in the following way.
                        ACCEPT WS-DATE FROM DATE
But we would not get it in the format we prefer to use ,say in the format YYYYMMDD.
DATE has the picture clause of PIC 9(6). So when we use the above cobol statement, we would get the date in the format like below when read  sequentially from left to right:
First 2 digits for the year of the century, next 2 for the month and next 2 digits with the date.
Example: This if the current date is 25-JUL-1994, we would get  as 940725.

VS cobol II does not support the date format giving results in YYYY format. However the results can be interpolated in many ways to get our desired result.Some of the utilities are described below.

For NON LE Cobol Environment 
1.IBM has offered a non-LE callable interface known as  IGZEDT4 which can be used to achieve our
desired function.  When we call it , it will give the desired result in the YYYYMMDD format.

01  WS-YYYYMMDD                         PIC  9(08).
01  WS-DATE-IGZEDT4                     PIC  X(08) VALUE 'IGZEDT4'.
*
CALL WS-IGZEDT4      USING WS-YYYYMMDD

2.  Another way to do this is to use the LE callable function CEELOCT. We need to check with the mainframe infrastructure team to know if LE is optionally installed in our LPAR. If yes, then we can call this function which returns the result in the format of YYYYMMDD.  CEELOCT returns the result in 3 formats.
 a: Lilian  Date
 b.Lilian Seconds
 c. Gregorian  character strings.
It also returns the feedback code(CEE000 if call is successful)  which decides whether the function executed successfully or not.

WORKING-STORAGE SECTION.
01 WS-LILIAN PIC S9(9) COMP.
01 WS-XSECONDS PIC S9(18) COMP.
01 WS-GREGORN PIC X(17).
01 WS-FC.
    03 CEEIGZCT-RC PIC X.
        88 CEE000 VALUE LOW-VALUE.
PROCEDURE DIVISION.
       MAIN-SECTION.
           CALL 'CEELOCT' USING WS-LILIAN
                                WS-XSECONDS
                                WS-GREGORN
                                WS-FC
           IF CEE000 OF WS-FC
             DISPLAY 'Time: '    WS-GREGORN
           ELSE
             DISPLAY 'CEELOCT error' UPON CONSOLE
           END-IF

For LE enabled environment

3.  CURRENT-DATE  FUNCTION has been introduced after cobol II, which makes life much simpler. It is a 21 byte alphanumeric value which contains the below fields when read from left to right .

01  WS-CURRENT-DATE-FIELDS.
             05  WS-CURRENT-DATE.
                 10  WS-CURRENT-YEAR    PIC  9(4).
                 10  WS-CURRENT-MONTH   PIC  9(2).
                 10  WS-CURRENT-DAY     PIC  9(2).
             05  WS-CURRENT-TIME.
                 10  WS-CURRENT-HOUR    PIC  9(2).
                 10  WS-CURRENT-MINUTE  PIC  9(2).
                 10  WS-CURRENT-SECOND  PIC  9(2).
                 10  WS-CURRENT-MS      PIC  9(2).
             05  WS-DIFF-FROM-GMT       PIC S9(4).
 We need to use the cobol code like below and use the appropriate values as per our requirement.
 MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-FIELDS

No comments:

Post a Comment