Saturday, November 19, 2011

Sequential SEARCH


During SERIAL SEARCH, the first entry of the table is searched. If the condition is met, the table look-up is completed. If the condition is not met, then index or subscript is incremented by one and the next entry is searched and the process continues until a match is found or the table has been completely searched.

          SET indexname-1 TO 1.
          SEARCH identifier-1 AT END display ‘match not found:’
             WHEN condition-1 imperative statement-1 /NEXT SENTENCE
             WHEN condition-2 imperative statement-2 /NEXT SENTENCE
          END-SEARCH
Identifier-1 should be OCCURS item and not 01 item.
Condition-1, Condition-2 compares an input field or search argument with a table argument.
Though AT END Clause is optional, it is highly recommended to code that. Because if it is not coded and element looking for is not found, then the control simply comes to the next statement after SEARCH where an invalid table item can be referred and that may lead to incorrect results / abnormal ends.

SET statement Syntax:
          SET index-name-1 TO/UP BY/DOWN BY integer-1.

 

No comments:

Post a Comment