IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Problem while doing Binary search


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Moderator Emeritus


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

PostPosted: Wed Jun 11, 2008 3:00 am
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts first column truncated in search result IBM Tools 13
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
Search our Forums:

Back to Top