Quiz Question:

Chris Sharman Chris.Sharman@ccagroup.co.uk
Fri, 15 Jan 1999 13:59:41 +0000


>I would like to create a new subfile with all of the above fields + Minimum
>field + Minimum $ value. i.e.  
>
>	FIELDA 	Alpha Numeric value X(2)	    	AA
>            FIELDB             Alpha Numeric value X(2)		BB
>            FIELDC             Alpha Numeric value X(2)		CC
>            FIELDD             Alpha Numeric value X(2)		DD
>            FIELDA-DOL      $					$1.20
>            FIELDB-DOL      $					$1.05
>            FIELDC-DOL      $					$1.50
>            FIELDD-DOL      $					$1.70
>            Minimum-Field    Alpha Numeric value X(2)                BB 
>            Minimum-Dol      $					$1.05
>
>Incase of if the $value are the same, the order of the field value picked is
>in the order of a,b,c,d.
>
>Is there an easy way to do above in QUIZ.  Any tricks provided is greatly
>appreciated.   

No special trick. Powerhouse isn't really that good at arrays, it works better
if you normalise your data structures

def mindol = fielda-dol if (fielda-dol<=fieldb-dol) and &
				(fielda-dol<=fieldc-dol) and &
				(fielda-dol<=fieldd-dol) &
	else fieldb-dol if (fieldb-dol<=fieldc-dol) and &
				(fieldb-dol<=fieldd-dol) &
	else fieldc-dol if (fieldc-dol<=fieldd-dol) &
	else fieldd-dol
def minfield char*2 = fielda if (fielda-dol<=fieldb-dol) and &
				(fielda-dol<=fieldc-dol) and &
				(fielda-dol<=fieldd-dol) &
	else fieldb if (fieldb-dol<=fieldc-dol) and &
				(fieldb-dol<=fieldd-dol) &
	else fieldc if (fieldc-dol<=fieldd-dol) &
	else fieldd

Pretty tedious stuff, and it gets worse (in both readability & execution speed)
as order n-squared. Another technique useful for larger number of values:

$ qtp
> run addmin
> ; I added record-id in case you have more than 1 record
> ; If you don't have a record-id, you could utilise a record counter
> request normalise
> access *infile
> subfile normfile &
>	include record-id, fielda alias field, fielda-dol alias dol
> subfile normfile alias normb append &
>	include record-id, fieldb, fieldb-dol
> subfile normfile alias normc append &
>	include record-id, fieldc, fieldc-dol
> subfile normfile alias normd append &
>	include record-id, fieldd, fieldd-dol

> request minimise
> access *normfile
> sorted on record-id
> temp mindol
> temp minfield char*2
> item minfield = field if (mindol>dol)
> item mindol min dol reset at record-id
> subfile minfile at record-id index record-id &
>	include record-id, minfield, mindol
>
> request output
> access *infile link to *minfile
> subfile outfile include record-id, fielda, fieldb, fieldc, fieldd, &
>	fielda-dol, fieldb-dol, fieldc-dol, fieldd-dol, minfield, mindol
______________________________________________________________________
Chris Sharman			Chris.Sharman@CCAgroup.co.uk
CCA Stationery Ltd, Eastway, Fulwood, Preston, Lancashire, PR2 9WS.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
powerh-l@lists.swau.edu is gatewayed one-way to bit.listserv.powerh-l
This list is closed, thus to post to the list, you must be a subscriber.