Insert Command (AREV Specific)
At 27 AUG 1998 11:28:44AM Bruce Lee wrote:
Hello,
Will the insert command sort values as they are inserted? Basically, I am building a list of @vm delimitted items; however, I need the list to be built in sorted order. If the insert command will do this, what is the syntax.
Thank You,
Bruce Lee
At 27 AUG 1998 11:47AM Matt Sorrell wrote:
Bruce,
What you need to use first is the LOCATE … BY statment. What this does is determines where in the array the value would be, and returns the POS for that location. You can then insert at that POS. Here is a snippet of code that I use for that:
LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS ELSE
FNOS=INSERT(FNOS,1,POS,0,FN)END
The AL mnemonic indicates an ascending, left-justified search. Other possible values are:
AR - ascending, right-justified (usually used for numerics)
DL - descending, left-justified (text strings)
DR - descending, right-justified (numerics)
Obviously, ascending sorts from A - Z, and descending sorts from Z - A. I use the ELSE clause because I don't want to insert into the array if it already exists. If you do want to insert regardless, then the command would be as follows:
LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS THEN
FNOS=INSERT(FNOS,1,POS,0,FN)END ELSE
FNOS=INSERT(FNOS,1,POS,0,FN)END
This will insert into the array at the correct position regardless.
Hope this helps.
Matt
At 27 AUG 1998 11:48AM Matt Sorrell wrote:
Bruce,
What you need to use first is the LOCATE … BY statment. What this does is determines where in the array the value would be, and returns the POS for that location. You can then insert at that POS. Here is a snippet of code that I use for that:
LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS ELSE
FNOS=INSERT(FNOS,1,POS,0,FN)END
The AL mnemonic indicates an ascending, left-justified search. Other possible values are:
AR - ascending, right-justified (usually used for numerics)
DL - descending, left-justified (text strings)
DR - descending, right-justified (numerics)
Obviously, ascending sorts from A - Z, and descending sorts from Z - A. I use the ELSE clause because I don't want to insert into the array if it already exists. If you do want to insert regardless, then the command would be as follows:
LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS THEN
FNOS=INSERT(FNOS,1,POS,0,FN)END ELSE
FNOS=INSERT(FNOS,1,POS,0,FN)END
This will insert into the array at the correct position regardless.
Hope this helps.
Matt