xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

SET RELATION

Synchronizes the record pointers in one or more work areas.

Syntax

SET RELATION TO [<expression1>|<nRecord1> INTO <cAlias1> [SCOPED]] ;
         [, [TO] <expressionN>|<nRecordN> INTO <cAliasN> [SCOPED]]
         [ADDITIVE]

Arguments

TO <expression>
This is the expression used to relate the current work area with a secondary one. The current work area becomes the parent of the secondary, which is also referred to as child work area. The effect of such a relation is that the record pointer in the child work area is synchronized with the parent work area. The database in the child work area <cAlias> must have a controlling index whose index expression matches <expression>.

The record pointer in the child work area is synchronized using a SEEK operation. The value of <expression> is passed to SEEK.

When no argument is passed, all active relations in the current work area are cleared.

TO <nRecord>
This is a numeric expression. The record pointer in the child work area is synchronized either with a GOTO operation or with a SEEK operation. GOTO is used when there is no controlling index in the child work area. SEEK is used when the controllng index in the child work area is of numeric data type.
INTO <cAlias>
The parameter specifies the alias name of the child work area. It can be specified as a literal alias name, or a character expression enclosed in parentheses.
SCOPED
When the SCOPED option is used, database navigation in the child work area is restricted (scoped) to the records that relate to the current record in the parent work area.
ADDITIVE
This option is only meaningful when relations are already defined in the current work area. In this case, all relations remain active, and new ones are defined. If ADDITIVE is omitted, all existing relations are cleared prior to defining new ones.

Description

The SET RELATION command relates a parent work area with one or more child work areas. This causes the record pointer in a child work area to be synchronized with the record pointer in the parent work area.

Synchronization of the record pointer in a child work area is accomplished either relative via an index, or absolute via a record number.

Relative synchronization

This requires a controlling index in the child work area. Each time the record pointer moves in the parent work area, the value of <expression> is SEEKed in the child work area. As a consequence, the data type of <expression> must match the data type of the controlling index in the child work area.

Absolute synchronization

When the child work area has no controlling index, or when the type of the index expression is not numeric and the relation expression is numeric, the child work area is synchronized via GOTO <nRecord>.

Notes

The record pointer in the child work area is positioned on Lastrec()+1 when there is no match with the relation expression.

It is illegal to relate a parent work area directly or indirectly with itself.

The SET RELATION command does not support SOFTSEEK. It always acts as if SOFTSEEK is set to OFF.

When relating two work areas based on matching record numbers, use the Recno() function for the SET RELATION TO expression. Make sure that the child work area has no controlling index.

Info

See also:DbClearRelation(), DbRelation(), DbRSelect(), DbSetRelation(), Found(), RecNo(), SET INDEX, SET ORDER, SET SOFTSEEK
Category: Database commands
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example lists data from a customer and an invoice database

   PROCEDURE Main
      USE Customer ALIAS Cust

      USE Invoice  ALIA Inv NEW
      INDEX ON CustNo TO Invoice01

      SELECT Cust
      SET RELATION TO CustNo INTO Inv

      // Invoice data changes whith each SKIP in Customer database
      DO WHILE .NOT. Eof()
         ? Cust->LastName, Cust->FirstName, Inv->Total
         SKIP
      ENDDO

      CLOSE ALL
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe