MainframeMaster
Progress0 of 0 lessons

CICS EXEC CICS Commands

Master the fundamental EXEC CICS commands that form the backbone of CICS application development. Learn program control, terminal control, file operations, and more to build robust CICS applications.

Why EXEC CICS Commands Matter

EXEC CICS commands are the building blocks of CICS applications. They provide the interface between your application programs and CICS services, enabling you to control programs, manage data, handle terminals, and coordinate transactions.

Program Control

Link programs, transfer control, and manage program execution flow within CICS.

Data Management

Read, write, and manage files, temporary storage, and transient data queues.

Terminal Control

Send and receive data from terminals, manage screen displays, and handle user input.

Program Control Commands

Program control commands manage the execution flow of programs within CICS. They enable you to link programs, transfer control, and manage program resources effectively.

LINK Command

Purpose: Call another program and return to caller

Syntax: EXEC CICS LINK PROGRAM('program-name')

Data Passing: COMMAREA or CHANNEL

Return: Always returns to calling program

LINK Example:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
IDENTIFICATION DIVISION. PROGRAM-ID. MAINPROG. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-COMMAREA. 05 WS-CUSTOMER-ID PIC X(10). 05 WS-CUSTOMER-NAME PIC X(30). PROCEDURE DIVISION. * Get customer ID from terminal EXEC CICS RECEIVE INTO(WS-CUSTOMER-ID) END-EXEC * Link to customer processing program EXEC CICS LINK PROGRAM('CUSTPROC') COMMAREA(WS-COMMAREA) END-EXEC * Display result EXEC CICS SEND FROM(WS-COMMAREA) END-EXEC EXEC CICS RETURN END-EXEC.

XCTL Command

Purpose: Transfer control to another program

Syntax: EXEC CICS XCTL PROGRAM('program-name')

Data Passing: COMMAREA or CHANNEL

Return: Never returns to calling program

XCTL Example:

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
IDENTIFICATION DIVISION. PROGRAM-ID. MENUPROG. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-COMMAREA. 05 WS-FUNCTION PIC X(1). 88 INQUIRY VALUE 'I'. 88 UPDATE VALUE 'U'. 88 DELETE VALUE 'D'. PROCEDURE DIVISION. * Get function selection from user EXEC CICS RECEIVE INTO(WS-COMMAREA) END-EXEC * Transfer control based on function EVALUATE TRUE WHEN INQUIRY EXEC CICS XCTL PROGRAM('CUSTINQ') COMMAREA(WS-COMMAREA) END-EXEC WHEN UPDATE EXEC CICS XCTL PROGRAM('CUSTUPD') COMMAREA(WS-COMMAREA) END-EXEC WHEN DELETE EXEC CICS XCTL PROGRAM('CUSTDEL') COMMAREA(WS-COMMAREA) END-EXEC END-EVALUATE.

Other Program Control Commands

LOAD Command:

cobol
1
2
3
4
5
6
* Load program into memory EXEC CICS LOAD PROGRAM('PROGNAME') END-EXEC * Load with specific length EXEC CICS LOAD PROGRAM('PROGNAME') LENGTH(WS-PROG-LENGTH) END-EXEC

Loads a program into memory without executing it. Useful for pre-loading frequently used programs.

RELEASE Command:

cobol
1
2
3
4
5
* Release program from memory EXEC CICS RELEASE PROGRAM('PROGNAME') END-EXEC * Release all programs EXEC CICS RELEASE PROGRAM('*') END-EXEC

Removes a program from memory to free up storage space.

Terminal Control Commands

Terminal control commands manage communication between CICS programs and user terminals. They handle sending data to screens, receiving user input, and managing terminal sessions.

SEND Command

Purpose: Send data to terminal screen

Syntax: EXEC CICS SEND FROM(data-area)

Options: MAP, MAPSET, ERASE, ALARM

Use Cases: Display screens, messages, prompts

SEND Examples:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
* Send simple text message EXEC CICS SEND FROM('HELLO WORLD') END-EXEC * Send with map and mapset EXEC CICS SEND MAP('CUSTMAP') MAPSET('CUSTSET') FROM(WS-CUSTOMER-DATA) END-EXEC * Send with screen clearing EXEC CICS SEND FROM(WS-MESSAGE) ERASE END-EXEC * Send with alarm EXEC CICS SEND FROM('ERROR MESSAGE') ALARM END-EXEC

RECEIVE Command

Purpose: Receive data from terminal

Syntax: EXEC CICS RECEIVE INTO(data-area)

Options: MAP, MAPSET, LENGTH

Use Cases: Get user input, form data

RECEIVE Examples:

cobol
1
2
3
4
5
6
7
8
9
10
11
* Receive simple input EXEC CICS RECEIVE INTO(WS-USER-INPUT) END-EXEC * Receive with map and mapset EXEC CICS RECEIVE MAP('CUSTMAP') MAPSET('CUSTSET') INTO(WS-CUSTOMER-DATA) END-EXEC * Receive with length checking EXEC CICS RECEIVE INTO(WS-INPUT) LENGTH(WS-INPUT-LENGTH) END-EXEC

Advanced Terminal Control

CONVERSE Command:

cobol
1
2
3
4
* Send and receive in one command EXEC CICS CONVERSE FROM(WS-MESSAGE) INTO(WS-RESPONSE) LENGTH(WS-RESP-LENGTH) END-EXEC

Combines SEND and RECEIVE operations for conversational programming.

SEND TEXT Command:

cobol
1
2
3
4
* Send text with formatting EXEC CICS SEND TEXT FROM(WS-MESSAGE) LENGTH(WS-MSG-LENGTH) ERASE END-EXEC

Sends text data with specific formatting and control options.

File Control Commands

File control commands manage data access to VSAM files, databases, and other data sources. They provide the interface for reading, writing, updating, and deleting records.

READ Command

Purpose: Read records from files

Syntax: EXEC CICS READ FILE('filename')

Options: INTO, RIDFLD, KEYLENGTH

Use Cases: Retrieve customer data, lookup records

READ Examples:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
* Read by key EXEC CICS READ FILE('CUSTFILE') INTO(WS-CUSTOMER-RECORD) RIDFLD(WS-CUSTOMER-ID) END-EXEC * Read with error handling EXEC CICS READ FILE('CUSTFILE') INTO(WS-CUSTOMER-RECORD) RIDFLD(WS-CUSTOMER-ID) RESP(WS-RESPONSE) END-EXEC * Check response IF WS-RESPONSE = DFHRESP(NORMAL) PERFORM PROCESS-CUSTOMER ELSE PERFORM HANDLE-ERROR END-IF

WRITE Command

Purpose: Write new records to files

Syntax: EXEC CICS WRITE FILE('filename')

Options: FROM, RIDFLD, KEYLENGTH

Use Cases: Add new customers, create records

WRITE Examples:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
* Write new record EXEC CICS WRITE FILE('CUSTFILE') FROM(WS-CUSTOMER-RECORD) RIDFLD(WS-CUSTOMER-ID) END-EXEC * Write with error handling EXEC CICS WRITE FILE('CUSTFILE') FROM(WS-CUSTOMER-RECORD) RIDFLD(WS-CUSTOMER-ID) RESP(WS-RESPONSE) END-EXEC * Check for duplicate key IF WS-RESPONSE = DFHRESP(DUPREC) PERFORM HANDLE-DUPLICATE END-IF

Other File Control Commands

REWRITE Command:

cobol
1
2
3
* Update existing record EXEC CICS REWRITE FILE('CUSTFILE') FROM(WS-CUSTOMER-RECORD) END-EXEC

Updates an existing record that was previously read.

DELETE Command:

cobol
1
2
3
* Delete record EXEC CICS DELETE FILE('CUSTFILE') RIDFLD(WS-CUSTOMER-ID) END-EXEC

Removes a record from the file.

Browse Operations:

cobol
1
2
3
4
5
6
7
8
9
10
11
* Start browse EXEC CICS STARTBR FILE('CUSTFILE') RIDFLD(WS-START-KEY) END-EXEC * Read next record EXEC CICS READNEXT FILE('CUSTFILE') INTO(WS-CUSTOMER-RECORD) RIDFLD(WS-CURRENT-KEY) END-EXEC * End browse EXEC CICS ENDBR FILE('CUSTFILE') END-EXEC

Browse operations allow sequential access to file records.

TS/TD Queue Control Commands

Temporary Storage (TS) and Transient Data (TD) commands manage data queues for temporary storage and inter-program communication within and across CICS regions.

Temporary Storage (TS)

Purpose: Temporary data storage within region

Scope: Region-specific storage

Persistence: Survives transaction boundaries

Use Cases: Work-in-progress, temporary results

TS Commands:

cobol
1
2
3
4
5
6
7
8
9
10
* Write to TS queue EXEC CICS WRITEQ TS QUEUE('WORKDATA') FROM(WS-WORK-AREA) END-EXEC * Read from TS queue EXEC CICS READQ TS QUEUE('WORKDATA') INTO(WS-WORK-AREA) END-EXEC * Delete TS queue EXEC CICS DELETEQ TS QUEUE('WORKDATA') END-EXEC

Transient Data (TD)

Purpose: Data transfer between regions

Scope: Cross-region communication

Persistence: Survives region restarts

Use Cases: Inter-region messaging, logging

TD Commands:

cobol
1
2
3
4
5
6
7
8
9
* Write to TD queue EXEC CICS WRITEQ TD QUEUE('MSGQUEUE') FROM(WS-MESSAGE) LENGTH(WS-MSG-LENGTH) END-EXEC * Read from TD queue EXEC CICS READQ TD QUEUE('MSGQUEUE') INTO(WS-MESSAGE) LENGTH(WS-MSG-LENGTH) END-EXEC

Task Control Commands

Task control commands manage the execution of CICS tasks, including timing, synchronization, and task coordination. They provide control over task lifecycle and behavior.

DELAY Command

Purpose: Pause task execution

Syntax: EXEC CICS DELAY INTERVAL(time)

Options: INTERVAL, TIME

Use Cases: Rate limiting, polling delays

DELAY Examples:

cobol
1
2
3
4
5
6
7
8
9
* Delay for 5 seconds EXEC CICS DELAY INTERVAL(5) END-EXEC * Delay until specific time EXEC CICS DELAY TIME('14:30:00') END-EXEC * Delay with error handling EXEC CICS DELAY INTERVAL(10) RESP(WS-RESPONSE) END-EXEC

SYNCPOINT Command

Purpose: Commit or rollback changes

Syntax: EXEC CICS SYNCPOINT

Options: ROLLBACK, COMMIT

Use Cases: Transaction consistency, error recovery

SYNCPOINT Examples:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
* Commit changes EXEC CICS SYNCPOINT END-EXEC * Rollback changes EXEC CICS SYNCPOINT ROLLBACK END-EXEC * Commit with error handling EXEC CICS SYNCPOINT RESP(WS-RESPONSE) END-EXEC * Check response IF WS-RESPONSE = DFHRESP(NORMAL) PERFORM SUCCESS-PROCESSING ELSE PERFORM ERROR-HANDLING END-IF

Other Task Control Commands

POST Command:

cobol
1
2
3
4
* Post event to another task EXEC CICS POST INTERVAL(0) PROGRAM('NOTIFY') COMMAREA(WS-NOTIFICATION) END-EXEC

Posts an event to another task for asynchronous communication.

WAIT Command:

cobol
1
2
* Wait for event EXEC CICS WAIT EVENT(WS-EVENT-NAME) END-EXEC

Pauses task execution until a specific event occurs.

Quick Quiz

Question 1:

What is the difference between LINK and XCTL commands?

Question 2:

When would you use the SYNCPOINT command?

Question 3:

What are the main differences between TS and TD queues?