COL2 function

Syntax

COL2 ( )

Description

Use the COL2 function after the execution of a FIELD function to return the numeric value for the character position that immediately follows the selected substring (see the FIELD function). Although the COL2 function takes no arguments, parentheses are required to identify it as a function.

The value obtained from COL2 is local to the program or subroutine executing the FIELD function. Before entering a subroutine, the current value of COL2 in the main program is saved. The value of COL2 in the subroutine is initialized as 0. When control is returned to the calling program, the saved value of COL2 is restored.

If no FIELD function precedes the COL2 function, a value of 0 is returned. If the delimiter expression of the FIELD function is an empty string or the null value, or if the string is not found, the COL2 function returns a 0 value.

Examples

The FIELD function in the following example returns the substring 111. COL2( ) returns 4, the position of the delimiter ( # ) that follows 111.

SUBSTRING=FIELD("111#222#3","#",1)
P=COL2()

In the following example, the FIELD function returns a substring of two fields with the delimiter ( & ) that separates them: 7&8. COL2( ) returns 5, the position of the delimiter that follows 8.

SUBSTRING=FIELD("&7&8&B&","&",2,2)
S=COL2()

In the next example, FIELD( ) returns the whole string, because the delimiter ( . ) is not found. COL2( ) returns 6, the position after the last character of the string.

SUBSTRING=FIELD("9*8*7",".",1)
Y=COL2()

In the next example, FIELD( ) returns an empty string, because there is no tenth occurrence of the substring in the string. COL2( ) returns 0 because the substring was not found.

SUBSTRING=FIELD("9*8*7","*",10)
O=COL2()