Resolved BREAK BY a function's return value

davidvilla

Member
Hi,
I am trying to break a query by a return value from a function. The results are good, except that i am not able to use a last-of or first-of. It gives me a error -** BREAK keyword or BY phrase missing for aggregate expression. (574).

for each mytable where mytable.field1 = true break by myfunction(input mytable.field2):
if last-of(myfunction(input mytable.field2)) then display mytable.
end.

If i display mytable without the last-of - iam getting the records in the desired order. But I am not able to a last-of operation with it.

Please help. I am using Progress 11.2 in a chui unix box.

Thanks.
 

GregTomkins

Active Member
In my experience, about 40% of the time I use 'BREAK BY', I end up recoding it, eventually, to use an old-fashioned variable to keep track of the last value, etc. This is probably one of those cases.
 

Stefan

Well-Known Member
Not sure about getting the static version to work, but with a dynamic query it is not an issue, since you provide the number of the break-by you want to use:

Code:
DEFINE TEMP-TABLE tt NO-UNDO
   FIELD ii AS INT
   .
 
CREATE tt. tt.ii = 1.
CREATE tt. tt.ii = 2.
CREATE tt. tt.ii = 3.
CREATE tt. tt.ii = 4.
 
FUNCTION Mod3 RETURNS INTEGER ( i_i AS INT ):
   
   RETURN i_i MODULO 3.
 
END FUNCTION.
 
 
DEF VAR hq AS HANDLE.
 
CREATE QUERY hq.
hq:ADD-BUFFER( TEMP-TABLE tt:DEFAULT-BUFFER-HANDLE ).
 
hq:QUERY-PREPARE( 'FOR EACH tt BREAK BY DYNAMIC-FUNCTION("Mod3", tt.ii )' ).
hq:QUERY-OPEN().
 
DO WHILE hq:GET-NEXT():
   IF hq:FIRST-OF(1) THEN
      MESSAGE tt.ii VIEW-AS ALERT-BOX.
END.
 
DELETE OBJECT hq.
 
Top