Group:
My apologies for top-posting this - but for those who have already read 6 other
variations on this code, it would be a pain to page down below the original request,
and for those who have not seen the original request, it would be a pain to have to go
find it.
There are as many good ways to code this as there are programmers - here is what I
would do, preserving the variables as much as possible because I assume this code
fragment fits into a larger program and you don't want to have to modify the whole
program.
STARTPOS = 1 ; * Set the first value to be checked!
SPECIAL.VAL = "" ; * Assuming that you will want this later on eg to decrement the qty
if ordered, reserve it, etc.
SPECIAL.FROM.QTY.TEMP = 0
SPECIAL.PARTS = SPECIAL.REC<12>
LOOP
LOCATE PART.NBR IN SPECIAL.PARTS<1,STARTPOS> SETTING SPECIAL ELSE SPECIAL = ""
UNTIL SPECIAL = "" DO
SPECIAL.FROM.QTY = SPECIAL.REC<14,SPECIAL>
IF SPECIAL.FROM.QTY < QTY.REQUESTED THEN
IF SPECIAL.FROM.QTY.TEMP < SPECIAL.FROM.QTY THEN
SPECIAL.FROM.QTY.TEMP = SPECIAL.FROM.QTY
SPECIAL.VAL = SPECIAL ; * the value for the part number desired with the
greatest qty at or above desired qty
END
END
STARTPOS = SPECIAL + 1
REPEAT
IF SPECIAL.VAL = "" THEN
DATA.OUT = "Part ":PART.NBR:", Qty ":QTY.REQUESTED:" not found." ; * or other error
logic...
END ELSE
SPECIAL.PART.PRICE = SPECIAL.REC<16,SPECIAL.VAL> ; * You only need to do this once
at the end!
DATA.OUT = OCONV(SPECIAL.PART.PRICE,MDP)"R#12"
END
RETURN
Susan M. Lynch
F.W. Davison & Company, Inc.
Original message from [EMAIL PROTECTED]:
I'm looking for an algorithm for searching through a group of associated multi-value
fields. The fields are F12 (PartsList), F14 (From Qty) and F16 (Unit Price). I can't
depend on these being in any certain order, just that the associated fields will be in
identical order. What I want to return is the Unit Price (F16) given PART.NBR and
QTY.REQUESTED. I've got a code snippet of what I think will work, but I'd like to get
some feedback on it...it won't work because, there's a better way of doing this, etc.
Thanks.
SPECIAL.PARTS = SPECIAL.REC<12>
SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM)
SPECIAL.FROM.QTY.TEMP = 0
FOR SPECIALPART = 1 TO SPECIALCOUNT
LOCATE PART.NBR IN SPECIAL.PARTS<1,STARTPOS> SETTING SPECIAL ELSE EXIT
SPECIAL.FROM.QTY=SPECIAL.REC<14,SPECIAL>
IF SPECIAL.FROM.QTY<QTY.REQUESTED AND SPECIAL.FROM.QTY>=SPECIAL.FROM.QTY.TEMP THEN
SPECIAL.FROM.QTY = SPECIAL.REC<14,SPECIAL>
SPECIAL.PART.PRICE = SPECIAL.REC<16,SPECIAL>
TEMP.OUT = OCONV(SPECIAL.PART.PRICE,MDP) "R#12"
SPECIAL.FROM.QTY.TEMP = SPECIAL.FROM.QTY
END
STARTPOS = SPECIAL + 1
FIRST = 0
NEXT SPECIALPART
DATA.OUT=TEMP.OUT
RETURN
--
u2-users mailing list
[EMAIL PROTECTED]
http://www.oliver.com/mailman/listinfo/u2-users