Progress0 of 0 lessons

CICS FORMATTIME - Time Formatting

CICS FORMATTIME provides time formatting capabilities for programs and transactions. It enables programs to format time values, display date/time information, and handle time formatting in CICS environments.

What is CICS FORMATTIME?

CICS FORMATTIME is a command that allows programs to format time values for display purposes. It provides time formatting capabilities, date/time display, and time formatting for CICS applications.

Command Syntax

cobol
1
2
3
4
5
6
7
EXEC CICS FORMATTIME FROMTIME(input-time) TOTIME(output-time) [FROMFORMAT(input-format)] [TOFORMAT(output-format)] [RESP(response-code)] END-EXEC

Parameters

Required Parameters

  • FROMTIME(input-time) - Input time to format
  • TOTIME(output-time) - Output formatted time

Optional Parameters

  • FROMFORMAT(input-format) - Input time format
  • TOFORMAT(output-format) - Output time format
  • RESP(response-code) - Response code variable

Time Format Types

Display Formats

Time display formats

  • HH:MM:SS - Hour:Minute:Second format
  • HH:MM - Hour:Minute format
  • MM/DD/YYYY - US date format
  • DD/MM/YYYY - European date format

Standard Formats

Standard time formats

  • YYYYMMDD - Year Month Day format
  • HHMMSS - Hour Minute Second format
  • YYYYMMDDHHMMSS - Combined format
  • YYYY-DD-MM - ISO date format

Custom Formats

Custom time formats

  • READABLE DATE - Human readable date
  • READABLE TIME - Human readable time
  • READABLE DATETIME - Human readable datetime
  • LOCALIZED FORMAT - Localized format

Specialized Formats

Specialized time formats

  • UNIX TIMESTAMP - Unix timestamp format
  • JULIAN DATE - Julian date format
  • EPOCH TIME - Epoch time format
  • UTC TIME - UTC time format

Programming Examples

Basic Time Formatting

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
IDENTIFICATION DIVISION. PROGRAM-ID. FORMATTIME01. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-TIME PIC X(14) VALUE '20231225143000'. 01 OUTPUT-TIME PIC X(19). 01 INPUT-FORMAT PIC X(14) VALUE 'YYYYMMDDHHMMSS'. 01 OUTPUT-FORMAT PIC X(19) VALUE 'YYYY-MM-DD HH:MM:SS'. 01 RESPONSE-CODE PIC S9(8) COMP. PROCEDURE DIVISION. DISPLAY 'Formatting time for display' DISPLAY 'Input: ' INPUT-TIME EXEC CICS FORMATTIME FROMTIME(INPUT-TIME) TOTIME(OUTPUT-TIME) FROMFORMAT(INPUT-FORMAT) TOFORMAT(OUTPUT-FORMAT) RESP(RESPONSE-CODE) END-EXEC IF RESPONSE-CODE = DFHRESP(NORMAL) DISPLAY 'Time formatting successful' DISPLAY 'Output: ' OUTPUT-TIME ELSE DISPLAY 'Time formatting failed' END-IF EXEC CICS RETURN END-EXEC.

Advanced Time Formatting

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
IDENTIFICATION DIVISION. PROGRAM-ID. FORMATTIME02. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-TIME PIC X(14). 01 OUTPUT-TIME PIC X(19). 01 INPUT-FORMAT PIC X(14). 01 OUTPUT-FORMAT PIC X(19). 01 RESPONSE-CODE PIC S9(8) COMP. 01 FORMAT-COUNT PIC S9(2) COMP VALUE 0. 01 MAX-FORMATS PIC S9(2) COMP VALUE 3. 01 TIME-LIST. 05 TIME-ITEM OCCURS 3 TIMES. 10 TIME-INPUT PIC X(14). 10 TIME-OUTPUT PIC X(19). 10 TIME-INPUT-FMT PIC X(14). 10 TIME-OUTPUT-FMT PIC X(19). PROCEDURE DIVISION. PERFORM INITIALIZE-TIMES PERFORM FORMAT-MULTIPLE-TIMES EXEC CICS RETURN END-EXEC. INITIALIZE-TIMES. MOVE '20231225143000' TO TIME-INPUT(1) MOVE 'YYYY-MM-DD HH:MM:SS' TO TIME-OUTPUT-FMT(1) MOVE 'YYYYMMDDHHMMSS' TO TIME-INPUT-FMT(1) MOVE '20231225' TO TIME-INPUT(2) MOVE 'YYYY-MM-DD' TO TIME-OUTPUT-FMT(2) MOVE 'YYYYMMDD' TO TIME-INPUT-FMT(2) MOVE '143000' TO TIME-INPUT(3) MOVE 'HH:MM:SS' TO TIME-OUTPUT-FMT(3) MOVE 'HHMMSS' TO TIME-INPUT-FMT(3). FORMAT-MULTIPLE-TIMES. PERFORM VARYING FORMAT-COUNT FROM 1 BY 1 UNTIL FORMAT-COUNT > MAX-FORMATS MOVE TIME-INPUT(FORMAT-COUNT) TO INPUT-TIME MOVE TIME-INPUT-FMT(FORMAT-COUNT) TO INPUT-FORMAT MOVE TIME-OUTPUT-FMT(FORMAT-COUNT) TO OUTPUT-FORMAT PERFORM FORMAT-SINGLE-TIME IF RESPONSE-CODE = DFHRESP(NORMAL) MOVE OUTPUT-TIME TO TIME-OUTPUT(FORMAT-COUNT) DISPLAY 'Format ' FORMAT-COUNT ' successful' DISPLAY 'Output: ' TIME-OUTPUT(FORMAT-COUNT) ELSE DISPLAY 'Format ' FORMAT-COUNT ' failed' END-IF END-PERFORM. FORMAT-SINGLE-TIME. EXEC CICS FORMATTIME FROMTIME(INPUT-TIME) TOTIME(OUTPUT-TIME) FROMFORMAT(INPUT-FORMAT) TOFORMAT(OUTPUT-FORMAT) RESP(RESPONSE-CODE) END-EXEC.

Error Handling with Time Formatting

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
IDENTIFICATION DIVISION. PROGRAM-ID. FORMATTIME03. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-TIME PIC X(14) VALUE '20231225143000'. 01 OUTPUT-TIME PIC X(19). 01 INPUT-FORMAT PIC X(14) VALUE 'YYYYMMDDHHMMSS'. 01 OUTPUT-FORMAT PIC X(19) VALUE 'YYYY-MM-DD HH:MM:SS'. 01 RESPONSE-CODE PIC S9(8) COMP. 01 RETRY-COUNT PIC S9(2) COMP VALUE 0. 01 MAX-RETRIES PIC S9(2) COMP VALUE 3. 01 FORMAT-SUCCESSFUL PIC X(1) VALUE 'N'. PROCEDURE DIVISION. PERFORM FORMAT-TIME-WITH-RETRY EXEC CICS RETURN END-EXEC. FORMAT-TIME-WITH-RETRY. PERFORM FORMAT-TIME IF RESPONSE-CODE NOT = DFHRESP(NORMAL) AND RETRY-COUNT < MAX-RETRIES ADD 1 TO RETRY-COUNT DISPLAY 'Retry ' RETRY-COUNT ' time formatting' PERFORM FORMAT-TIME-WITH-RETRY END-IF. FORMAT-TIME. EXEC CICS FORMATTIME FROMTIME(INPUT-TIME) TOTIME(OUTPUT-TIME) FROMFORMAT(INPUT-FORMAT) TOFORMAT(OUTPUT-FORMAT) RESP(RESPONSE-CODE) END-EXEC EVALUATE RESPONSE-CODE WHEN DFHRESP(NORMAL) MOVE 'Y' TO FORMAT-SUCCESSFUL DISPLAY 'Time formatting successful' WHEN DFHRESP(NOTAUTH) DISPLAY 'Not authorized for time formatting' WHEN DFHRESP(INVREQ) DISPLAY 'Invalid time formatting request' WHEN DFHRESP(TIMEERR) DISPLAY 'Time formatting error' WHEN DFHRESP(FORMATERR) DISPLAY 'Time format error' WHEN DFHRESP(INVALIDTIME) DISPLAY 'Invalid time value' WHEN OTHER DISPLAY 'Unexpected time formatting error' END-EVALUATE.

Time Formatting Management

Format Operations

  • Time Formatting - Format time values
  • Format Validation - Validate time formats
  • Format Conversion - Convert between formats
  • Format Display - Display formatted time

Format Analysis

  • Format Parsing - Parse time formats
  • Format Classification - Classify time formats
  • Format Filtering - Filter time formats
  • Format Aggregation - Aggregate time formats

Format Storage

  • Format Storage - Store time formats
  • Format Archiving - Archive time formats
  • Format Indexing - Index time formats
  • Format Retrieval - Retrieve stored formats

Error Recovery

  • Error Detection - Detect formatting errors
  • Error Recovery - Recover from formatting errors
  • Retry Mechanisms - Implement retry logic
  • Fallback Procedures - Use fallback procedures

Error Handling

Common Response Codes

  • DFHRESP(NORMAL) - Time formatting successful
  • DFHRESP(NOTAUTH) - Not authorized for time formatting
  • DFHRESP(INVREQ) - Invalid time formatting request
  • DFHRESP(TIMEERR) - Time formatting error
  • DFHRESP(FORMATERR) - Time format error
  • DFHRESP(INVALIDTIME) - Invalid time value

Performance Considerations

Formatting Efficiency

  • Optimize formatting operations - Use efficient formatting
  • Minimize formatting overhead - Reduce formatting overhead
  • Use formatting caching - Implement formatting caching
  • Monitor formatting frequency - Track formatting patterns

System Impact

  • Monitor system impact - Track formatting impact
  • Optimize formatting handling - Ensure efficient formatting
  • Manage formatting usage - Monitor formatting consumption
  • Track performance metrics - Monitor formatting performance

Best Practices

Time Formatting Best Practices

  • • Use appropriate time formats for your needs
  • • Implement proper error handling for formatting operations
  • • Validate time values before formatting
  • • Use appropriate formatting techniques
  • • Monitor time formatting activities and performance
  • • Maintain time formatting audit trails
  • • Handle time formatting errors gracefully

Explain It Like I'm 5 Years Old

Think of CICS FORMATTIME like changing how you write the time:

  • Different Ways: "There are different ways to write time" - Different formats
  • Change Format: "Change from one way to another" - Format time
  • Same Time: "It's the same time, just written differently" - Same value, different format
  • Choose Format: "Choose the format you want" - Select output format
  • Get New Time: "Get the time in the new format" - Receive formatted time

Exercises

Exercise 1: Basic Time Formatting

Create a program that formats time between different formats.

Exercise 2: Advanced Time Formatting

Write a program that manages multiple time formatting operations.

Exercise 3: Error Handling

Implement comprehensive error handling for time formatting failures.