View previous topic :: View next topic
|
Author |
Message |
rammraju
New User
Joined: 05 Mar 2005 Posts: 65 Location: Hyderabad
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
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. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 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. |
|
Back to top |
|
|
|