I am facing a problem of doing a page up operation while reading the data from TSQ. The problem is I can read a fix number of rows say x from tsq depending on the screen and I am displaying the x rows at a time. These rows are fetched from TSQ using the next command in readq operation.
I am stuck in page up as the cics does not support 'prev' command in readq. Can any one suggest how can i do page up reading the cicis.
when you press PF7 then you read the number of specified set of records and display in the map from TSQ and keep the last record in the COMMAREA and as well as the first record, so you can read from last record to first record easily by DECRIMENTING the counter, when the attention key is PF8
IF PF7 IS FOR SCROLL DOWN.
IF PF8 IS FOR SCROLL UP.
Joined: 11 Jun 2007 Posts: 80 Location: Columbus, Ohio
There are multiple methods, but here is one that has worked successfully for me. By your description, you are trying to display multiple records on a given screen, and you are writing a single row to the TS Queue for every record you want to display on the screen. You also want to be able to Page Forward and Backward between the screens. Based on these assumptions, this is what my example will be guiding you thru. I am also going to assume that you have studied and understand the basics of TS Queues as well as knowing the basics of COBOL in a CICS command level environment.
The code below is NOT exact code or even all the code, but a general example of a process to load and access your TS Queue. I’m using a VSAM example. A DB2 FETCH or IMS call could easily be substituted.
The key to this simplistic method is to capture and store two values in your commarea. The first is NUMITEMS, which is an option of the WRITEQ TS command, defined as a binary halfword:
03 CA-NUMITEMS PIC S9(04) COMP VALUE ZEROS.
The second is ITEM, which you will use as an option of the READQ TS command, defined as a binary halfword:
03 CA-ITEM PIC S9(04) COMP VALUE +1.
Let’s say you want to display 10 records on every screen (I will use ‘map’ interchangeably with screen) along with 5 columns for every record. Define a table in working storage that has 10 occurrences:
03 TSQ-PAGE-ENTRY OCCURS 10 TIMES.
07 TSQ-REC-ELEMENT-1 PIC X(05) VALUE SPACES.
07 TSQ-REC-ELEMENT-2 PIC X(10) VALUE SPACES.
07 TSQ-REC-ELEMENT-3 PIC X(05) VALUE SPACES.
07 TSQ-REC-ELEMENT-4 PIC X(08) VALUE SPACES.
(You will probably want to redefine the output part of your symbolic map as a table that occurs 10 times … easier, consistent processing later in your code).
Now you want to perform logic, as part of your first time in process (or maybe after some key values were entered on the screen for specific data retrieval), that will ‘read input, load the page table, writeq the page table’ until you have reached some ending condition. The important thing here is that when you have completed loading the TS Queue, CA-NUMITEMS will contain a constant value of the total number of items (in this case ‘pages’) in the Queue. (Constant unless you issue more writeqs for some odd reason … and there are those odd reasons)
Read thru your file (generic), until you’ve reached end-of-file or some other condition, and load the TSQ table with up to 10 records. After the 10th record is loaded, write the TS Queue from TSQ-PAGE-TABLE. CA-NUMITEMS is updated with the total number of items (pages) in the TS Queue every time you writeq a “Page” of records.
Once you’ve successfully loaded the queue, you want to load the screen with what is in the queue. So you READQ TS, (CA-ITEM is initially +1 so you will get the first page), move the TSQ-REC-ELEMENT-1 thru 5 (TSQ-SUB) to their respective map elements, set the display attributes, send the map and then return to your transaction.
You now will always know where you are in your paging (PF7 / PF8) process. If PF7 is pressed, you compute the ITEM (page) you want to access from the TS queue, by subtracting 1 from the current ITEM, which is stored in CA-ITEM. If the resulting value is 0*, you know you are already at the first page and can send a message accordingly, otherwise, you use the result value to retrieve the corresponding page (ITEM) from the TS queue, load the map fields, set the attributes, send the map and return to the transaction.
The process is basically the same for PF8, except that you compute the ITEM (page) you want to access by adding 1 to the current ITEM (page) which is stored in CA-ITEM. If the resulting value is greater than the last possible page, i.e. *CA-NUMITEMS, then you are already at the last page and can send a message accordingly, otherwise you use the result value to retrieve the corresponding page (ITEM) from the TS Queue, load the map fields, set the attributes, send the map and return to the transaction.
*Note: If resulting value is 0, reset CA-ITEM back to +1. If resulting value is greater than CA-NUMITEMS, reset CA-ITEM to CA-NUMITEMS.
By capturing these values, not only will you always know where you are in your paging, you can display a “page number of page numbers” on the screen, something like “PAGE: 16 OF 250”. If you open page number for entry, you can go directly to the page. These are “features” that customers/users like to see.
First time loading and retrieving the TS Queue:
UNTIL NO-MORE-RECORDS OR SOME-ERROR
EXEC CICS READNEXT ….
IF RESP-CODE = ZEROS
IF TSQ-SUB > 10
PERFORM A999-WRITEQ-TS THRU A999-EXIT
ADD 1 TO TSQ-SUB
MOVE record elements TO TSQ-REC-ELEMENT-1 thru 5 (TSQ-SUB)
IF RESP-CODE = DFHRESP(NOTFND) OR DFHRESP(ENDFILE)
SET NO-MORE-RECORDS TO TRUE
IF TSQ-SUB > 0
PERFORM A999-WRITEQ-TS THRU A999-EXIT
SET SOME-ERROR TO TRUE
PERFORM some error routine ….
Sorry for opening up this post again. I have a question on the value in CA-ITEM & CA-NUM-ITEM. How are the values in CA-ITEM and CA-NUM-ITEM stored or rather where is that stored to be used in the below portion in above code
IF EIBAID = DFHPF7
COMPUTE CA-ITEM = CA-ITEM – 1
IF CA-ITEM = 0