Consultor Eletrônico



Kbase 11005: Code work-around FIND PREV with REPEAT .. PRESELECT BREAK BY
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/05/1998
Code work-around FIND PREV with REPEAT .. PRESELECT BREAK BY

REPEAT PRESELECT ... BREAK BY with LAST-OF test will not work with
FIND PREV in the loop. It may appear to work sporadically, or may
fail consistently. It is not possible to "fix" this behavior as
it is a limitation of the design of BREAK BY logic. FIND PREV is
*NOT* supported within BREAK BY. This may not be a problem until
the LAST-OF function is used, but it's important to understand
that the FIND PREV behavior itself shouldn't be used within a
PRESELECT BREAK BY block. The BREAK BY feature is designed for use
with forward-only scans.

LAST-OF and FIRST-OF break groups can be simulated in a variety of
ways. Two possibilities follow:

1>
Define a buffer for your file.
When you want to check to see if the current record is
either the FIRST-OF or LAST-OF a particular break-group,
FIND (using the buffer) the previous or next record using
the same search criteria and test the field of your
buffer to see if it is the same as your current file.field.
If it is the same, than your current record is not
the FIRST-OF or LAST-OF your group.
If it is different, then your current record is EITHER
the FIRST-OF or LAST-OF depending on whether you did a
FIND PREV or FIND NEXT.

Here's an example:

DEFINE custx FOR customer.

REPEAT PRESELECT EACH customer WHERE <criteria>:
FIND NEXT customer.
/* CHECK LAST-OF */
FIND custx WHERE custx.primary_field = customer.primary_field.
FIND NEXT custx WHERE <criteria>.
IF custx.break_group_field <> customer.break_group_field THEN DO:
BREAK GROUP LOGIC
END.
/* END LAST-OF LOGIC */

/* CHECK FIRST-OF */
FIND custx WHERE custx.primary_field = customer.primary_field.
FIND PREV custx WHERE <criteria>.
IF custx.break_group_field <> customer.break_group_field THEN DO:
BREAK GROUP LOGIC
END.
/* END FIRST-OF */
END.

2>
With Version 7 or later, you can DEFINE a QUERY using an alternate
buffer, then use an OPEN QUERY ... PRESELECT to obtain the
number of rows in the result-list (using NUM-RESULTS). This will
indicate which is the LAST-OF that break group.

Progress Software Technical Support Note # 11005