File Translation. The TFILE correlative translates data from one file to another file. It uses data stored in one file to reference the item-IDs of another file in order to retrieve data from the second file. This eliminates the need for duplicating data in related files.
Format
T [DICT] filename ; code [vmc] ; in-attr ; out-attr [; br-attr] |
Parameter(s)
DICT |
Specifies the file dictionary from which data is to be translated. |
|
filename |
Name of the file from which data is to be translated. |
|
code |
An action code, which specifies the action to be taken if the item being looked up does not exist. This code must be one of the following: |
|
C |
If conversion is impossible, return the original data. |
|
I |
Input verify only. Functions like V for input and like C for output. |
|
O |
Output verify only. Functions like C for input and like V for output. |
|
V |
Conversion item must exist on file, and the specified attribute must contain data, otherwise an error message is returned. |
|
X |
If conversion is impossible, return a null value. |
|
vmc |
Value mark count indicating the value to be returned from a MultiValued attribute. If vmc is not specified and the attribute is MultiValued, all values are returned with all system delimiters turned into blanks. |
|
in-attr |
Number of the attribute for input conversion. in-attr is used only in mvBASIC using ICONV (see the mvBASIC documentation for more information). in-attr is not used by INFO/ACCESS and can either be null or the same as the out-attr. in-attr cannot be omitted, however; if it is, no translation takes place. |
|
out-attr |
Number of the attribute for output translation. The data to be translated is retrieved from the attribute specified by the out-attr. |
|
br-attr |
Number of the attribute that is used instead of out-attr during the listing at BREAK-ON and TOTAL time if the translation is in Attribute 7 of the Attribute Definition item. |
Description
The TFILE correlative, placed in the source file, translates data from the destination file. The source file must include an attribute whose data is the same as the item-IDs of the destination file. This attribute in the source file contains the keys—the item-IDs of the destination file—that allow the source file to access any of the data in the destination file.
The TFILE correlative is placed in its own Attribute Definition item in the source file. This Attribute Definition item is created as a synonym for the Attribute Definition item (also in the source file) that defines the attribute mentioned in the preceding paragraph—the one that contains the item-IDs of the destination file. This is done by assigning an S (synonym) code in Attribute 1 and by assigning an attribute number which is the same as the attribute number of the attribute containing the destination file’s item-IDs. The TFILE correlative itself specifies:
The name of the destination file
The attribute number of the attribute in the destination file from which data is to be translated
What action is to be taken if there is no data value in that attribute.
Using the TFILE Correlative
Assume you have a BOOK-CATALOG file that contains a book store’s inventory. The file dictionary includes Attribute Definition items for author, title, and price, among others. The item-IDs in BOOK-CATALOG are unique code numbers that identify each book. Here is some sample output from the BOOK-CATALOG file:
>SORT BOOK-CATALOG AUTHOR TITLE PRICE |
|||
|
|
|
|
PAGE 1 |
|
15:03:18 DD MMM YYYY |
|
|
|
|
|
BOOK-CATALOG |
Author... |
Title........................ |
Price... |
|
|
|
|
N01 |
STRANG |
DATABASE MANAGEMENT SYSTEMS |
$9.95 |
N02 |
JACKSON |
OPERATING SYSTEM CONCEPTS |
$18.75 |
QR01 |
O'REILLY |
WRITING COMMERCIAL APPLICATION |
$24.50 |
QR02 |
BALLARD |
WORD PROCESSING |
$22.98 |
|
|
|
|
4 ITEMS LISTED. |
|
|
|
|
|
|
|
> |
|
|
|
Assume in addition that you have another file called ORDERS. The file dictionary includes Attribute Definition items for quantity ordered (QTY), and unique book codes for each book (BOOKCODE).
Here is a report showing some sample data in the ORDERS file:
>SORT ORDERS QTY CODE PAYMENT |
||
|
|
|
PAGE 1 |
14:31:57 DD MMM YYYY |
|
|
|
|
ORDERS |
Qty |
Book Code |
|
|
|
10101 |
2 |
N01 |
10102 |
3 |
N02 |
|
1 |
N01 |
10104 |
3 |
N01 |
|
5 |
N02 |
|
1 |
QR01 |
|
34 |
QR02 |
10105 |
1 |
N01 |
|
4 |
QR01 |
|
7 |
QR02 |
10106 |
3 |
N02 |
10107 |
9 |
N01 |
|
34 |
N02 |
10108 |
10 |
N02 |
|
2 |
QR01 |
10109 |
7 |
QR02 |
Using TFILE correlatives, you can link the data contained in the BOOK-CATALOG file to the data contained in the ORDERS file, thus avoiding unnecessary duplication of data. The ORDERS file requires only one set of data to access the BOOK-CATALOG file, namely the unique book code numbers which are the item-IDs of BOOK-CATALOG. These numbers are stored as Attribute 1, BOOKCODE, in the ORDERS file.
The following three Attribute Definition items in the dictionary of the ORDERS file contain the TFILE correlatives that are necessary to translate data from the BOOK-CATALOG file to the ORDERS file:
TITLE 001 S 002 1 003 Title 004 005 006 007 008 TBOOK-CATALOG ; C ; ; 2 009 T 010 35 |
The preceding synonym for Attribute 1, BOOKCODE, uses the TFILE correlative to access Attribute 2, TITLE, in the BOOK-CATALOG file.
PRICE 001 S 002 1 003 Price 004 005 006 007 MR2$ 008 TBOOK-CATALOG ; X; ; 3 009 R 010 8 |
The preceding synonym for Attribute 1, BOOKCODE, uses the TFILE correlative to access Attribute 3, PRICE, in the BOOK-CATALOG file. Since this is a numeric value, it is right-justified. A masked decimal conversion is applied to the output.
LINE.AMT 001 S 002 0 003 ITEM AMOUNT 004 005 006 007 MR2$ 008 F ; 1 ; (TBOOK-CATALOG ; X ; ; 3) ; 2 ; * 009 R 010 10 |
The preceding Attribute Definition contains an F correlative that includes an embedded TFILE correlative. The TFILE correlative obtains the unit price from Attribute 3, PRICE, of BOOK-CATALOG. The F correlative then multiplies the unit price by the data in Attribute 2, QTY, of ORDERS to arrive at the total amount for each line item.
With these three Attribute Definition items in place, it is now possible to replace the data in the attribute BOOKCODE with the titles and prices that are stored in the BOOK-CATALOG file.
Compare the following orders report with the preceding one:
>SORT ORDERS QTY TITLE PRICE LINE.AMT |
||||
PAGE 1 |
|
11:15:44 DD MMM YYYY |
||
|
|
|
|
|
ORDERS |
Qty |
Title........................ |
Price... |
Item Amount |
|
|
|
|
|
10101 |
2 |
DATABASE MANAGEMENT SYSTEMS |
$9.95 |
$19.90 |
10102 |
3 |
OPERATING SYSTEM CONCEPTS |
$18.75 |
$56.25 |
|
1 |
DATABASE MANAGEMENT SYSTEMS |
$9.95 |
$9.95 |
10103 |
2 |
DATABASE MANAGEMENT SYSTEMS |
$9.95 |
$19.90 |
10104 |
3 |
DATABASE MANAGEMENT SYSTEMS |
$9.95 |
$29.85 |
|
5 |
OPERATING SYSTEM CONCEPTS |
$18.75 |
$93.75 |
|
1 |
WRITING COMMERCIAL APPLICATIONS |
$24.50 |
$24.50 |
|
34 |
WORD PROCESSING |
$22.98 |
$781.32 |
10105 |
1 |
DATABASE MANAGEMENT SYSTEMS |
$9.95 |
$9.95 |
|
4 |
WRITING COMMERCIAL APPLICATIONS |
$24.50 |
$98.00 |
|
7 |
WORD PROCESSING |
$22.98 |
$160.86 |
10106 |
3 |
OPERATING SYSTEM CONCEPTS |
$18.75 |
$56.25 |
10107 |
9 |
DATABASE MANAGEMENT SYSTEMS |
$9.95 |
$89.55 |
|
34 |
OPERATING SYSTEM CONCEPTS |
$18.75 |
$637.50 |
10108 |
10 |
OPERATING SYSTEM CONCEPTS |
$18.75 |
$187.50 |
|
2 |
WRITING COMMERCIAL APPLICATIONS |
$24.50 |
$49.00 |
10109 |
7 |
WORD PROCESSING |
$22.98 |
$160.86 |
See Also