CICS Commands Coding


What is CICS Command-Level Coding?


CICS command-level coding refers to writing application programs that interact with the CICS environment using CICS-provided commands. These commands enable programs to utilize CICS services such as file handling, task management, communication with terminals, and database operations.

CICS commands are embedded in application programs and act as an interface between the program and CICS to perform specific tasks like reading a file, sending a message, or retrieving user input.

CICS operations are carried out by using specific CICS commands within the application program. To execute these commands, a command-level interface known as EXECUTE CICS or EXEC CICS is required. When a CICS service is needed, these commands must be coded between the EXEC CICS and END-EXEC statements to clearly distinguish them from the rest of the application program code. The commands placed between EXEC CICS and END-EXEC must be recognized by the CICS translator. This translator processes the commands and converts them into appropriate calls during the compilation process.

Syntax -

EXEC CICS <COMMAND>
    [OPTIONS]
    [RESP(response-variable)]
    [END-EXEC].
  • EXEC CICS: Indicates the start of a CICS command.
  • <COMMAND>: Specifies the operation to be performed, such as READ, WRITE, SEND, RECEIVE and many more.
  • OPTIONS: Includes additional parameters like file names, data areas, keys, and control flags required for the operation.
  • RESP: An optional parameter used to capture the response code from the command execution.
  • END-EXEC: Marks the end of the CICS command.

Short Examples -

Scenario1 - Sends data or messages to a terminal.

EXEC CICS SEND
    TEXT('Welcome to CICS')
    END-EXEC.

Scenario2 - Reads a record from a file.

EXEC CICS READ
    FILE(file-name)
    INTO(data-area)
    KEY(key-field)
    END-EXEC.

Scenario3 - Ends a transaction or returns control to CICS.

EXEC CICS RETURN
    END-EXEC.

Response Handling -


Response handling captures the result of a CICS command execution. It helps determine whether the command was successful or encountered an error.

Methods -

  1. RESP Option: Use the RESP option in a command to capture the response code in a variable.
    EXEC CICS READ
        FILE('CUSTOMER-FILE')
        INTO(DATA-AREA)
        KEY(ACCOUNT-NUMBER)
        RESP(RESPONSE-CODE)
        END-EXEC.
    	
    IF RESPONSE-CODE = NOTFOUND
        DISPLAY 'Record not found'
    ELSE IF RESPONSE-CODE = NORMAL
        DISPLAY 'Record retrieved successfully'
    END-IF.
  2. EIBRESP Field: The Execution Interface Block (EIB) contains the EIBRESP field, which automatically stores the response code after a command.
    EXEC CICS READ
        FILE('CUSTOMER-FILE')
        INTO(DATA-AREA)
        KEY(ACCOUNT-NUMBER)
        END-EXEC.
    	
    MOVE EIBRESP TO RESPONSE-CODE.

We will discuss the response and error handling concepts in futher chapters.