Consultor Eletrônico



Kbase 12255: How to use REPOSITION with a QUERY (V7 ONLY)
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
How to use REPOSITION with a QUERY (V7 ONLY)


INTRODUCTION:
=============
This Techincal Support KnwoledgeBase entry explains how to use the V7
REPOSITION statement with a query.


WHY YOU NEED TO KNOW THIS:
===========================
To be able to understand how REPOSITION works and how to use it
effectively in your procedures.


PROCEDURAL APPROACH:
====================

The REPOSITION statement in PROGRESS V7 allows you to
position a query's cursor to another location in the result
list. Please refer to the following to see how REPOSITION
functions:

For example, you execute the following query using the
demo database:

DEF QUERY qcust FOR CUSTOMER SCROLLING.
OPEN QUERY qcust FOR EACH CUSTOMER NO-LOCK.

You now are positioned right before the first record.
Also, the record buffer is empty. A subsequent
"GET NEXT qcust." finds the first record and populates
the record buffer.

From this state, "REPOSITION qcust FORWARD 0." moves you
to the end of record 1. In effect, you are now between record 1
and record 2. "REPOSITION qcust BACKWARD 0." has the same effect
A subsequent "GET NEXT qcust." finds record 2.

If you execute, "REPOSITION qcust FORWARD 1.", you are
poasitioned between record 3 and record 4. A subsequent "GET
NEXT qcust." finds record 4.

The following chart shows how different statements
affect your position in the file. Remember,
REPOSITION does not "find" a record for you; it only
changes the location of the cursor. You must use the GET
statement to find a record.

Customer
query

--------- <---- REPOSITION BACKWARD 2.
! 1 |
--------- <---- REPOSITION BACKWARD 1.
| 2 | <---- current record in record buffer
--------- <---- REPOSITION FORWARD/BACKWARD 0.
| 3 |
--------- <---- REPOSITION FORWARD 1.
| 4 |
--------- <---- REPOSITION FORWARD 2.
| 5 |
---------
.
.
.

GET NEXT vs. GET PREV After a REPOSITION
----------------------------------------
Since REPOSITION puts you between records, Use GET NEXT or
GET PREV depending on which side of the record you want to
be located. In the above example, if you execute the
following code:

/* current record is record 2 */
REPOSITION qcust FORWARD 1.
GET PREV qcust.

the current record is record 3. Executing "GET NEXT
qcust." instead of "GET PREV qcust." finds record 4.

REPOSITIONing with a RECID
--------------------------
If you know the RECID of a record you want to locate, you
can specify it by coding:

REPOSITION q-name TO RECID recid.

Things to Remember About REPOSITION
-----------------------------------
o After REPOSITION, there is NO record in your record
buffer.

o REPOSITION q-name BACKWARD 1.
GET NEXT q-name.

Would find the same record again, not the one before
it. Remember, the REPOSITION positioned you between the
record you just had and the one before it.

o REPOSITION q-name FORWARD 1.
GET NEXT q-name.

Finds NOT the next record, but the one after that.


ONLINE PROCEDURES OR UTILITIES:
===============================
None.


REFERENCES TO WRITTEN DOCUMENTATION:
====================================
Language Reference Manual - REPOSITION statement

Progress Software Technical Support Note # 12255