SQL MAX() equivalent in ABL?

D.Cook

Member
I think I've had to solve this problem in the past but can't remember how...

If you're familiar with SQL, you'll know you can do something like SELECT MAX(a_column) FROM a_table, which will find the highest value of a numerical column in the table.

Is there a quick way to do this in ABL, or do I need to loop through every value, keeping a temp variable for the highest value?
 
Have a look at Aggregate phrase in the Manual

Code:
FOR EACH customer NO-LOCK:
    DISPLAY customer.customer_ID customer.paid(MAXIMUM).
END.
 
Thanks for the suggestion Cecil. I came up with this, which will put the value into a variable.

Code:
def var iMax as int.

for each customer fields(paid):
    accumulate customer.paid (maximum).
end.

iMax = (accum maximum customer.paid).


But for this case I ended up with an index on the numerical field, and a FIND LAST using the index, which should give me the record containing the highest number.
 
Surely it would be better to have the index defined as DESC and then find first?
 
Back
Top