TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Date Function Example 1


How to get the Current Date/Time in a COBOL?

IDENTIFICATION DIVISION.
PROGRAM-ID. COBLDATE.
DATE-WRITTEN. SEP 2, 1990.
DATE-COMPILED. SEP 2, 1990.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-ZOS.
OBJECT-COMPUTER. IBM-ZOS.

DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 WS-CURRENT-DATE-DATA.
   05  WS-CURRENT-DATE.
       10  WS-CURRENT-YEAR         PIC 9(04).
       10  WS-CURRENT-MONTH        PIC 9(02).
       10  WS-CURRENT-DAY          PIC 9(02).
   05  WS-CURRENT-TIME.
       10  WS-CURRENT-HOURS        PIC 9(02).
       10  WS-CURRENT-MINUTE       PIC 9(02).
       10  WS-CURRENT-SECOND       PIC 9(02).
       10  WS-CURRENT-MILLISECONDS PIC 9(02).

PROCEDURE DIVISION.
0000-MAIN-PARA.
        INITIALIZE WS-CURRENT-DATE-DATA.
        MOVE FUNCTION CURRENT-DATE TO WS-CURRENT-DATE-DATA.
        DISPLAY WS-CURRENT-DATE-DATA.
9999-MAIN-EXIT.
      STOP RUN.

When you compile and execute the above program, it produces the following result −

2020122818242863-0000


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal