IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Multiple ' ASCENDING KEY IS '


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Wed Mar 11, 2009 4:14 pm
Reply with quote

hello,

I searched the forum but could not find any satisfactory answer.

I know we can give multiple keys in Ascending keys clause in a table.

Like

ASCENDING KEY IS Key1 Key2

The question is :

1. What exactly happens to the table ? Does it gets sorted on two keys individually ? or first it sorts it on Key1 and then on Key2

2. In my program I am adding a new key to the ASCENDING clause. Will that affect my existing searchs ?

Please advise.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 11, 2009 4:48 pm
Reply with quote

The manuals link at the top of the page contains the COBOL Language Reference manual, which says in section 5.3.11.2 on ASCENDING KEY:
Quote:
The following example illustrates the specification of ASCENDING KEY data items:


Code:
     WORKING-STORAGE SECTION.
     01  TABLE-RECORD.
         05  EMPLOYEE-TABLE OCCURS 100 TIMES
             ASCENDING KEY IS WAGE-RATE EMPLOYEE-NO
             INDEXED BY A, B.
           10  EMPLOYEE-NAME                     PIC X(20).
           10  EMPLOYEE-NO                       PIC 9(6).
           10  WAGE-RATE                         PIC 9999V99.
           10  WEEK-RECORD OCCURS 52 TIMES
               ASCENDING KEY IS WEEK-NO INDEXED BY C.
             15  WEEK-NO                         PIC 99.
             15  AUTHORIZED-ABSENCES             PIC  9.
             15  UNAUTHORIZED-ABSENCES           PIC  9.
             15  LATE-ARRIVALS                   PIC  9.


The keys for EMPLOYEE-TABLE are subordinate to that entry, and the key for WEEK-RECORD is subordinate to that subordinate entry.

In the preceding example, records in EMPLOYEE-TABLE must be arranged in ascending order of WAGE-RATE, and in ascending order of EMPLOYEE-NO within WAGE-RATE. Records in WEEK-RECORD must be arranged in ascending order of WEEK-NO. If they are not, results of any SEARCH ALL statement are unpredictable.
So the answer to your first question is, no the table must be sorted before loading -- by you -- and must be sorted by secondary key within primary key. The answer to your second question is of course existing searches will be affected if you add another key.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Grouping by multiple headers DFSORT/ICETOOL 7
No new posts How to append a PS file into multiple... JCL & VSAM 3
Search our Forums:

Back to Top