View previous topic :: View next topic |
Author |
Message |
harisubs Beginner
Joined: 03 Aug 2007 Posts: 8 Topics: 2
|
Posted: Mon Aug 13, 2007 9:21 am Post subject: Query on cursor logic in IMS Screens using DB2 table |
|
|
Hi
I have a query for the Pageup and Pagedown logic in IMS screen and I need to fetch records from DB2 table.
The normal pageup and pagedown logic will be based on the key fields displayed on the screen. For pageup, we use the first record displayed on the screen to fetch the previous set of records from DB2 table.
For pagedown, we use the last record displayed on the screen to fetch the next set of records from DB2 table.
The problem is:
I need to display the records on the screen sorted on a different set of fields other than the KEY field and this 'different set of fields' can contain the same values.
If I try to sort them on the 'different set of fields' while retrieving from DB2 itself then I lose track of the Key field as my key field gets jumbled and I would not be able to get the 'correct' next/previous set of records while performing pageup and pagedown.
I will try to list a sample data to add more clarity to the problem.
Data in DB2 table
============
Code: |
KEY_FLD-------DATE---------------AMOUNT
9-------------2001-08-01--------100.00
10------------2001-08-01--------110.00
11------------2001-08-01--------120.00
52------------2001-08-27--------100.00
56------------2001-07-26--------100.00
57------------2001-08-01--------130.00
58------------2001-08-01--------140.00
|
MUST APPEAR ON SCREEN AS
==================== Code: |
KEY_FLD-------DATE---------------AMOUNT
56------------2001-07-26--------100.00
9 ------------2001-08-01--------100.00
10------------2001-08-01--------110.00
11------------2001-08-01--------120.00
57------------2001-08-01--------130.00
58------------2001-08-01--------140.00
52------------2001-08-27--------100.00
|
The solution that I could think of is to fetch all the records from the table ordered by the 'different set of fields' everytime and then calculate the next set of records to be displayed (either previous or next set) based on the number of pages already displayed and the current key operation (Pageup or page down). But I think that this is very inefficient way in an online environment.
Is there an alternative/better solution to this?
Thanks
Harisubs |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Mon Aug 13, 2007 9:40 am Post subject: |
|
|
harisubs,
From what I see your screen data is sorted on Date and key_field.
Page up/normal cursor. for first time move low-values to ws-key-field and ws-date-field. When page up move the last key values from the screen to these 2 variables.
Code: |
SELECT *
FROM TABLE
WHERE KEY_FIELD > :WS-KEY-FIELD
AND DATE_FIELD > :WS-DATE-FIELD
ORDER BY DATE_FIELD
,KEY_FELD
|
page down cursor. When page down move the first key values from the screen to these 2 variables.
Code: |
SELECT *
FROM TABLE
WHERE KEY_FIELD < :WS-KEY-FIELD
AND DATE_FIELD < :WS-DATE-FIELD
ORDER BY DATE_FIELD
,KEY_FELD
|
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
harisubs Beginner
Joined: 03 Aug 2007 Posts: 8 Topics: 2
|
Posted: Tue Aug 14, 2007 3:32 am Post subject: |
|
|
Kolusu
The data on screen is sorted on Date,Amount and Key-fld respectively.
I have a query for the solution provided.
Considering the same data as given above (first post) and let us assume that I am displaying 2 records at a time on the screen. Then if user performs Page up operation then at the 3rd page the user would have the following data on screen
KEY_FLD-------DATE---------------AMOUNT
57------------2001-08-01--------130.00
58------------2001-08-01--------140.00
And if the user performs a pageup operation again then the query will look like
SELECT *
FROM TABLE
WHERE KEY_FIELD > 58
AND DATE_FIELD > 2001-08-01
ORDER BY DATE_FIELD
,KEY_FELD
This query would not fetch the last record as the kEY_FLD's values is 52 which is less than 58. Ideally, it should fetch the below record on 4th page.
52------------2001-08-27--------100.00
Also, as I had mentioned there could be duplicate values on the date and amount field.
So, if we just use '>' for pageup and '<' for pagedown (in the query) then we will be losing data. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Aug 14, 2007 7:16 am Post subject: |
|
|
harisubs,
what is the format/definition of all the columns involved here?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
harisubs Beginner
Joined: 03 Aug 2007 Posts: 8 Topics: 2
|
Posted: Tue Aug 14, 2007 7:27 am Post subject: |
|
|
Kolusu
The KEY-FLD is numeric, DATE field would be converted to MMCCYY format (example: 082007) while displaying on screen and AMOUNT field is numeric.
The sorting should be done on DATE,AMOUNT,KEY-FLD respectively
Thanks
Harisubs |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Aug 14, 2007 8:25 am Post subject: |
|
|
harisubs,
Try this. You need to concatenate all the 3 fields together and treat it as a key. Move the last entry of the screen to the level 10 fields and use that information to get the next key
Code: |
05 WS-FWD-CONCAT-KEY PIC X(22).
05 WS-FWD-CONCAT-ASC REDEFINES WS-FWD-CONCAT-KEY.
10 WS-FWD-DATE PIC X(10).
10 WS-FWD-AMT PIC X(08).
10 WS-FWD-KEY PIC X(04).
SELECT *
FROM Table
WHERE (CHAR(DATE_FIELD) || DIGITS(AMOUNT) || DIGITS(KEY_FIELD)) > :WS-FWD-CONCAT-KEY
ORDER BY DATE_FIELD
,AMOUNT
,KEY_FIELD
|
for example take the data from your 1st post and if you want the the next key after 9 (i.e the second record)
Code: |
SELECT *
FROM Table
WHERE (CHAR(DATE_FIELD) || DIGITS(AMOUNT) || DIGITS(KEY_FIELD)) > '2001-08-01001000000009'
ORDER BY DATE_FIELD
,AMOUNT
,KEY_FIELD
|
Change the lengths depending on the field declarations.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
harisubs Beginner
Joined: 03 Aug 2007 Posts: 8 Topics: 2
|
Posted: Tue Aug 14, 2007 8:50 am Post subject: |
|
|
Thank you Kolusu.
I made a short test in SPUFI and the results are as desired.
Shall get back if I face any trouble
Thanks
Harisubs |
|
Back to top |
|
 |
|
|