Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 4: CICS COBOL Programming


EXEC CICS Statements

EXEC CICS statements are the commands your COBOL program uses to ask CICS for services: terminal I/O, file I/O, program control and more. This page explains their format and the options you will use most.

Format of an EXEC CICS statement

  • Every statement starts with EXEC CICS and ends with END-EXEC.
  • Between them comes the command name (for example, SEND TEXT, READ, LINK) followed by its options.
  • Options are written as keyword(value), for example LENGTH(15) or FILE('EMPFILE').
  • Code EXEC CICS statements in the Procedure Division, starting in Area B (columns 12 to 72).
  • A statement can continue over several lines. The period at the end closes the COBOL sentence, not the CICS command.
  • The translator checks every EXEC CICS statement for correct syntax before the compiler runs.

How options work

  • FROM(data-name) sends data out; INTO(data-name) brings data in; SET(pointer) returns an address.
  • LENGTH must match the size of the data you are sending or receiving.
  • RESP(data-name) captures the response code so you can check whether the command worked.
  • Always check RESP after file and terminal commands instead of assuming success.

Common EXEC CICS commands you will see

  • SEND TEXT / RECEIVE - simple terminal input and output (basic mapping support).
  • SEND MAP / RECEIVE MAP - formatted screen I/O using BMS maps (covered in Module 5).
  • READ / WRITE / REWRITE / DELETE - VSAM file access under CICS.
  • LINK / XCTL / RETURN - pass control between programs.
  • HANDLE CONDITION - tell CICS what to do when an error condition occurs.

Example: reading a file with response checking

  • The program below reads one record from EMPFILE and checks the response code.
  • DFHRESP(NORMAL) is a condition name the translator provides; you do not need to define it yourself.
EXEC CICS READ
           FILE('EMPFILE')
           INTO(EMP-RECORD)
           RIDFLD(EMP-ID)
           RESP(WS-RESP)
      END-EXEC.
IF WS-RESP = DFHRESP(NORMAL)
       PERFORM 2000-PROCESS-RECORD
ELSE
       PERFORM 9000-HANDLE-ERROR
END-IF.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant