FORMATTIME


The CICS FORMATTIME statement converts a binary timestamp (absolute time) into a human-readable date and time format. Since ASKTIME returns the system time in a packed decimal format, using FORMATTIME is important to make this information readable.

FORMATTIME is commonly used for:

  • Displaying timestamps in a human-readable format (e.g., YYYY-MM-DD HH:MM:SS).
  • Logging and reporting transactions with precise timestamps.
  • Comparing and formatting timestamps received from other CICS commands.

Syntax -

EXEC CICS FORMATTIME
     ABSTIME(timestamp-data-area)
     DATE(date-data-area)
	 [FULLDATE(date-area)]
	 [DATEFORM(date-area) DATESEP(date-value)]
	 [DAYCOUNT(date-area)] 
	 [DAYOFMONTH(date-area)] [DAYOFWEEK(date-area)]
	 [DDMMYY(data-area)] [DDMMYYYY (date-area)]
	 [MILLISECONDS(date-area)] 
	 [MMDDYYYY (date-area)] [MONTHOFYEAR(date-area)]
     TIME(time-data-area) [TIMESEP(date-area)]
	 [YEAR(data-area)] [YYDDD(data-area)]
	 [YYDDMM(data-area)] [YYMMDD(date-area)]
	 [YYYYDDD(data-area)] [YYYYDDMM(date-area)] 
     [YYYYMMDD(date-area)] [DATESTRING(date-area)]
     [STRINGFORMAT(cvda)]
     [RESP(response-field)]
     [RESP2(response-field2)]
     END-EXEC.
  • ABSTIME(timestamp-data-area) - Specifies the binary timestamp to be converted (from ASKTIME).
  • DATE(date-data-area) - Converts the timestamp into a human-readable date.
  • TIME(time-data-area) - Converts the timestamp into a human-readable time.
  • FULLDATE(date-area) - Specifies the 10-character user field in which CICS returns the date in the format specified in the DATFORM parameter with the year expanded to 4 digits.
  • DATEFORM(date-area) - Specifies the format of the installation-defined date. CICS returns YYMMDD, DDMMYY or MMDDYY according to the DATFORM parameter.
  • DATESEP(date-value) - Specifies the character to be inserted as the separator between the day, month and year.
  • DDMMYYYY (date-area) ... YYYYMMDD(date-area) - Specifies the output format of the date.
  • DATESTRING(data-area) - Specifies the 64-character user field updated by CICS with date and time stamp string in the format that is specified by the STRINGFORMAT option.
  • RESP(response-variable) - Optional. It captures the response code of the FORMATTIME operation and used to check if the command executed successfully or encountered an error.
  • RESP2(response2-variable) - Optional. It captures the response2 code of the FORMATTIME operation when the error occured.

Short Examples -


Scenario - Retrieving the System Time and formatting it

...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TRANS-ID    PIC X(4)  VALUE 'TRN1'. 
01 WS-RESP        PIC S9(4) COMP.

PROCEDURE DIVISION.

    EXEC CICS ASKTIME
         ABSTIME(WS-TIMESTAMP)
         RESP(WS-RESP)
         END-EXEC.

    IF WS-RESP = DFHRESP(NORMAL) THEN
        EXEC CICS FORMATTIME
             ABSTIME(WS-TIMESTAMP)
             DATE(WS-DATE)
             TIME(WS-TIME)
             RESP(WS-RESP)
             END-EXEC 
	ELSE
		...
	END-IF.

	...

ASKTIME fetches the system time in binary format (WS-TIMESTAMP). FORMATTIME converts the binary timestamp into human-readable WS-DATE and WS-TIME. The formatted date and time are displayed for verification.

Error Conditions -


Eror Condition RESP RESP2 Reason
INVREQ 16 1 The ABSTIME value is less than zero or not in packed-decimal format.
16 2 Invalid CVDA value for the STRINGFORMAT option.