Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

use of ascending key clause in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
inbasekarmani
Warnings : 2

New User


Joined: 20 Apr 2007
Posts: 13
Location: chennai

PostPosted: Thu Apr 08, 2010 1:17 pm    Post subject: use of ascending key clause in cobol
Reply with quote

Dear all,

I am executing the following code.


Code:
 IDENTIFICATION DIVISION.                         
 PROGRAM-ID.  xyz.                             
 AUTHOR.      xyz.                             
 DATA DIVISION.                                   
 WORKING-STORAGE SECTION.                         
 01 abc.                                     
    02 NUM OCCURS 2 TIMES ASCENDING KEY IS E-NO.   
       03 E-NO PIC 9(3).                           
 PROCEDURE DIVISION.                               
 main-PARA.                                     
      MOVE 862 TO NUM(1).                         
      MOVE 453 TO NUM(2).                         
      DISPLAY 'abc =' abc.             
      DISPLAY '-------------------------'.         
      STOP RUN.       

Iam expecting the above code should throw error bcoz iam passing second no which is less than first no.But the above coding works fine. whats the reason behind this.
Back to top
View user's profile Send private message

bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Thu Apr 08, 2010 1:43 pm    Post subject:
Reply with quote

Please Refer

Quote:
ASCENDING KEY and DESCENDING KEY phrases
Data is arranged in ascending or descending order, depending on the keyword specified, according to the values contained in data-name-2. The data-names are listed in their descending order of significance.

The order is determined by the rules for comparison of operands (see Relation conditions). The ASCENDING KEY and DESCENDING KEY data items are used in OCCURS clauses and the SEARCH ALL statement for a binary search of the table element.

data-name-2
Must be the name of the subject entry or the name of an entry subordinate to the subject entry. data-name-2 cannot be a windowed date field. data-name-2 can be qualified.
If data-name-2 names the subject entry, that entire entry becomes the ASCENDING KEY or DESCENDING KEY and is the only key that can be specified for this table element.

If data-name-2 does not name the subject entry, then data-name-2:

Must be subordinate to the subject of the table entry itself
Must not be subordinate to, or follow, any other entry that contains an OCCURS clause
Must not contain an OCCURS clause
data-name-2 must not have subordinate items that contain OCCURS DEPENDING ON clauses.

When the ASCENDING KEY or DESCENDING KEY phrase is specified, the following rules apply:

Keys must be listed in decreasing order of significance.
The total number of keys for a given table element must not exceed 12.
The data in the table must be arranged in ascending or descending sequence according to the collating sequence in use.
The key must be described with one of the following usages:
BINARY
DISPLAY
DISPLAY-1
NATIONAL
PACKED-DECIMAL
COMPUTATIONAL
COMPUTATIONAL-1
COMPUTATIONAL-2
COMPUTATIONAL-3
COMPUTATIONAL-4
COMPUTATIONAL-5
A key described with usage NATIONAL can have one of the following categories: national, national-edited, numeric-edited, numeric, or external floating-point.
The sum of the lengths of all the keys associated with one table element must not exceed 256.
If a key is specified without qualifiers and it is not a unique name, the key will be implicitly qualified with the subject of the OCCURS clause and all qualifiers of the OCCURS clause subject.
The following example illustrates the specification of ASCENDING KEY data items:

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.

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

Global Moderator


Joined: 06 Jun 2008
Posts: 7998
Location: Bellevue, IA

PostPosted: Thu Apr 08, 2010 4:56 pm    Post subject:
Reply with quote

COBOL expects the programmer to be reasonably competent. If you put ASCENDING KEY in a table, you are expected to ensure that the values in the table are actually in ascending key sequence. If you do not do so, some actions (such as SEARCH ALL) will return unpredictable results. However, it is not a compile time nor a run time error to do this -- it is merely ignorance on the part of the programmer. COBOL does protect the programmer from some of his (her) stupidity, but by no means is it all guarded against.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Apr 08, 2010 7:42 pm    Post subject:
Reply with quote

Hello,

Quote:
Iam expecting the above code should throw error bcoz iam passing second no which is less than first no. But the above coding works fine. whats the reason behind this.
The way to get the code to generate an error is if the code compares the values to ensure they are in sequence as values are moved to the array..

Good job trying the experiment and questioning the outcome icon_smile.gif
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Thu Apr 08, 2010 10:17 pm    Post subject: Reply to: use of ascending key clause in cobol
Reply with quote

The Ascending key clause in a table description - is only useful when you ALSO use the INDEXED BY clause that will specify an INDEX-ITEM name -- AND THEN it only comes into play when you use the SEARCH ALL instruction within the program. There is no way, other than the code that YOU write to prevent your table from be incorrectly sequenced.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 1 Wed Mar 29, 2017 12:47 am
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm
No new posts Submit job from Cobol with input data abdulrafi COBOL Programming 4 Wed Feb 01, 2017 12:41 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us