INDEX

INDEX returns an unscaled REAL FIXED BINARY value that indicates the starting position within x of a substring identical to y. You can also specify the location within x where processing begins.

Read syntax diagramSkip visual syntax diagramINDEX( x, y, n)
x
String-expression to be searched.
y
Target string-expression of the search.
n
n specifies the location within x at which to begin processing. It must have a computational type and is converted to FIXED BINARY(31,0).

If y does not occur in x, or if either x or y have zero length, the value zero is returned.

If n is less than 1 or if n is greater than 1 + length(x), the STRINGRANGE condition will be raised, and the result will be 0.

The BIFPREC compiler option determines the precision of the result returned.

INDEX will perform best when the second and third arguments are either literals, named constants declared with the VALUE attribute, or restricted expressions.

Example

  dcl tractatus char
        value( 'Wovon man nicht sprechen kann, ' ∥
               'darueber muss man schweigen.' );

  dcl pos fixed bin init(1);

  pos = index( tractatus, 'man', pos+1 ); /* pos = 07 */

  pos = index( tractatus, 'man', pos+1 ); /* pos = 46 */

  pos = index( tractatus, 'man', pos+1 ); /* pos = 00 */