Here's a generic sort routine to use as an example.  It is capable of
sorting any number of attributes in a file.  Basically, after using LOCATE
you have to use INSERT.

*TEST.SORT Sort unlimited associated fields off of one field
OPEN "", "ORDER.BACK" TO ORDER.BACK ELSE PRINT "GAAAAAA";STOP
ORD = ""
ORD<11> = CHANGE('789,456,123',",",@VM)
ORD<12> = CHANGE('1,2,3',",",@VM)
ORD<13> = CHANGE('4,5,6',",",@VM)
ORD<14> = CHANGE('SOMETHING, THAT, SHOULDNOTCHANGE',",",@VM)
ORD<31> = CHANGE('7,8,9',",",@VM)
ORD<32> = CHANGE('10,11,12',",",@VM)

* Setup Parameters
SORT.REC   = ORD
ATTR.LIST  = "12,13,31,32"
ATTR.LIST  = CHANGE(ATTR.LIST, ",", @AM)
ATTR.COUNT = DCOUNT(ATTR.LIST,@AM)
DATA.BASE  = ""
SORT.ATTR  = 11
SORT.BASE  = ""
SORT.COUNT = DCOUNT(SORT.REC<SORT.ATTR>,@VM)
* Sort the data based off of the sort attribute in the sort record
FOR SORT.I = 1 TO SORT.COUNT
  SORT.VALUE = SORT.REC<SORT.ATTR, SORT.I>
  LOCATE SORT.VALUE IN SORT.BASE<1>,1 BY 'AR' SETTING SORT.INDEX ELSE NULL
  SORT.BASE = INSERT(SORT.BASE, 1, SORT.INDEX, 0, SORT.VALUE)
  FOR ATTR.I = 1 TO ATTR.COUNT
    ATTR = ATTR.LIST<ATTR.I>
    ATTR.VALUE = SORT.REC<ATTR, SORT.I>
    DATA.BASE<ATTR.I> = INSERT(DATA.BASE<ATTR.I>, 1, SORT.INDEX, 0,
ATTR.VALUE)
  NEXT ATTR.I
NEXT SORT.I
* Replace the sort record with the sorted values
SORT.REC<SORT.ATTR> = SORT.BASE
FOR ATTR.I = 1 TO ATTR.COUNT
  ATTR = ATTR.LIST<ATTR.I>
  SORT.REC<ATTR> = DATA.BASE<ATTR.I>
NEXT ATTR.I
ORD = SORT.REC
WRITE ORD ON ORDER.BACK, 'TEST.SORT'
STOP

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Al DeWitt
Sent: Monday, November 07, 2005 15:27
To: [email protected]
Subject: [U2] Sort help needed


Environment: UniData - Pick Flavor



I'm trying to build a multi-value field in part number order.



I begin with LOCATE PART.NBR IN RECORD<14> BY "AL" SETTING POS ELSE POS
= 0



The first time through RECORD<14> is empty.  The second time RECORD<14>
has one value.  If PART.NBR is of greater value than what is now in
RECORD<14> then I want PART.NBR to be the second value, if it is of
lesser value than I want PART.NBR to be inserted before the value in
RECORD<14>.



I will then do a second LOCATE to see where PART.NBR is stored
(RECORD<14,x>) and use that position to insert data into associated
attributes.



My problem is that I haven't done this in a while and when I did it was
in Universe.  So not only am I suffering a senior moment I'm dealing
with a language barrier.



Any help would be greatly appreciated.



Thanks.



Al DeWitt

Stylmark, Inc.
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to