View previous topic :: View next topic
|
Author |
Message |
srimsc_ibmmainframes
New User
Joined: 17 Feb 2004 Posts: 19 Location: pune
|
|
|
|
While we work with SEARCH ALL how do we know that whether the table is in sorted order r not......? |
|
Back to top |
|
|
rahul_jot
New User
Joined: 17 Aug 2005 Posts: 22 Location: Pune
|
|
|
|
I think there is no way in SEARCH ALL to know whether the tables are sorted or not. We must sort the tables before using the SEARCH ALL options. Please correct me if I am wrong. |
|
Back to top |
|
|
sonalig
New User
Joined: 22 Aug 2005 Posts: 7 Location: India
|
|
|
|
Hi,
While applying SEARCH ALL on a particular order, we MUST provide the KEY IS pharse in the table declaration itself. That means, COBOL expects the table to be sorted on some key-field in either ascending/descending order.
In case, we do not ensure that the table data is actually sorted, then SEARCH ALL will give unexpected results. So, its the programmer's responsiblity to make sure that the table is actually sorted in the order as per the table declaration.
If the table to be searched is only partially populated, the SEARCH ALL may not work correctly. If the table is ordered in ascending sequence then, to get the SEARCH ALL to function correctly, the unpopulated elements must be filled with HIGH-VALUES. If the table is in descending sequence, the unpopulated elements should be filled with LOW-VALUES.
Correct me if I'm wrong.
Thanks,
Sonali. |
|
Back to top |
|
|
sathish_rathinam
New User
Joined: 22 Aug 2005 Posts: 59 Location: india
|
|
|
|
hi sonali,
could u tell me the syntax to declare for the key.......
the below syntax is correct or not,
occurs 1 to n times ascending\descending key is variable depending on identifier.
corret me.
regards
sathish |
|
Back to top |
|
|
nag Warnings : 1 New User
Joined: 29 Jul 2005 Posts: 20
|
|
|
|
hi buddies
can i know wat will b the actual will v get if the table is not in a sorted order and we have applied searchall |
|
Back to top |
|
|
sonalig
New User
Joined: 22 Aug 2005 Posts: 7 Location: India
|
|
|
|
The syntax for KEY IS is:
OCCURS SmallBoundry#1 TO LargeBoundry#2 TIMES
DEPENDING ON Var#1
{ASCENDING/DESCENDING} KEY IS TableItem#
INDEXED BY IndexItem#.
Now, about the second question that "what will happen if we try to SEARCH on an unsorted table?".
Well, consider a situation, where your table is having single column say ItmNumber. You specify in the table declaration that it is sorted in ASCENDING order on KEY ItmNumber. Your data is not actually sorted, so it is containing following values:
ItmNumber(1) = 12
ItmNumber(2) = 2
ItmNumber(3) = 34
ItmNumber(4) = 17
ItmNumber(5) = 0
Now, you apply SEARCH ALL on this table, to search a value, say 17.
this value is present at 4th entry in the table.
Here, the main point to remember is that SEARCH ALL works as per Binary Search concept . So, internally, first ItmNumber(3) will be compared with 17. Since ItmNumber(3) i.e. 34 > 17, it'll discard the lower half section of the table and will start searching at the first half i.e. table location 1 & 2. It will now search at ItmNumber(2). Now, ItmNumber(2) i.e. 2 < 17. So, it'll conclude taht 17 is not present in the table and will return from the search and thus, you'll get incorrect result.
This is just a sample example given. In real life, you might get similar results for different permutations and combinations.
Thanks,
Sonali. |
|
Back to top |
|
|
|