Recital

Login Register
The SET RELATION Recital Navigational Data Command can be used to link two (or more) tables based on the master index key of the child table.  With a relation active, as you move through the parent table, the record pointer also moves in the child table, automatically selecting the first related record or moving to the end of file if no related record exists.    

open database southwind
// open child table
use order_details order orderid in 0
// open parent table
use orders order orderid in 0
set relation to orderid into order_details
do while not eof()
? orders.orderid, order_details.productid
skip
enddo

The code above will display the productid from the first related record, but you will often want to display information from all the related records in the child or detail table as in an SQL Left Outer Join.

open database southwind
select orders.orderid, order_details.productid;
from orders left outer join order_details;
on orders.orderid = order_details.orderid

In this case, we can use a second nested DO WHILE loop, for example:

open database southwind
use order_details order orderid in 0
use orders order orderid in 0
set relation to orderid into order_details
do while not eof()
// Display first or 0 child record
? orders.orderid, order_details.productid
// Display any additional child records
do while not eof(order_details)
? orders.orderid, order_details.productid
skip in order_details
enddo
skip
enddo

Or we can use the SET SKIP command.  The SET SKIP command can be used with DISPLAY, LIST and REPORT and automatically skips through all the related records in the child table.

open database southwind
use order_details order orderid in 0
use orders order orderid in 0
set relation to orderid into order_details
set skip on
set skip to order_details
list orders.orderid, order_details.productid

LIST and DISPLAY offer a number of keyword options to allow you to configure the display output.  REPORT offers full column based report design.
Published in Blogs
Twitter

Copyright © 2024 Recital Software Inc.

Login

Register

User Registration
or Cancel