You are on page 1of 2

        

SEARCH.. WHEN..

SEARCH.. AT END

The SEARCH statement is used to locate or search for an


element
in a one-dimensional Table.

SEARCH Table � name


[AT END imperative statements]
WHEN condition 1[imperative statements]
[END SEARCH]

The following rules apply to the SEARCH statement.


1. The SEARCH statement can be applied to a Table only if it
is
indexed using INDEXED BY phrase.
2. Before using the SEARCH statement, the index must be
initialized
using a SET statement.
3. If the SEARCH statement terminates without finding the
particular
element in the Table, then the index has an unpredictable
value.
4. The SEARCH statement cannot be used to find multiple
matches.
5. The SEARCH statement does a sequential or serial search of
the table.
6. If search reaches end of array then at end statement will
be executed.

SEARCH Example :
01 WT-FIELDS.
05 WT-CODE-CTRL OCCURS 100 TIMES
INDEXED BY WT-CODE-CTRL-INDEX.
10 WT-CODE-VALUE PIC X(03).
10 WT-CODE-DESC PIC X(03).

SET WT-CODE-CTRL-INDEX TO 1.

SEARCH WT-CODE-CTRL
AT END
DISPLAY �SEARCH ELEMENET NOT FOUND IN
TABLE WT-CODE-CTRL�
WHEN WT-BILLER-CODE (WT-CODE-CTRL-INDEX) =
�121�
DISPLAY WT-CODE-DESC (WT-CODE-CTRL-INDEX)
END-SEARCH.

You might also like