View previous topic :: View next topic |
Author |
Message |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Wed Mar 08, 2006 6:27 am Post subject: Binary Search Problem |
|
|
hi sir/madam,
i am having problems searching tables in cobol using binary search.
here is how i declared my table:
Code: |
01 MY-TABLE.
03 ELEMENT-LIST OCCURS 20000,
DEPENDING ON REC-LENGTH
ASCENDING KEY IS ELEMENT-1,
ELEMENT-2,
ELEMENT-3
INDEXED BY IDX.
05 ELEMENT-1 PIC X(2).
05 ELEMENT-2 PIC X(2).
05 ELEMENT-3 PIC X(2).
05 ELEMENT-4 PIC X(2).
05 ELEMENT-5 PIC X(1).
05 ELEMENT-6 PIC X(15).
05 ELEMENT-7 PIC X(2).
05 ELEMENT-8 PIC X(1).
05 ELEMENT-9 PIC X(15).
|
here is how i am searching the table:
Code: |
SEARCH ALL ELEMENT-LIST
AT END
SET NO-REC-FOUND TO TRUE
WHEN ELEMENT-1(IDX) = 'XX'
AND ELEMENT-1(IDX) = 'YY'
AND ELEMENT-1(IDX) = 'ZZ'
do something.....
END-SEARCH.
|
it was not able to search for the record even if the record is present.
hope you can help me out on this.
thanks. |
|
Back to top |
|
 |
German Castillo Beginner

Joined: 23 Dec 2005 Posts: 83 Topics: 2 Location: Caracas, Venezuela
|
Posted: Wed Mar 08, 2006 7:11 am Post subject: |
|
|
Your table should be previously sorted out. Is yours? _________________ Best wishes,
German Castillo |
|
Back to top |
|
 |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Wed Mar 08, 2006 7:21 am Post subject: |
|
|
hello German Castillo,
i think this is my problem. can you please explain how binary search really works? what if my table is not sorted but the record exists? why cant the binary search locate this record?
Thanks! |
|
Back to top |
|
 |
Ravi Beginner
Joined: 27 Jun 2005 Posts: 88 Topics: 2
|
Posted: Wed Mar 08, 2006 7:34 am Post subject: |
|
|
Binary Search algorithm
The most common application of binary search is to find a specific value in a sorted list.
The search begins by examining the value in the center of the list; because the values are sorted, it then knows whether the value occurs before or after the center value, and searches through the correct half in the same way.
Details in http://en.wikipedia.org/wiki/Binary_search |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Thu Mar 09, 2006 4:50 am Post subject: |
|
|
wow! now i know! cool! thanks for all your help! this site rocks! 8) |
|
Back to top |
|
 |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Mon Mar 13, 2006 9:09 am Post subject: |
|
|
hi guys! its me again... i have another question regarding the code i have previously. i have compile and tested it in UNIX and it was working file. but when I try to compile it in MVS, i received an error
Code: |
"NO-REC-FOUND" was reference modified and reference modification is not allowed in this context. The statement was discarded.
|
and
Code: |
Not all of the keys that precede a key referenced in a "WHEN" phrase were referenced in the "WHEN" phrase. The statement was discarded.
|
Can you please tell me why is this happenning? |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Mar 13, 2006 9:23 am Post subject: |
|
|
treks02,
Please Post the error Message ID which starts with IG....
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Mon Mar 13, 2006 9:36 am Post subject: |
|
|
hi kolusu,
here it is...
IGYPS2213-S
IGYPA3122-S |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Mar 13, 2006 9:42 am Post subject: |
|
|
treks02,
Post your SEARCH statement also.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Mon Mar 13, 2006 9:49 am Post subject: |
|
|
hi kolusu,
here it is:
Code: |
01 MY-TABLE.
03 ELEMENT-LIST OCCURS 0 TO 20000,
DEPENDING ON REC-LENGTH
ASCENDING KEY IS ELEMENT-1,
ELEMENT-2,
ELEMENT-3
INDEXED BY IDX.
05 ELEMENT-1 PIC X(2).
05 ELEMENT-2 PIC X(2).
05 ELEMENT-3 PIC X(2).
05 ELEMENT-4 PIC X(2).
05 ELEMENT-5 PIC X(1).
05 ELEMENT-6 PIC X(15).
05 ELEMENT-7 PIC X(2).
05 ELEMENT-8 PIC X(1).
05 ELEMENT-9 PIC X(15).
|
Code: |
SEARCH ALL ELEMENT-LIST
AT END
SET NO-REC-FOUND TO TRUE
WHEN ELEMENT-1(IDX) = 'XX'
AND ELEMENT-2(IDX) = 'YY'
AND ELEMENT-3(IDX) = 'ZZ'
MOVE ELEMENT-1(IDX) = WV-TEMP-VAR1
MOVE ELEMENT-2(IDX) = WV-TEMP-VAR2
MOVE ELEMENT-3(IDX) = WV-TEMP-VAR3
END-SEARCH.
|
|
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Mar 13, 2006 10:06 am Post subject: |
|
|
Quote: |
MOVE ELEMENT-1(IDX) = WV-TEMP-VAR1
MOVE ELEMENT-2(IDX) = WV-TEMP-VAR2
MOVE ELEMENT-3(IDX) = WV-TEMP-VAR3
|
treks02,
A move statement should have TO instead of = . change that and your code should compile fine.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Mon Mar 13, 2006 10:10 am Post subject: |
|
|
hi kolusu, that was a typo error. sorry...
treks02 wrote: | hi kolusu,
here it is:
Code: |
01 MY-TABLE.
03 ELEMENT-LIST OCCURS 0 TO 20000,
DEPENDING ON REC-LENGTH
ASCENDING KEY IS ELEMENT-1,
ELEMENT-2,
ELEMENT-3
INDEXED BY IDX.
05 ELEMENT-1 PIC X(2).
05 ELEMENT-2 PIC X(2).
05 ELEMENT-3 PIC X(2).
05 ELEMENT-4 PIC X(2).
05 ELEMENT-5 PIC X(1).
05 ELEMENT-6 PIC X(15).
05 ELEMENT-7 PIC X(2).
05 ELEMENT-8 PIC X(1).
05 ELEMENT-9 PIC X(15).
|
Code: |
SEARCH ALL ELEMENT-LIST
AT END
SET NO-REC-FOUND TO TRUE
WHEN ELEMENT-1(IDX) = 'XX'
AND ELEMENT-2(IDX) = 'YY'
AND ELEMENT-3(IDX) = 'ZZ'
MOVE ELEMENT-1(IDX) TO WV-TEMP-VAR1
MOVE ELEMENT-2(IDX) TO WV-TEMP-VAR2
MOVE ELEMENT-3(IDX) TO WV-TEMP-VAR3
END-SEARCH.
|
|
the error only occurs in MVS.
IGYPS2213-S
IGYPA3122-S
 |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Mon Mar 13, 2006 10:23 am Post subject: |
|
|
treks02,
The code compiles fine for me. Are you sure that the error you are showing is somewhere else in the code? .
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
treks02 Beginner
Joined: 08 Mar 2006 Posts: 15 Topics: 3
|
Posted: Mon Mar 13, 2006 10:34 am Post subject: |
|
|
hi kolusu,
it is in the code that i have. are there certain compilers that does not allow these syntax?
can certain syntax be exempted or blocked by a compiler?
thanks, |
|
Back to top |
|
 |
|
|