GROUP Function

Returns a group of character-delimited fields from within a string.

Syntax

GROUP(string-expr, delimiter, start-field, no-of-fields)

Syntax Elements

string-expr is the string in which the fields are located. This can be any string expression.

delimiter is the character used as a field delimiter.

start-field is the number of the first field to return. The fields are numbered starting from 1. If the field number is less than 1, field 1 is assumed.

Note that this is different to the OCONV function, in which the fields are numbered starting from 0.

no-of-fields is the maximum number of fields to return. If no-of-fields is greater than the number of fields in the string, GROUP returns all fields from the specified starting field to the end of the string.

Comment

The fields are returned separated by delimiter.

The GROUP intrinsic function is similar to the group extract conversion (option G of the OCONV function), except that fields number from 1 and it allows any delimiter to be specified as the field separator, including system delimiters.

See Also

FIELD function, GROUPSTORE statement.

Examples

CITY = "IRVINE/ORANGE/TUSTIN"
Y = GROUP(CITY,"/",3,2)

Returns the value TUSTIN, because it is the third field in string CITY (start-field = 3). Only one element is returned because this is the last field in the string.

EQU AM TO CHAR(254)
A = "123":AM:"456":AM:"789":AM:"123"
X = GROUP(A,AM,1,2)

Returns the value 123^456, because they are the first two fields in string A.

B = "A/B/C/D/E"
Y = GROUP(B,"/",3,2)

Returns two fields, starting with the third field. Y now has the value C/D.

Go to top button