I came across this old source I was playing with and never had the time to manufacture an answer until now...so I thought I'd ask about it here...
How do you use SEARCH or SEARCH ALL against a multiple level table? Do these verbs only restrict you to one level or can you successfully search multi-level tables? I never found much of a conclusive answer to this one, so I ended up just rolling my own search and let it be.
The answer I came up with is that SEARCH only seems to allow varying only one index. Like for example, if I vary my first index, I only get hits if the items I search for are in position #1 of the second level. Likewise if I vary the second index I only get to search the first level.
What I ended up doing was throwing SEARCH (varying the second index) into a perform loop that varied the first.
Is there a way to do a complete search on a multi-level table just using SEARCH or SEARCH ALL and not additional code?
A quick simplified table example:
What my answer ended up being:
How do you use SEARCH or SEARCH ALL against a multiple level table? Do these verbs only restrict you to one level or can you successfully search multi-level tables? I never found much of a conclusive answer to this one, so I ended up just rolling my own search and let it be.
The answer I came up with is that SEARCH only seems to allow varying only one index. Like for example, if I vary my first index, I only get hits if the items I search for are in position #1 of the second level. Likewise if I vary the second index I only get to search the first level.
What I ended up doing was throwing SEARCH (varying the second index) into a perform loop that varied the first.
Is there a way to do a complete search on a multi-level table just using SEARCH or SEARCH ALL and not additional code?
A quick simplified table example:
Code:
01 TEMP-DATA REDEFINES TEMP-FILLER.
04 TABLE-first OCCURS 12 TIMES INDEXED BY first-NDX.
08 TABLE-second OCCURS 10 TIMES INDEXED BY second-NDX.
12 TEMP-VALUE PIC 9(2).
What my answer ended up being:
Code:
PERFORM VARYING FIRST-NDX FROM 1 BY 1 UNTIL FIRST-NDX > 12
SET SECOND-NDX TO 1
PERFORM 1000-PROC-SECTION
END-PERFORM.
1000-PROC-SECTION.
SEARCH TABLE-SECOND VARYING SECOND-NDX
AT END DISPLAY 'YOUR VALUE WAS NOT FOUND.'
WHEN TEMP-VALUE(FIRST-NDX, SECOND-NDX) = INPUT-NUMBER
DISPLAY 'YOUR VALUE WAS FOUND'
END-SEARCH.