Kbase 16170: Why FIND NEXT in called procedure might find first record
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/10/1998 |
|
Why FIND NEXT in called procedure might find first record
If you are using a shared buffer across two procedures, sharing a
FIND cursor between them, then you might encounter a situation where
a FIND NEXT in the called procedure will always return the *first*
record.
For example, this will happen in the following code:
/******** main.p ********/
DEF NEW SHARED BUFFER b-cust FOR customer.
REPEAT:
RUN subproc.p.
END.
/******** subproc.p ********/
DEF SHARED BUFFER b-cust FOR customer.
FIND NEXT b-cust NO-LOCK NO-ERROR.
IF AVAILABLE(b-cust) THEN DISPLAY b-cust.name WITH FRAME f.
With each iteration of the loop in main.p, the first customer
record is found.
The problem is that there is no FIND NEXT in procedure main.p, so
the called procedure subproc.p always gets a brand new cursor.
To make sure the main procedure and subprocedure share the same
cursor, include a FIND NEXT on the same index somewhere in the
calling procedure. This FIND NEXT does not even have to be code
that is actually executed, for example:
/******** newmain.p ********/
DEF NEW SHARED BUFFER b-cust FOR customer.
IF FALSE THEN FIND NEXT b-cust. /* Add this line */
REPEAT:
RUN subproc.p.
END.
Note that the "IF FALSE ..." statement is never executed, but gives
the compiler a reason to access the cursor that will eventually
be used by subproc.p as well. In the original example, main.p
never actually used the cursor for b-cust, so a brand new one was
created each time subproc.p ran.
PROGRESS index cursors are scoped to blocks. In the original
program configuration, the FIND NEXT scopes the cursor to an inner
block. Upon exiting the block, PROGRESS discards the cursor. When
the block is re-entered later, a new cursor is created and the first
record is fetched again.
By placing a FIND NEXT in the main calling program, you are in effect
scoping the cursor to the program block for main.p. By establishing
the cursor here, you assure that each subsequent FIND will use a
cursor that has been retained throughout both programs.
This will work only if you use the same index for both FIND
statements.
Progress Software Technical Support Note # 16170