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
05 WS-TABLE-DATA OCCURS 50 TIMES
ASCENDING KEY IS WS-DATA-ITEM1,
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
SEARCH ALL WS-TABLE-DATA
WHEN WS-DATA-ITEM1(WS-INDEX) = WS-DATA-ITEM1 AND
WS-DATA-ITEM1(WS-INDEX) = WS-DATA-ITEM2
MOVE 'X' TO WS-DATA-ITEM3(WS-INDEX1).
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?
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
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.
Joined: 06 Jun 2008 Posts: 8280 Location: Dubuque, Iowa, USA
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.