CONTAINS

Figure 1. Syntax

1 COntains(haystack,+ , needle)

Checks the contents of haystack for one or more occurrences of needle.

Returns
If the haystack string contains one or more of the needle strings, then CONTAINS returns 1. Otherwise, CONTAINS returns 0.

CONTAINS is case-sensitive: it only returns 1 if the haystack contains a string with the same mix of uppercase and lowercase as a needle.

haystack
The string that you want to search.
needle
The string that you are attempting to find within haystack. You can search for up to 20 strings at a time.

For a similar function that matches numeric values, see NCONTAIN. For a FASTREXX-eligible equivalent, see FLD_CO.

Example 1

If the current input record contains “Michael”, “Mick” or “Mike” in the first ten columns, then print the record.
If CO(FLD(1,10),'Michael','Mick','Mike') Then
  PRINT(inrec, 'CHAR')

Example 2

If the current input record contains “USA”, “Australia” or “England”, then drop the record from processing.
If CONTAINS(inrec,'USA','Australia','England') Then
  Return 'DROP'