In this article we will be specifying some of the basic commands for CICS in COBOL with examples. The basic definition of CICS is given in the article CICS in Mainframe – Basics.CICS commands are coded in a blocked structure having a beginning and end similar to that of DB2 commands within COBOL. The most visible aspect of CICS command is that they all have a common framework.

EXEC CICS

Function

[options]

END-EXEC.

This is the basic structure for CICS command. An example is RETURN.

EXEC CICS

RETURN

TRANSID(name)

COMMAREA(dataname)

LENGTH( datavalue)

END-EXEC.

In the above example, the TRANSID, COMMAREA and LENGTH are optional. But COMMAREA can be given only if there is a TRANSID and LENGTH can be given only if there is a COMMAREA.

COMMAREA can have only dataname while TRANSID and LENGTH can have both dataname and literals. When you use numeric literals directly, there is no issue of its datatype. But when you give the literal to a datavalue then the datavalue can be declared only in three formats.

Halfword binary item     –              PIC S9(4) COMP

Fullword binary item      –              PIC S9(9) COMP or PIC S9(8) COMP

Packed decimal item      –              PIC S9(7) COMP-3

As per IBM’s recommendation, all numeric values must be less than 24K.

SYNTAX TO RECEIVE AND SEND DATA WITH EXAMPLE

RECEIVE command:

EXEC CICS

RECEIVE

[INTO(dataname)]

LENGTH(dataname)

END-EXEC.

Length is given as dataname so as to get the exact length of the received data. Length must be defined as

LENGTH PIC S9(4) COMP.

Example of Receive:

* Declarartion part of receive command

01 WS-INPUT-FIELD.

05 WS-TRAN-FIELD          PIC X(4).

05 FILLER                              PIC X(1).

05 WS-DATA-FIELD          PIC X(15).

01 INPUT-LENGTH-FLD                  PIC S9(4) COMP.

*In procedure division

EXEC CICS

RECEIVE

INTO (WS-INPUT-FIELD)

LENGTH (INPUT-LENGTH-FLD)

END-EXEC.

If ‘C345’ is the transaction ID and data is some number like 949-59-497, then the screen after entering the transaction ID and data will look like,

C345,949-59-497

SEND command:

EXEC CICS

SEND TEXT

FROM (dataname)

[LENGTH( length)]

END-EXEC.

The SEND TEXT command sends a string of text characters, unformatted to the screen. Here, the length can be a literal or dataname. If dataname it must be defined as PIC S9(4) COMP.

Example of SEND:

*Declaration part for Send

01 RESPONSE-AREA.

05 FILLER                            PIC X(22) VALUE ‘Your search results: ’.

05 RESP-STATUS               PIC X(10).

*In procedure division

MOVE ‘Employee’ TO RESP-STATUS

EXEC CICS

SEND TEXT

FROM (RESPOSNE-AREA)

LENGTH(32)

END-EXEC.

The output will be like

Your search results: Employee

A complete COBOL program with CICS will look like the example given below.

A sample program to check if the ID given belongs to an employee or not.

 IDENTIFICATION DIVISION.PROGRAM ID.   SAMPLE.DATA DIVISION.

WORKING-STORAGE SECTION.

01           RESPONSE-AREA.

05 FILLER                            PIC X(22) VALUE ‘Your search result’.

05 RESP-STATUS               PIC X(15).

01           DATA-AREA.

05 TRANS-ID                       PIC X(4).

05 FILLER                            PIC X(1).

05 SSN                                   PIC X(11).

01           DATA-LENGTH                   PIC S9(4) COMP VALUE 16.

LINKAGE SECTION.

PROCEDURE DIVISION.

0000-MAIN-PARA.

PERFORM 1000-RECEIVE-DATA

THRU 1000-RECEIVE-DATA-EXIT

PERFORM 2000-VALIDATE-DATA

THRU 2000-VALIDATE-DATA-EXIT

PERFORM 3000-SEND-DATA

THRU 3000-SEND-DATA-EXIT

EXEC CICS

RETURN

END-EXEC.

0000-MAIN-PARA-EXIT.

EXIT.

1000-RECEIVE-DATA.

EXEC CICS

RECEIVE

INTO (DATA-AREA)

LENGTH (DATA-LENGTH)

END-EXEC.

1000-RECEIVE-DATA-EXIT.

EXIT.

2000-VALIDATE-PARA.

PERFORM 2500-CHECK-VALID-ID              ———not shown

THRU 2500-CHECK-VALID-ID-EXIT      ——–not shown

IF VALID-SSN

MOVE ‘Valid Employee’ TO RESP-STATUS

ELSE

MOVE ‘ Not an Employee’ TO RESP-STATUS

END-IF.

2000-VALIDATE-PARA-EXIT.

EXIT.

3000-SEND-RESPONSE.

EXEC CICS

SEND TEXT

FROM (RESPONSE-AREA)

LENGTH (36)

END-EXEC.

3000-SEND-RESPONSE-EXIT.

EXIT.

STOP RUN.

 

 

 

 

 

CICS Programming Basic in Mainframe
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *