SEARCH


ANSI

 

The SEARCH instruction examines a list of variables for the specified key and returns an index indicating the item was the matching variable. The instruction uses the following format:

 

 

[label]

SEARCH

{source}{sep}{begin}{sep}{count}{sep}{match}

 

Where:

label

Optional. A Program Execution Label.

source

Required. A previously defined Character String Variable or Numeric Variable indicating the search key.

sep

Required. A comma or one of the following prepositions: BY, TO, OF, FROM, USING, WITH, IN, or INTO.

begin

Required. A previously defined Character String Variable or Numeric Variable indicating the search beginning variable.

count

Required. A previously defined Numeric Variable or Expression indicating the number of contiguous variables to search.

match

Required. A previously defined Numeric Variable indicating the variable number that matched.

Flags Affected: OVER, ZERO

Note the following:

  1. {source} and all the variables searched should be of the same data type in order for the search to succeed (i.e., all character strings or all FORMs).

  2. For character string searches, only the Logical String is used. On FORM searches, the entire Physical String is used and the sizes must match as the searching is done on a character by character basis in each field and not on a value of the entire field basis.

  3. The variables are searched in sequence beginning with {begin} until a match is found or the specified number of contiguous variables to search ({count}) is exhausted.

  4. If {begin} matches {source}, {match} is set to one. If the next contiguous variable matches {source}, {match} is set to two. If the next variable matches, {match} is set to three and so on.

  5. If a match is found, the EQUAL (or ZERO) Condition Flag is set. If no match is found, {match} is set to zero and the OVER Condition Flag is set.

  6. The search will terminate when a variable other than a DIM or FORM is encountered.

  7. Any or all of the variables may be ARRAY variables. They may be specific array elements: 'ARRAY(1)', or a variable array element: 'ARRAY(X)' (where 'X' is a numeric variable). If {begin} is an array element, the remaining array elements are searched prior to the next variable, since array elements are contiguous in memory.

  8. If {begin} is a POINTER array, the referenced item is the starting point of the search. Each successive item that is searched are those items that are physically contiguous to the first item searched, not the other elements of the pointer array.

 

 

See Also: Example Code, SCAN, Character String Instructions

 



PL/B Language Reference SDELETE SET