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
 

 

Problem while doing Binary search

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

New User


Joined: 18 Aug 2006
Posts: 2

PostPosted: Tue Jun 10, 2008 11:50 pm    Post subject: Problem while doing Binary search
Reply with quote

i created a working storage table and loading this table from Db2.

Below code for the working storage table.



[1) working storage table declaration.

01 WS-PRODCODE-BUILD-AREA.
05 WS-PRODCODE-BUILD-WORK.
10 FILLER PIC X(1506).

05 WS-PRODUCT-CODE REDEFINES WS-PRODCODE-BUILD-WORK.
10 WS-TABLE-PARMS.
15 WS-TP-IN-CTR PIC S9(04) COMP.
15 WS-TP-OCCURS PIC S9(04) COMP.
15 WS-TP-MAX-OCCURS PIC S9(04) COMP.
10 WS-PC-TABLE.
15 WS-PC-TBL-ENTRY OCCURS 250 TIMES
ASCENDING KEY IS WS-PROD-CODE
INDEXED BY WS-PC-NDX.
20 WS-PROD-CODE PIC X(02).
20 WS-PROD-EXTERN-TYPE PIC X(01).
20 WS-PROD-ACE-TYPE PIC X(02).
20 WS-PROD-NPSL-IN PIC X(01).


2)Reading the values from the table


PERFORM VARYING WS-PC-NDX FROM 1 BY 1 UNTIL
WS-PC-NDX GREATER THAN 250 OR NO-MORE-PROD-CODE-RECS
EXEC SQL
FETCH CURPRCD
INTO :TSPROD-PROD-CODE,
:TSPROD-EXTERN-TYPE,
:TSPROD-ACE-TYPE,
:TSPROD-NPSL-IN
END-EXEC



3)Binary search condition .
i am not at all able to enter in to the when condition. i.e. WHEN condition is not satisfying if the both values all equal


PERFORM VARYING WS-PC-NDX FROM 1 BY 1 UNTIL WS-PC-NDX > 250
SEARCH ALL WS-PC-TBL-ENTRY
AT END SET PROD-CODE-NT-FND TO TRUE
WHEN WS-PROD-CODE(WS-PC-NDX) = CBE-TSYS-PRODUCT-CODE
IF WS-PROD-NPSL-IN(WS-PC-NDX) = 'Y'
IF (WS-PROD-EXTERN-TYPE(WS-PC-NDX) = 'E' AND
WS-PROD-ACE-TYPE(WS-PC-NDX) = 'MC' OR
'PL' OR 'VC')
MOVE 'C' TO M2-PORTFOLIO
ELSE
MOVE 'O' TO M2-PORTFOLIO
END-IF
END-IF
END-SEARCH
END-PERFORM.


Query :- I am not at all able to enter in to the when condition. i.e. WHEN condition is not satisfying if the both values all equal
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jun 11, 2008 12:27 am    Post subject: Re: Problem while doing Binary search
Reply with quote

RAMA12 wrote:
i created a working storage table and loading this table from Db2.

PERFORM VARYING WS-PC-NDX FROM 1 BY 1 UNTIL WS-PC-NDX > 250
END-PERFORM.


1. Is the data being loaded into the table in sequence, is there an order by clause on your cursor? What if you load less than 250 entries into the table?

2. Why are you performing the search 250 times, WS-PC-INDX is the index that the search all will use to conduct it's search?
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: Wed Jun 11, 2008 3:00 am    Post subject:
Reply with quote

Hello,

Quote:
Is the data being loaded into the table in sequence
Is the data being loaded into the table at all? The perform with the fetch increments the index, but i see no table entry "loaded". The variables from the db2 fetch would have data, but how does it get into the array?

FWIW - i may misunderstand something, but when you use SEARCH ALL, you should not need to iterate in your code (as Craig mentioned).
Back to top
View user's profile Send private message
RAMA12

New User


Joined: 18 Aug 2006
Posts: 2

PostPosted: Thu Jun 19, 2008 10:03 am    Post subject:
Reply with quote

Thanks for you r suggestion really it was very helpful for me.


_Krishna
Back to top
View user's profile Send private message
smitha T

New User


Joined: 04 Jun 2008
Posts: 2
Location: Hyderabad

PostPosted: Fri Jun 20, 2008 9:33 am    Post subject: Reply to: Problem while doing Binary search
Reply with quote

Hi all,
iam facing similar problem while using binary search.
Here is the code:

2225-SEARCH-WS-EVENT.
MOVE 'N' TO WZBET-TBL-EOF-IND
SET ET-NDX TO 1
SEARCH ALL WZBET-TBL-ENTRY
AT END
MOVE 'Y' TO WZBET-TBL-EOF-IND
MOVE WZBET-TEST-DFLT TO WS-ZBET-SINGLE-ROW-X
WHEN WZBET-TBL-KEY(ET-NDX)
= WSET-TBL-KEY
MOVE WZBET-TBL-ENTRY(ET-NDX)
TO WS-ZBET-SINGLE-ROW

END-SEARCH.
Here WZBET-TBL-ENTRY is loaded with table values using cursor. Order by clause is used for it. When i replaced search all with Search, it worked fine.

SEARCH WZBET-TBL-ENTRY VARYING ET-NDX
AT END
MOVE 'Y' TO WZBET-TBL-EOF-IND
MOVE WZBET-TEST-DFLT TO WS-ZBET-SINGLE-ROW-X
WHEN WZBET-TBL-KEY(ET-NDX)
= WSET-TBL-KEY
MOVE WZBET-TBL-ENTRY(ET-NDX)
TO WS-ZBET-SINGLE-ROW

END-SEARCH. Can somebody tell me what is the error in using binary search?Pls let me know if i need to provide any data.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 20, 2008 10:41 am    Post subject:
Reply with quote

you need to start a new thread. and learn how to use BBcode
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 resume binary ftp in z/os meykh2014 All Other Mainframe Topics 5 Sun Jan 22, 2017 10:01 am
No new posts SYMNAMES problem jacobdng DFSORT/ICETOOL 7 Thu Dec 22, 2016 7:47 am
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm
No new posts DB2 Streaming Batch Processing Problem Manshadi DB2 4 Sat Sep 24, 2016 12:14 pm


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