View previous topic :: View next topic |
Author |
Message |
misi01 Advanced
Joined: 02 Dec 2002 Posts: 626 Topics: 175 Location: Stockholm, Sweden
|
Posted: Fri Jun 08, 2018 7:18 am Post subject: Search all using different keys |
|
|
I'm guessing that the following isn't allowed (I certainly can't get it to compile)
Code: |
05 t-idam-tbl.
10 t-idam-rader occurs 15000
ascending key is t-idam-wdws-uid
indexed by x-wdws
ascending key is t-idam-cics-uid
indexed by x-cics.
15 t-idam-wdws-uid pic x(8).
15 t-idam-fornamn pic x(15).
15 t-idam-efternamn pic x(20).
15 t-idam-chef-uid pic x(8).
15 t-idam-cics-uid pic x(5).
15 t-vsg-behorighet pic x.
15 t-smort-behorighet
pic xx.
|
What I would like to do is to define TWO diffferent keys for the same table.
The first time through, I sort the table on ascending windows userid after which I can do a SEARCH ALL using the windows userid.
Once I've done that, I then sort on ascending CICS userid and do a search all based on that field.
Another option might be to create a temporrary DB2 table and populate it, after which I can select my rows and order them based on either windows or CICS userid.
A third coption would be simply to create a copy of this table where the copy is defined as having
Code: |
ascending key is t-idam-cics-uid
indexed by x-cics.
|
Suggestions anyone ?
[Edited to include 2 fields I'd left out first time round] _________________ Michael
Last edited by misi01 on Fri Jun 08, 2018 9:59 am; edited 3 times in total |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Fri Jun 08, 2018 8:20 am Post subject: |
|
|
Would another option be to redefine t-idam-tbl so now you have the same table sorted in 2 different sequences. I don't think COBOL allows the same table to have 2 different keys for the same table at the same time without redefining it. This option wouldn't work if you constantly have to refer to the different sequences alternately throughout your program logic. I'd probably go with your 3rd option. _________________ ....Terry |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 626 Topics: 175 Location: Stockholm, Sweden
|
Posted: Fri Jun 08, 2018 9:57 am Post subject: |
|
|
Thatnks Terry - that's what I ended up going with. My redefined table was
Code: |
05 t-cics-tbl redefines t-idam-tbl.
10 t-cics-rader occurs 15000
ascending key is t-cics-uid
indexed by x-cics.
15 filler pic x(51).
15 t-cics-uid pic x(5).
15 filler pic x(3).
|
Note how each row is the same length as the first table with fillers for the various fields that I'm not interested in when it comes to the sorting of the table (only the CICS userid is of interest) _________________ Michael |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Fri Jun 08, 2018 10:50 am Post subject: Re: Search all using different keys |
|
|
misi01 wrote: | I'm guessing that the following isn't allowed (I certainly can't get it to compile)
Code: |
05 t-idam-tbl.
10 t-idam-rader occurs 15000
ascending key is t-idam-wdws-uid
indexed by x-wdws
ascending key is t-idam-cics-uid
indexed by x-cics.
15 t-idam-wdws-uid pic x(8).
15 t-idam-fornamn pic x(15).
15 t-idam-efternamn pic x(20).
15 t-idam-chef-uid pic x(8).
15 t-idam-cics-uid pic x(5).
15 t-vsg-behorighet pic x.
15 t-smort-behorighet
pic xx.
|
What I would like to do is to define TWO diffferent keys for the same table.
The first time through, I sort the table on ascending windows userid after which I can do a SEARCH ALL using the windows userid.
Once I've done that, I then sort on ascending CICS userid and do a search all based on that field. |
misi01,
Unless I am mistaken, You CAN have multiple keys , you just need 1 index. You don't have to SORT it TWICE. You can do it in a single pass. SORT it on both WDWS-ID and CICS-ID and then you can search them as you need.
Try this
Code: |
01 T-IDAM-TBL.
10 T-IDAM-RADER OCCURS 15000
ASCENDING KEY IS T-IDAM-WDWS-UID
ASCENDING KEY IS T-IDAM-CICS-UID
INDEXED BY X-WDS-CICS.
15 T-IDAM-WDWS-UID PIC X(8).
15 T-IDAM-FORNAMN PIC X(15).
15 T-IDAM-EFTERNAMN PIC X(20).
15 T-IDAM-CHEF-UID PIC X(8).
15 T-IDAM-CICS-UID PIC X(5).
15 T-VSG-BEHORIGHET PIC X.
15 T-SMORT-BEHORIGHET PIC XX. |
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 626 Topics: 175 Location: Stockholm, Sweden
|
Posted: Sat Jun 09, 2018 2:54 am Post subject: |
|
|
Thanks for the suggestion, I'll try it on Monday. Having said that, I'm confused as to how the same table can be sorted on two different columns at the same time. Let's assume the table contains the following 3 rows (first column is windows, second one is cics)
Sorting on Windows would give rows 1, 2 and 3 as the sorted results. Sorting on cics would give 3, 2 and 1 instead.
Maybe I explained myself badly here. I don't want the table sorted on Windows and WITHIN that, on cics, I want it sorted on the one hand on Windows, and a completely different sort based on cics.
Based on that, does your suggestion still fly? _________________ Michael |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Mon Jun 11, 2018 11:13 am Post subject: |
|
|
misi01 wrote: |
Maybe I explained myself badly here. I don't want the table sorted on Windows and WITHIN that, on cics, I want it sorted on the one hand on Windows, and a completely different sort based on cics.
Based on that, does your suggestion still fly? |
Misi01,
Your CICS id would be sorted WITHIN the windows id. So if you want to have different sort orders then why NOT use the same table? Define only 1 uid field and then use that.
Code: |
01 T-IDAM-TBL.
05 T-IDAM-RADER OCCURS 15000
ASCENDING KEY IS T-IDAM-UID
INDEXED BY X-WDS-CICS.
10 T-IDAM-UID PIC X(8).
10 T-IDAM-FORNAMN PIC X(15).
10 T-IDAM-EFTERNAMN PIC X(20).
10 T-IDAM-CHEF-UID PIC X(8).
10 T-VSG-BEHORIGHET PIC X.
10 T-SMORT-BEHORIGHET PIC XX.
|
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 626 Topics: 175 Location: Stockholm, Sweden
|
Posted: Fri Jun 15, 2018 6:15 am Post subject: |
|
|
Let me rephrase what I would like to do. I've simplified the definition of the table as shown below.
Code: |
01 T-IDAM-TBL.
05 T-IDAM-RADER OCCURS 15000
ASCENDING KEY IS T-WDWS-UID
INDEXED BY X-WDWS.
10 T-WDWS-UID PIC X(8).
10 T-CICS-UID PIC X(5).
|
I would like to use the same table to do a search ALL based on either T-WDWS-UID or T-CICS-UID. This would mean (?) sorting the table on T-WDWS-UID and/or T-CICS-UID.
I'm wondering if this is doable. I've tried something like
Code: |
05 t-idam-tbl.
10 t-idam-rader occurs 10
ascending key is t-wdws-uid
indexed by x-wdws
ascending key is t-cics-uid
indexed by x-cics.
15 t-wdws-uid pic x(8).
15 t-cics-uid pic x(5).
|
but this simply gives me a compilation error. I removed the lines
Code: |
ascending key is t-cics-uid
indexed by x-cics.
|
but then I got a compilation error on the following section:-
Code: |
*****************************************************************
*
*****************************************************************
aha-find-cics-userid section.
*
search all t-idam-rader
*
at end
set v-hittat-nej to true
*
when t-cics-uid(x-wdws) = w-cics-userid
* Found it
set v-hittat-ja to true
end-search
*
exit.
|
Am I forced to have the one table sorted on WDWS userid and a copy of that table based on the CICS userid?
In the end, I was forced to define my tables in the following manner (simplified again). Note how I now have TWO tables of equal size, but NOT redefined
Code: |
05 t-wdws-tbl.
10 t-wdws-rader occurs 10
ascending key is t-wdws-uid
indexed by x-wdws.
15 t-wdws-uid pic x(8).
15 t-cics-uid pic x(6).
05 t-cics-tbl.
10 t-cics-rader occurs 10
ascending key is t-cics
indexed by x-cics.
15 t-wdws pic x(8).
15 t-cics pic x(6).
|
I then filled the tables with data similar to the following (as you can see, the windows userids are inserted in descending order and the CICS ones in ascending order):-
Code: |
*
move 'WDWS10' to t-wdws-uid(1)
move 'CICS01' to t-cics-uid(1)
*
move 'WDWS09' to t-wdws-uid(2)
move 'CICS02' to t-cics-uid(2)
*
move 'WDWS08' to t-wdws-uid(3)
move 'CICS03' to t-cics-uid(3)
|
followed by
Code: |
move t-wdws-tbl to t-cics-tbl
|
I then had to sort BOTH the windows and CICS tables after which I could do a search all on EITHER the windows table (searching for windows userid) OR the CICS table, searching based on CICS userid.[/code] _________________ Michael |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12369 Topics: 75 Location: San Jose
|
Posted: Fri Jun 15, 2018 11:32 am Post subject: |
|
|
misi01,
You don't have to use 2 different tables. Here is a snippet of code (untested) which will give you the desired results.
Table definition
Code: |
01 T-IDAM-TBL.
05 T-IDAM-RADER OCCURS 10
ASCENDING KEY IS T-WDWS-UID
INDEXED BY X-WDWS.
10 T-WDWS-UID PIC X(8).
10 T-CICS-UID PIC X(6).
|
Populate the table with values
Code: |
MOVE 'WDWS10' TO T-WDWS-UID(1)
MOVE 'CICS02' TO T-CICS-UID(1)
MOVE 'WDWS09' TO T-WDWS-UID(2)
MOVE 'CICS01' TO T-CICS-UID(2)
MOVE 'WDWS08' TO T-WDWS-UID(3)
MOVE 'CICS03' TO T-CICS-UID(3)
|
SORT the internal table on Windows Id and also do the SEARCH
Code: |
SORT T-IDAM-RADER ON ASCENDING KEY T-WDWS-UID
DISPLAY T-IDAM-TBL
MOVE 'WDWS09' TO W-SEARCH-KEY
PERFORM 2000-SEARCH-USERID |
Done with windows processing, now switch to CICS look up
Code: |
** WE ARE DONE WITH WINDOWS ID, NOW MOVE TO CICS SEARCH ID
PERFORM 1000-SWITCH-USERID
SORT T-IDAM-RADER ON ASCENDING KEY T-WDWS-UID
DISPLAY T-IDAM-TBL
MOVE 'CICS04' TO W-SEARCH-KEY
PERFORM 2000-SEARCH-USERID
.
1000-SWITCH-USERID.
PERFORM VARYING X-WDWS FROM 1 BY 1 UNTIL X-WDWS > 10
MOVE SPACES TO T-WDWS-UID(X-WDWS)
MOVE T-CICS-UID(X-WDWS) TO T-WDWS-UID(X-WDWS)
MOVE SPACES TO T-CICS-UID(X-WDWS)
END-PERFORM
.
2000-SEARCH-USERID.
SEARCH ALL T-IDAM-RADER
AT END
DISPLAY 'MISSING USERID : ' W-SEARCH-KEY
WHEN T-WDWS-UID(X-WDWS) = W-SEARCH-KEY
DISPLAY ' USERID FOUND : ' T-WDWS-UID(X-WDWS)
END-SEARCH
|
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 626 Topics: 175 Location: Stockholm, Sweden
|
Posted: Mon Jun 18, 2018 1:16 am Post subject: |
|
|
Now I understand how you're thinking. However, I'm going to skip your suggestion for two reasons..
1 The main one is maintainability. You're going to end up with a table containing a key element that at times is the windows userid, and at other times is the CICS userid. This means that reviewing the code at any time is going to be confusing. Okay, the next programmer is going to think, you're doing a SEARCH ALL on the table, but does the key column contain windows or CICS userids. In addition, somewhere else, you might have
Code: |
move t-key-column(x-wdws) to somewhere
|
and in reality it's a CICS userid you're moving. I don't think I'd be too popular after that.
2 This batch program is going to be run 2-3 times a year, so the concept of having "duplicate" tables doesn't seem like the end of the world to me (yeah, the program'll be bigger, but nowadays, that's not an issue).
But thank you anyway for your suggestions. _________________ Michael |
|
Back to top |
|
|
|
|