GROUPSTORE statement

Syntax

GROUPSTORE new.string IN string USING start, n [ ,delimiter]

Description

Use the GROUPSTORE statement to modify character strings by inserting, deleting, or replacing fields separated by specified delimiters.

new.string is an expression that evaluates to the character string to be inserted in string.

string is an expression that evaluates to the character string to be modified.

delimiter evaluates to any single ASCII character, including field, value, and subvalue marks. If you do not specify delimiter, the field mark is used.

start evaluates to a number specifying the starting field position. Modification begins at the field specified by start. If start is greater than the number of fields in string, the required number of empty fields is generated before the GROUPSTORE statement is executed.

n specifies the number of fields of new.string to insert in string. n determines how the GROUPSTORE operation is executed. If n is positive, n fields in string are replaced with the first n fields of new.string. If n is negative, n fields in string are replaced with all the fields in new.string. If n is 0, all the fields in new.string are inserted in string before the field specified by start.

If string evaluates to the null value, null is returned. If new.string, start, n, or delimiter is null, the GROUPSTORE statement fails and the program terminates with a run-time error message.

Example

Q='1#2#3#4#5'
GROUPSTORE "A#B" IN Q USING 2,2,"#"
PRINT "TEST1= ",Q
*
Q='1#2#3#4#5'
GROUPSTORE "A#B" IN Q USING 2,-2,"#"
PRINT "TEST2= ",Q
*
Q='1#2#3#4#5'
GROUPSTORE "A#B" IN Q USING 2,0,"#"
PRINT "TEST3= ",Q
*
Q='1#2#3#4#5'
GROUPSTORE "A#B#C#D" IN Q USING 1,4,"#"
PRINT "TEST4= ",Q
*
Q='1#2#3#4#5'
GROUPSTORE "A#B#C#D" IN Q USING 7,3,"#"
PRINT "TEST5= ",Q

This is the program output:

TEST1=   1#A#B#4#5
TEST2=   1#A#B#4#5
TEST3=   1#A#B#2#3#4#5
TEST4=   A#B#C#D#5
TEST5=   1#2#3#4#5##A#B#C