MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Binary Search Problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Wed Mar 08, 2006 6:27 am    Post subject: Binary Search Problem Reply with quote

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
View user's profile Send private message
German Castillo
Beginner


Joined: 23 Dec 2005
Posts: 83
Topics: 2
Location: Caracas, Venezuela

PostPosted: Wed Mar 08, 2006 7:11 am    Post subject: Reply with quote

Your table should be previously sorted out. Is yours?
_________________
Best wishes,

German Castillo
Back to top
View user's profile Send private message
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Wed Mar 08, 2006 7:21 am    Post subject: Reply with quote

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
View user's profile Send private message
Ravi
Beginner


Joined: 27 Jun 2005
Posts: 88
Topics: 2

PostPosted: Wed Mar 08, 2006 7:34 am    Post subject: Reply with quote

Arrow 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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Wed Mar 08, 2006 8:44 am    Post subject: Reply with quote

treks02,

Check this link which explains in detail about the various Search methods

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3LR10/6.2.32?DT=20020920180651

Hope this helps...

Cheers

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Thu Mar 09, 2006 4:50 am    Post subject: Reply with quote

wow! now i know! cool! thanks for all your help! this site rocks! 8)
Back to top
View user's profile Send private message
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Mon Mar 13, 2006 9:09 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Mon Mar 13, 2006 9:23 am    Post subject: Reply with quote

treks02,

Please Post the error Message ID which starts with IG....

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Mon Mar 13, 2006 9:36 am    Post subject: Reply with quote

hi kolusu,

here it is...

IGYPS2213-S
IGYPA3122-S
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Mon Mar 13, 2006 9:42 am    Post subject: Reply with quote

treks02,

Post your SEARCH statement also.

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Mon Mar 13, 2006 9:49 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Mon Mar 13, 2006 10:06 am    Post subject: Reply with quote

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 - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Mon Mar 13, 2006 10:10 am    Post subject: Reply with quote

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

Question
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Mon Mar 13, 2006 10:23 am    Post subject: Reply with quote

treks02,

The code compiles fine for me. Are you sure that the error you are showing is somewhere else in the code? .

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
treks02
Beginner


Joined: 08 Mar 2006
Posts: 15
Topics: 3

PostPosted: Mon Mar 13, 2006 10:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group