RE: Looking for associated multi-value algorithm...
Just to address a couple of your comments... The reason I use SPECIAL so much is the file I'm reading this information from is SPECIAL.PRICE. The fields I'm referencing are from something similar to a sales quote. I'd expect the quantity numbers to rarely match. The fields I'm referencing are Part Number, From Qty and Sales Price. So there could be 5 iterations of part number 12345 with From Qtys of 0, 1000, 2000, 4000 and 1 and Prices of 0.35200, 0.34200, 0.33200, 0.31200 and 0.29200. From experience, I know that I can't count on each of these triads being in any particular order, except for the fact that each mv will be in the same order as the other 2 for any given record. This is information living in my ERP system. -Original Message- From: Mark Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 5:46 PM To: U2 Users Discussion List Subject: Re: Looking for associated multi-value algorithm... Perhaps the most glaring problem here is the level of the LOCATE. Since SPECIAL.PARTS is a value and thus possibly multi-valued, the ,STARTPOS indicator suggests to the LOCATE to look at the first subvalue of the value'd. Somehow, especially since STARTPOS isn't previously defined, it become zero and 1,0 is the same as 1 which may accidentally satisfiy the LOCATE. Remove the commaSTARTPOS from the in the LOCATE and the STARTPOS=SPECIAL+1 as they don't contribute anything. Also, this looks like a FIFO/LIFO algorithm. What are the failures if the qtys don't match. The LOCATE should eliminate the FOR...NEXT loop unless you have the PART.NBR in the 12 more than once. In any case, the FOR...NEXT is is useless. If the PART.NBR is in 12 more than once, use FOR...NEXT and do a simple equals test on 12. I don't believe that LOCATE can find occurrences of PART.NBR after the first one it finds. At least using numbers inside the . Perhaps LOCATE X in Y1,STARTPOS on the outside. I don't use it. FInally, if it's any contribution (and it's my purely non-technical opinion). Remove all the extraneous uses of the prefix SPECIAL. That makes it hard to read as all the variables start with SPECIAL and it's hard to identify their purpose quickly. I'm sure I'll get flamed for this, but it does make it more readable. PARTS=SPECIAL.REC12 C.PARTS=DCOUNT(PARTS,VM) QTYS=SPECIAL.REC14 ; PRICES=SPECIAL.REC16 QTEMP=0 FOR I=1 TO C.PARTS IF PARTS1,I=PART.NBR THEN QTY=QTYS1,I IF QTY QTY.REQUESTED AND QTY QTEMP THEN DATA.OUT=OCONV(PRICES1,I,MDP)R#12 QTEMP=QTY END END NEXT I my 2 cents. 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.REC12 SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM) SPECIAL.FROM.QTY.TEMP = 0 FOR SPECIALPART = 1 TO SPECIALCOUNT LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE EXIT SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL IF SPECIAL.FROM.QTYQTY.REQUESTED AND SPECIAL.FROM.QTY=SPECIAL.FROM.QTY.TEMP THEN SPECIAL.FROM.QTY = SPECIAL.REC14,SPECIAL SPECIAL.PART.PRICE = SPECIAL.REC16,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 -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users
RE: Looking for associated multi-value algorithm...
Well, the first thing I notice is that your for/next counter, SPECIALPART, isn't used anywhere... Using LOCATE will search for the PART.NBR in the whole SPECIAL.PARTS field, so the for/next isn't needed. Next, I notice that this assignment: SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL is duplicated, once just before the IF and once just after the THEN. One of them can probably be dropped. Hope this helps some Jeff Fitzgerald Fitzgerald Long, Inc. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 3:18 PM To: [EMAIL PROTECTED] Subject: Looking for associated multi-value algorithm... 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.REC12 SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM) SPECIAL.FROM.QTY.TEMP = 0 FOR SPECIALPART = 1 TO SPECIALCOUNT LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE EXIT SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL IF SPECIAL.FROM.QTYQTY.REQUESTED AND SPECIAL.FROM.QTY=SPECIAL.FROM.QTY.TEMP THEN SPECIAL.FROM.QTY = SPECIAL.REC14,SPECIAL SPECIAL.PART.PRICE = SPECIAL.REC16,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 -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users
RE: Looking for associated multi-value algorithm...
There can, and usually are, multiple instances of the same part number. What makes a row unique is part number + from qty. Thanks for pointing out the doubling up of the SPECIAL.FROM.QTY assignment though. -Original Message- From: Jeff Fitzgerald [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 4:28 PM To: 'U2 Users Discussion List' Subject: RE: Looking for associated multi-value algorithm... Well, the first thing I notice is that your for/next counter, SPECIALPART, isn't used anywhere... Using LOCATE will search for the PART.NBR in the whole SPECIAL.PARTS field, so the for/next isn't needed. Next, I notice that this assignment: SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL is duplicated, once just before the IF and once just after the THEN. One of them can probably be dropped. Hope this helps some Jeff Fitzgerald Fitzgerald Long, Inc. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 3:18 PM To: [EMAIL PROTECTED] Subject: Looking for associated multi-value algorithm... 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.REC12 SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM) SPECIAL.FROM.QTY.TEMP = 0 FOR SPECIALPART = 1 TO SPECIALCOUNT LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE EXIT SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL IF SPECIAL.FROM.QTYQTY.REQUESTED AND SPECIAL.FROM.QTY=SPECIAL.FROM.QTY.TEMP THEN SPECIAL.FROM.QTY = SPECIAL.REC14,SPECIAL SPECIAL.PART.PRICE = SPECIAL.REC16,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 -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users
Re: Looking for associated multi-value algorithm...
It looks like you are using SPECIAL and STARTPOS as paired dummy buffers to walk across the SPECIAL.PARTS, each iteration only searching the remainder from where you left off. That's a little counter-intuitive :) Maybe better nomenclature would make that more apparent. Like Startpos and Currentpos ? I can see why you got this response however, because at first I thought you were wrong again Jason ;) then I read the code again and it hit me what you were doing. Will In a message dated 3/16/2004 6:04:48 PM Eastern Standard Time, [EMAIL PROTECTED] writes: There can, and usually are, multiple instances of the same part number. What makes a row unique is part number + from qty. Thanks for pointing out the doubling up of the SPECIAL.FROM.QTY assignment though. -Original Message- From: Jeff Fitzgerald [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 4:28 PM To: 'U2 Users Discussion List' Subject: RE: Looking for associated multi-value algorithm... Well, the first thing I notice is that your for/next counter, SPECIALPART, isn't used anywhere... Using LOCATE will search for the PART.NBR in the whole SPECIAL.PARTS field, so the for/next isn't needed. Next, I notice that this assignment: SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL is duplicated, once just before the IF and once just after the THEN. One of them can probably be dropped. Hope this helps some Jeff Fitzgerald Fitzgerald Long, Inc. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 3:18 PM To: [EMAIL PROTECTED] Subject: Looking for associated multi-value algorithm... 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.REC12 SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM) SPECIAL.FROM.QTY.TEMP = 0 FOR SPECIALPART = 1 TO SPECIALCOUNT LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE EXIT SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL IF SPECIAL.FROM.QTYQTY.REQUESTED AND SPECIAL.FROM.QTY=SPECIAL.FROM.QTY.TEMP THEN SPECIAL.FROM.QTY = SPECIAL.REC14,SPECIAL SPECIAL.PART.PRICE = SPECIAL.REC16,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
RE: Looking for associated multi-value algorithm...
All Righty, then! Just for grins, here's an alternative: SPECIAL.PARTS = SPECIAL.REC12 POS = 0 SPECIAL.FROM.QTY.TEMP = 0 REMOVE SPECIAL.PART.NBR FROM SPECIAL.PARTS SETTING MORE.PARTS POS += 1 IF SPECIAL.PART.NBR = PART.NBR THEN SPECIAL.FROM.QTY = SPECIAL.REC14, POS IF SPECIAL.FROM.QTY QTY.REQUESTED AND SPECIAL.FROM.QTY = SPECIAL.FROM.QTY.TEMP THEN TEMP.POS = POS SPECIAL.FROM.QTY.TEMP = SPECIAL.FROM.QTY END END WHILE MORE.PARTS DO REPEAT DATA.OUT = OCONV(SPECIAL.REC16, TEMP.POS, MDP) R#12 RETURN Have fun! Jeff Fitzgerald Fitzgerald Long, Inc. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 3:59 PM To: [EMAIL PROTECTED] Subject: RE: Looking for associated multi-value algorithm... There can, and usually are, multiple instances of the same part number. What makes a row unique is part number + from qty. Thanks for pointing out the doubling up of the SPECIAL.FROM.QTY assignment though. -Original Message- From: Jeff Fitzgerald [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 4:28 PM To: 'U2 Users Discussion List' Subject: RE: Looking for associated multi-value algorithm... Well, the first thing I notice is that your for/next counter, SPECIALPART, isn't used anywhere... Using LOCATE will search for the PART.NBR in the whole SPECIAL.PARTS field, so the for/next isn't needed. Next, I notice that this assignment: SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL is duplicated, once just before the IF and once just after the THEN. One of them can probably be dropped. Hope this helps some Jeff Fitzgerald Fitzgerald Long, Inc. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 16, 2004 3:18 PM To: [EMAIL PROTECTED] Subject: Looking for associated multi-value algorithm... 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.REC12 SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM) SPECIAL.FROM.QTY.TEMP = 0 FOR SPECIALPART = 1 TO SPECIALCOUNT LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE EXIT SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL IF SPECIAL.FROM.QTYQTY.REQUESTED AND SPECIAL.FROM.QTY=SPECIAL.FROM.QTY.TEMP THEN SPECIAL.FROM.QTY = SPECIAL.REC14,SPECIAL SPECIAL.PART.PRICE = SPECIAL.REC16,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 -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users
Re: Looking for associated multi-value algorithm...
Perhaps the most glaring problem here is the level of the LOCATE. Since SPECIAL.PARTS is a value and thus possibly multi-valued, the ,STARTPOS indicator suggests to the LOCATE to look at the first subvalue of the value'd. Somehow, especially since STARTPOS isn't previously defined, it become zero and 1,0 is the same as 1 which may accidentally satisfiy the LOCATE. Remove the commaSTARTPOS from the in the LOCATE and the STARTPOS=SPECIAL+1 as they don't contribute anything. Also, this looks like a FIFO/LIFO algorithm. What are the failures if the qtys don't match. The LOCATE should eliminate the FOR...NEXT loop unless you have the PART.NBR in the 12 more than once. In any case, the FOR...NEXT is is useless. If the PART.NBR is in 12 more than once, use FOR...NEXT and do a simple equals test on 12. I don't believe that LOCATE can find occurrences of PART.NBR after the first one it finds. At least using numbers inside the . Perhaps LOCATE X in Y1,STARTPOS on the outside. I don't use it. FInally, if it's any contribution (and it's my purely non-technical opinion). Remove all the extraneous uses of the prefix SPECIAL. That makes it hard to read as all the variables start with SPECIAL and it's hard to identify their purpose quickly. I'm sure I'll get flamed for this, but it does make it more readable. PARTS=SPECIAL.REC12 C.PARTS=DCOUNT(PARTS,VM) QTYS=SPECIAL.REC14 ; PRICES=SPECIAL.REC16 QTEMP=0 FOR I=1 TO C.PARTS IF PARTS1,I=PART.NBR THEN QTY=QTYS1,I IF QTY QTY.REQUESTED AND QTY QTEMP THEN DATA.OUT=OCONV(PRICES1,I,MDP)R#12 QTEMP=QTY END END NEXT I my 2 cents. 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.REC12 SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM) SPECIAL.FROM.QTY.TEMP = 0 FOR SPECIALPART = 1 TO SPECIALCOUNT LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE EXIT SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL IF SPECIAL.FROM.QTYQTY.REQUESTED AND SPECIAL.FROM.QTY=SPECIAL.FROM.QTY.TEMP THEN SPECIAL.FROM.QTY = SPECIAL.REC14,SPECIAL SPECIAL.PART.PRICE = SPECIAL.REC16,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 -- u2-users mailing list [EMAIL PROTECTED] http://www.oliver.com/mailman/listinfo/u2-users
RE: Looking for associated multi-value algorithm...
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.REC12 LOOP LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE SPECIAL = UNTIL SPECIAL = DO SPECIAL.FROM.QTY = SPECIAL.REC14,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.REC16,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.REC12 SPECIALCOUNT = DCOUNT(SPECIAL.PARTS,VM) SPECIAL.FROM.QTY.TEMP = 0 FOR SPECIALPART = 1 TO SPECIALCOUNT LOCATE PART.NBR IN SPECIAL.PARTS1,STARTPOS SETTING SPECIAL ELSE EXIT SPECIAL.FROM.QTY=SPECIAL.REC14,SPECIAL IF SPECIAL.FROM.QTYQTY.REQUESTED AND SPECIAL.FROM.QTY=SPECIAL.FROM.QTY.TEMP THEN SPECIAL.FROM.QTY = SPECIAL.REC14,SPECIAL SPECIAL.PART.PRICE = SPECIAL.REC16,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