INSERT Function
Inserts an attribute, value or subvalue into a dynamic array.
Note
INSERT has been replaced by the INS statement but is maintained for compatibility.
Syntax
INSERT(dyn-array,attr,val#,subval#,char-string)
or
INSERT(dyn-array,attr#{,val#};char-string)
Syntax Elements
dyn-array is the name of the dynamic array or variable into which the field is to be inserted.
attr# is the number of the attribute within dyn-array where the field is to be inserted.
If you specify a nonzero value for attr# and zero for both value# and subvalue#, the field is inserted into dyn-array as the specified attribute.
val# is the value number within the named attribute where the field is to be inserted.
If you specify a nonzero value for both attr# and value# and zero for subvalue#, the field is inserted as the specified value.
subval# is the subvalue number within the value where the field is to be inserted.
If you specify nonzero values for attr#, value# and subval#, the field is inserted as the specified subvalue.
char-string is the string to be inserted, expressed as a variable or a literal enclosed in quotes. It cannot contain any system delimiters.
Comments
If attr#, value# or subval# contains -1, the value specified by char-string is inserted after the last attribute, value or subvalue indicated. Otherwise, char-string is inserted before the specified attribute, value or subvalue.
Refer to the INS statement for information regarding invalid and illogical dynamic array references.
Examples
OPEN '','TEST-FILE' ELSE STOP
READ X FROM 'NAME' ELSE STOP
X = INSERT(X,10,0,0,'XXXXX')
WRITE X ON 'NAME'
Inserts the value XXXXX before attribute 10 of item NAME, creating a new attribute.
OPEN 'FN1' ELSE STOP
READ B FROM 'IT5' ELSE STOP
A = INSERT(B,-1,0,0,'EXAMPLE')
WRITE A ON 'IT5'
Inserts the string value EXAMPLE after the last attribute of item IT5 in file FN1.
Y=INSERT(X,3,2,0,"XYZ")
Inserts the string value XYZ before the second value of attribute 3 of dynamic array X and assigns the resulting array to variable Y.
A = "123456789" B = INSERT(B,3,-1,0,A)
Inserts 123456789 after the last value of attribute 3 of dynamic array B.
Z = INSERT(W,5,1,1,"B")
Inserts the string value B before the first subvalue of the first value of attribute 5 in array W and assigns the resulting array to Z.