Sunday, January 22, 2017

CICS TSQ Handling

Normally, temporary storage control maintains TSQ’s in single VSAM ESDS called temporary storage file or DFHTEMP. For pseudo conversational programs, that’s an efficient way to store data between program executions. The one big advantage the TSQ’s have over communication area is that it makes better use of the systems resources by not tying up the main memory for long periods of time.

One can also store the TSQ’s on disks as Temporary Storage Control allows that but that means overheads in storing and retrieving the data in a single task execution. But if we specify main storage over disk, the processing is faster at the cost of critical main memory in the CICS system.

1. Write to a TSQ (creates the Q if not present already)

            EXEC CICS
                        WRITEQ TS QUEUE(TS-QUEUE-NAME)
                                             FROM(TS-QUEUE-RECORD)
                                             LENGTH(TS-QUEUE-LENGTH)
                                            [ MAIN ]
                                            [ AUXIALLIARY ]
            END-EXEC.
           
TS-QUEUE-LENGTH : PIC S9(4) COMP FIELD (Half-Word binary).
TS-QUEUE-NAME     : 1 TO 8 CHARACTER name that should be unique to avoid using other TSQ’s.
MAIN/AUXIALLIARY  : Specifies that TSQ shall reside on main/disk storage. OPTIONAL FIELDS.

2. Update an existing record.
           
            EXEC CICS
                        WRITEQ TS QUEUE(TS-QUEUE-NAME)
                                             FROM(TS-QUEUE-RECORD)
                                             LENGTH(TS-QUEUE-LENGTH)
                                             ITEM(TS-ITEM-NUMBER)
                                             REWRITE
                                             RESP(RESPONSE-CODE)
            END-EXEC.

Within a TSQ, each record is assigned an ITEM-NUMBER just like an array-index. The item #s start from 1,2,…..To rewrite a record in the TSQ you need to specify the item number of the record to be updated. Since most TSQ’s have one record only that is updated, its never a problem. In case a TSQ name is not found it raises a QIDERR. In case it doesn’t find the item-number, then an ITEMERR is raised.

3. To read from a TSQ :

            EXEC CICS
                        READQ TS QUEUE(TS-QUEUE-NAME)
                                          INTO(TS-QUEUE-RECORD)
                                          LENGTH(TS-QUEUE-LENGTH)
                                          ITEM(TS-ITEM-NUMBER)
                                          RESP(RESPONSE-CODE)
                                          [  NEXT ]               
            END-EXEC.

NEXT : Specifies that the next record in the sequence following the most recently read record should be read. OPTIONAL         
            parameter. Its always a good practice to use the item #.

            In case of a readq also, the possible exceptions are QIDERR and ITEMERR. The response code can be used to handle an abnormal termination as in any CICS program.

4. Deleting a TSQ :
           
            EXEC CICS
DELETEQ TS QUEUE(TS-QUEUE-NAME)
            END-EXEC.     

            this command needs to be issued explicitly after the completion of processing to delete the TSQ. If we do not, then the TSQ remains indefinitely wasting storage space. The command deletes the entire TSQ and not just the record. That shouldn’t be problem either coz most of the times the TSQ is going to have a single entry.         


All the variables used will be defined in the working storage before you can use these lines of code in your program. Something like……

WORKING-STORAGE DIVISION.
           
            01  TSQ-AREA.
                       
                  05  TS-QUEUE-RECORD           PIC X(100).
                  05  TS-QUEUE-NAME                PIC X(8).
                  05  TS-QUEUE-LENGTH            PIC S9(4) COMP.
                  05  TS-ITEM-NUMBER                PIC 9(02).  
             ……………………………….
PROCEDURE DIVISION.
………………

2000-PROCESS SECTION.
            ……………..
MOVE “NIL001” TO TS-QUEUE-NAME.
            MOVE WS-Q-RECORD TO TS-QUEUE-RECORD.
            MOVE 100 TO TS-QUEUE-LENGTH.
             …………………..
            EXEC CICS WRITEQ TS QUEUE(TS-QUEUE-NAME
                               FROM(TS-QUEUE-RECORD)
                               LENGTH(TS-QUEUE-LENGTH)
            END-EXEC.     

……………………………

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.