Query Last-of

jmac13

Member
Hi All,

I'm using open edge 10.2b and I'm using a query object and i want to use last-of method.

e.g.
Code:
hanQuery:query-prepare("For each ttRecs break by tt-prdeld.pordno~
                                                  by tt-prdeld.pordln~
                                                  by tt-prdeld.stpgrp~
                                                  by tt-prdeld.s-level1~
                                                  by tt-prdeld.s-level2~
                                                  by tt-prdeld.s-level3 ~
                                                  by tt-prdeld.s-level4"). 
 
repeat:
 
  if hanQuery:last-of(7) then do:
     /*do something*/
  end.
 
 hanQuery:get-next().  /*Get the next line of the query*/      

 if hanQuery:query-off-end then leave. 
end.



But it not very Elegant as you have to use a number for the break e.g. 7 in this case rather than saying if last-of(s-level4) when its not a query object. So is there a better way of doing this or I am stuck with using a number.
 
You could parse the query phrase using:

Code:
FUNCTION LastOf RETURNS INTEGER (
   INPUT i_hq     AS HANDLE,
   INPUT i_cfield AS CHARACTER
):

   DEFINE VARIABLE cquery AS CHARACTER NO-UNDO.

   cquery = i_hq:PREPARE-STRING.
   cquery = REPLACE( SUBSTRING( cquery, R-INDEX( cquery, "BREAK BY ":U ) + 9 ), " BY ":U, " ":U ).

   RETURN LOOKUP( i_cfield, cquery, " ":U ).

END FUNCTION.

I would not call this function inside your query loop.

Or, if your query is as static as it looks, simply use a preprocessor for readability.
 
If you're just worried about readability, you could use preprocessors.

Code:
&SCOPE-DEFINE tt-prdeld.pordno   1
&SCOPE-DEFINE tt-prdeld.pordln   2
&SCOPE-DEFINE tt-prdeld.stpgrp   3
&SCOPE-DEFINE tt-prdeld.s-level1 4
&SCOPE-DEFINE t-prdeld.s-level2  5
&SCOPE-DEFINE tt-prdeld.s-level3 6
&SCOPE-DEFINE tt-prdeld.s-level4 7

hanQuery:query-prepare("For each ttRecs break by tt-prdeld.pordno~
                                              by tt-prdeld.pordln~
                                              by tt-prdeld.stpgrp~
                                              by tt-prdeld.s-level1~
                                              by tt-prdeld.s-level2~
                                              by tt-prdeld.s-level3 ~
                                              by tt-prdeld.s-level4"). 
 
repeat:
 
  if hanQuery:last-of({&tt-prdeld.s-level4}) then do:
     /*do something*/
  end.
 
 hanQuery:get-next().  /*Get the next line of the query*/      

 if hanQuery:query-off-end then leave. 
end.
 
Cheers that function looks good that way if one of the breaks moves its not hard coded in.. makes it much better thanks alot:D
 
Back
Top