INS, INSERT()

Top  Previous  Next

 

The INS statement and INSERT() function insert a field, value or subvalue into a dynamic array.

 

 

Format

 

INS string BEFORE dyn.array<field {, value {, subvalue}}>

INSERT(dyn.array, field {, value {, subvalue}} , string)

 

where

 

stringis the string to be inserted.

 

dyn.arrayis the dynamic array into which the item is to be inserted.

 

fieldevaluates to the number of the field before which insertion is to occur.

 

valueevaluates to the number of the value before which insertion is to occur. If omitted or zero, value 1 is assumed.

 

subvalueevaluates to the number of the subvalue before which insertion is to occur. If omitted or zero, subvalue 1 is assumed.

 

 

The string is inserted before the specified field, value or subvalue of the dynamic array. The INS statement assigns the result to the dyn.array variable. The INSERT() function returns the result without modifying dyn.array.

 

A negative value of field, value or subvalue causes the next item at this level to be appended. For example,

INS X BEFORE S<3, -1>

appends X as a new value at the end of field 3 of S. See the description of the S<f,v,sv> assignment operator for a discussion of how QM appends items.

 

Additional delimiters will be added to reach the specified field, value and subvalue unless the string to be inserted is null. Absent fields, values and subvalues are assumed to be null so there is no need to insert additional marks in this case.

 

 

 

Example

 

LOCATE PART.NO IN PARTS<1> BY "AL" SETTING I ELSE

  INS PART.NO BEFORE PARTS<I>

END

 

This program fragment locates PART.NO in a sorted list PARTS and, if it is not already present, inserts it.

 

 

See also:

DEL, DELETE(), EXTRACT(), FIND, FINDSTR, LISTINDEX(), LOCATE, LOCATE(), REPLACE()