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

Module 9: CICS DB2 Integration


CICS DB2 Program Structure

A CICS DB2 program is an ordinary CICS COBOL program with SQL sections added. The SQL pieces live in fixed places in the program.

Where the SQL pieces go

  • WORKING-STORAGE SECTION - EXEC SQL INCLUDE SQLCA END-EXEC gives the program the SQL communication area.
  • WORKING-STORAGE SECTION - EXEC SQL INCLUDE member END-EXEC brings in the DCLGEN host structure that describes the table rows.
  • WORKING-STORAGE SECTION - declare host variables here, the COBOL items the SQL statements read and write.
  • PROCEDURE DIVISION - EXEC SQL statements sit alongside EXEC CICS commands like RECEIVE MAP, SEND MAP and SYNCPOINT.

Order of operations in a typical program

  • RECEIVE MAP to read the screen, then move the screen fields into host variables.
  • Run the EXEC SQL statement (SELECT, INSERT, UPDATE or DELETE).
  • Check SQLCODE immediately. On success, move host variables back to the screen fields.
  • SEND MAP to show the result, then EXEC CICS SYNCPOINT to commit, then RETURN.

The divisions, with SQL notes

  • IDENTIFICATION DIVISION - program name as usual. Nothing SQL-specific here.
  • DATA DIVISION - this is where INCLUDE SQLCA, the DCLGEN include and the host variables live.
  • PROCEDURE DIVISION - program logic mixing EXEC CICS commands and EXEC SQL statements. Every SQL statement ends with END-EXEC.
  • Keep SQL and CICS error checking together: check EIBRESP after CICS commands and SQLCODE after SQL statements.

Example

  • Skeleton of a CICS DB2 inquiry program. The SQL parts are the INCLUDE lines and the SELECT in the PROCEDURE DIVISION.
  • IDENTIFICATION DIVISION. PROGRAM-ID. CUSTINQ. DATA DIVISION. WORKING-STORAGE SECTION. EXEC SQL INCLUDE SQLCA END-EXEC. EXEC SQL INCLUDE CUSTOMER END-EXEC. 01 WS-CUST-NO PIC X(6). 01 WS-CUST-NAME PIC X(30). PROCEDURE DIVISION. 0000-MAIN-LOGIC. EXEC CICS RECEIVE MAP('CUSTMAP') MAPSET('CUSTSET') INTO(CUSTMAP-INPUT) END-EXEC. MOVE CUSTNOI TO WS-CUST-NO. EXEC SQL SELECT CUSTNAME INTO :WS-CUST-NAME FROM CUSTOMER WHERE CUSTNO = :WS-CUST-NO END-EXEC. IF SQLCODE = 0 MOVE WS-CUST-NAME TO CUSTNAMEO EXEC CICS SEND MAP('CUSTMAP') MAPSET('CUSTSET') FROM(CUSTMAP-OUTPUT) ERASE END-EXEC END-IF. EXEC CICS SYNCPOINT END-EXEC. EXEC CICS RETURN END-EXEC.
  • Notice the program never uses EXEC SQL COMMIT. The commit is done with EXEC CICS SYNCPOINT.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant