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

Index in Search all


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rammraju

New User


Joined: 05 Mar 2005
Posts: 65
Location: Hyderabad

PostPosted: Thu Oct 23, 2008 6:11 am
Reply with quote

Hi,
Can someone please let me know if the index variable used in a SEARCH ALL resets to the initial value when the WHEN condition satisfies?

I intend to use the occurence number when the conditon satisfies, is there way for this?

My Working Storage
Code:
01 WS-ARRAY.
   05 WS-TABLE-DATA OCCURS 50 TIMES
                      ASCENDING KEY IS WS-DATA-ITEM1,
                                       WS-DATA-ITEM2
                      INDEXED BY WS-INDEX.
      10 WS-DATA-ITEM1      PIC X(10)  VALUE SPACES.
      10 WS-DATA-ITEM2      PIC X(10)  VALUE SPACES.
      10 WS-DATA-ITEM3      PIC X(01)  VALUE SPACES.


My Search all

Code:
SEARCH ALL WS-TABLE-DATA
   AT END
      PERFORM PROCESS-DATA-NOT-FND
   WHEN WS-DATA-ITEM1(WS-INDEX) = WS-DATA-ITEM1 AND
        WS-DATA-ITEM1(WS-INDEX) = WS-DATA-ITEM2
        PERFORM WRITE-CONTROL-RPT
END-SEARCH

WRITE-CONTROL-RPT.
   MOVE 'X'              TO  WS-DATA-ITEM3(WS-INDEX1).

WRITE-EXIT.
   EXIT.


I am trying to move "X" to WS-DATA-ITEM3 in the occurence when there is a hit, but the program is not behaving the way I am expecting. No matter what the occurence is, the program is always populating "X" in a particular position.

Can someone help in how to populate "X" in WS-DATA-ITEM3 in the occurence when there is a hit?

Thanks in advance
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: Thu Oct 23, 2008 6:30 am
Reply with quote

Hello,

Maybe there is something i am missing, but if the SEARCH is successful the position in the array that satisfied the WHEN is left in the index for use in processing.

If the search fails, the value in the index should not be used - it is not predictable.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Oct 23, 2008 7:20 am
Reply with quote

Unless you "typo'd", you have duplicate names assigned to your table fields and the ones you're comparing to. I'm assuming a typo, since I believe what you have keyed would give you a compile error. Your coding looks correct other than that. What happens in PROCESS-DATA-NOT-FND? You don't reference the index do you as Dick noted? Please paste the exact code.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Oct 23, 2008 7:58 am
Reply with quote

Your code segment didn't come from a working program, surely. You are testing the same variables with and without WS-INDEX (not to mention you use the WS-DATA-ITEM1 (WS-INDEX) twice) and then you're using another index variable WS-INDEX1 to set WS-DATA-ITEM3 so the code cannot work as presented.

Furthermore, if the code is exactly as presented, you're going to get some very unpredictable results since after the SEARCH ALL is done, the code falls through to the next statement ... which happens to set WS-DATA-ITEM3 to an X -- unless the search failed in which case who knows which occurrence of WS-DATA-ITEM3 gets set to X (or possibly none of them).

When you post code, post the exact code being used. You don't have to post extra code -- extract only the data definitions and PROCEDURE DIVISION statements that are relevant; if you don't include enough we'll let you know. But don't post something you've munged up from the original code.
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 first column truncated in search result IBM Tools 13
No new posts Cobol file using index COBOL Programming 2
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
Search our Forums:

Back to Top