POSIT: Finding the Beginning of a Substring

How to:

Available Languages: reporting

The POSIT function finds the starting position of a substring within a source string. For example, the starting position of the substring DUCT in the string PRODUCTION is 4. If the substring is not in the parent string, the function returns the value 0.

There is a version of the POSIT function that is available only in the Maintain language. For information on this function, see POSIT: Finding the Beginning of a Substring (Maintain).

Syntax: How to Find the Beginning of a Substring

POSIT(source_string, length, substring, sublength, output)

where:

source_string

Alphanumeric

Is the string to parse enclosed in single quotation marks, or a field or variable that contains the source character string.

length

Integer

Is the number of characters in the source string, or a field that contains the length. If this argument is less than or equal to 0, the function returns a 0.

substring

Alphanumeric

Is the substring whose position you want to find. This can be the substring enclosed in single quotation marks, or the field that contains the string.

sublength

Integer

Is the number of characters in substring. If this argument is less than or equal to 0, or if it is greater than length, the function returns a 0.

output

Integer

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.

Example: Finding the Position of a Letter

POSIT determines the position of the first capital letter I in LAST_NAME and stores the result in I_IN_NAME:

TABLE FILE EMPLOYEE
PRINT LAST_NAME AND COMPUTE
I_IN_NAME/I2 = POSIT(LAST_NAME, 15, 'I', 1, 'I2');
WHERE DEPARTMENT EQ 'PRODUCTION'
END

The output is:

LAST_NAME        I_IN_NAME
---------        ---------
STEVENS                  0
SMITH                    3
BANNING                  5
IRVING                   1
ROMANS                   0
MCKNIGHT                 5