Is the break-group parameter in first and last function useless ?

keithc

New Member
Please explain what the break-group parameter does in the FIRST(break-group) and LAST(break-group) function ? (In the context of a "FOR EACH ... BREAK BY break-group1 BY break-group2").
Giving break-group1 or break-group2 always seems to provide the same result.
Please provide a script where they do not.

When I use the following script:
Code:
define temp-table t
  field a as integer
  field b as integer.

create t. assign t.a = 1 t.b = 1.
create t. assign t.a = 1 t.b = 1.
create t. assign t.a = 1 t.b = 2.
create t. assign t.a = 1 t.b = 3.
create t. assign t.a = 2 t.b = 1.
create t. assign t.a = 2 t.b = 1.
create t. assign t.a = 2 t.b = 2.
create t. assign t.a = 2 t.b = 3.
create t. assign t.a = 3 t.b = 1.
create t. assign t.a = 3 t.b = 1.
create t. assign t.a = 3 t.b = 2.
create t. assign t.a = 3 t.b = 3.

for each t
  break by t.a by t.b:

  display
    t.a label "t.a"
    t.b label "t.b".

  display
    first-of(t.a) label "FO(a)"
    first(t.a)    label "F(a)"
    first-of(t.b) label "FO(b)"
    first(t.b)    label "F(b)"
    last-of(t.a)  label "LO(a)"
    last(t.a)     label "L(a)"
    last-of(t.b)  label "LO(b)"
    last(t.b)     label "L(b)".
end.

I have the following result (using Progress OpenEdge Release 11.7.5):
t.at.bFO(a)F(a)FO(B)F(b)LO(a)L(a)LO(b)L(b)
11yesyesyesyesnononono
11nonononononoyesno
12nonoyesnononoyesno
13nonoyesnoyesnoyesno
21yesnoyesnonononono
21nonononononoyesno
22nonoyesnononoyesno
23nonoyesnoyesnoyesno
31yesnoyesnonononono
31nonononononoyesno
32nonoyesnononoyesno
33nonoyesnoyesyesyesyes

I understand FIRST-OF and LAST-OF and they make perfect sense to me. I showed them here just to emphasize a correct usage of the break-group parameter.

Notice FIRST(t.a) is always the same as FIRST(t.b) and LAST(t.a) always the same as LAST(t.b).

It would make more sense to pass the break-group if it generated different results. I would expect FIRST(t.a) to return yes for the first four records (1-1, 1-1, 1-2 and 1-3) since "1" is the first value of t.a.
Then, FIRST(t.b) could return yes for the first two records (1-1 and 1-1), since 1-1 is the first value of the concatenation of t.a and t.b (the break-group using all fields up to t.b).
The result would depend on which break-group you pass in the parameter of the FIRST/LAST function.

In their current state, these functions could just have the buffer as their parameter. FIRST(t) and LAST(t) would be a very intuitive code to get the results these functions are curently returning.

I'm probably not understanding this correctly. An example where the break-group provided is important would greatly help my understanding.

Thanks in advance ! (btw, this is my first post here. It's really the only question I never found an answer for and I've been programming in Progress since 2008 !)
 
Back
Top