Tfile Code - Translation

The Tfile code provides a method for translating a value from a source file into a value taken from another file (the translation file). The value in the source file is used as an item-id in a translation file. This eliminates the need to duplicate data.

Input/Output Conversion

Output conversion is valid. The Tfile code has a parameter (outputAttr) that specifies the attribute in the translation item to use for output conversion.

Input conversion is valid. The Tfile code has a parameter (inputAttr) that specifies the attribute in the translation item to use for input conversion.

Syntax

T{{[DICT || *]}fileSpec};transCode{[valueNo||:delimiter]};{inputAttr};{outputAttr}{;breakAttr}

Syntax Elements

DICT or * Specifies that the dictionary of the specified file should be used (DICT is preferred).

fileSpec Identifies the translation file, in the format:

{/account/}filename{,data-section-name}

transCode One of the following translation codes:

CIf translate item does not exist or the specified AMC is null, output the value unchanged.

IInput verify. Functions as a C code for output and as a V code for input.

OOutput verify. Functions as a C code for input and as a V code for output.

VTranslate item must exist and the specified AMC must contain a translatable value. If the item does not exist or the AMC contains a null, an error message similar to the following is output at the end of the listing:

'[708] text CANNOT BE CONVERTED'

XIf translate item does not exist or the specified AMC is null, use a null.

valueNo Can be:

  • A value mark count: returns just that value from the attribute referenced (if omitted, all values from the attribute are referenced).
  • An asterisk (*): uses the same value mark count in the target file as in the primary file.

:delimiter Use delimiter to separate values and subvalues. If delimiter contains more than one character, only the first is used.

inputAttr The attribute number for input translation. If inputAttr is omitted or null, no input translation takes place. If it is 9999, the target item size is returned. Only meaningful when Tfile is used as an input/output conversion.

outputAttr The attribute number for output translation. If the value is null, no output translation takes place. If it is 9999, it returns the target item size.

breakAttr The attribute number for 'break' translation. If set to 9999, the target item size is returned. This is output for non-break attributes in BREAK-ON DET-SUPP listings and for break attributes when 'V' code used in BREAK-ON text.

Comments

Attribute

The Tfile code can be used in attribute 7 or 8 of the data definition item.

If translating a multivalued attribute, or if comparisons and sorts are required, the Tfile code should be used in attribute 8 of the data definition item.

If selection criteria may be used, you can use attribute 8 for the Tfile code or you can use attribute 7 and set up special items in the translation file to carry out the input translation required.

File Specifier

If a file specifier is included, the Tfile code uses the data value as the item-id for the specified translation file. It then returns the requested attribute value from that item.

If the file specifier is omitted, the data value must contain both a file specifier and an item-id. One way of generating the file specifier is to use the NF, NFA, NFD, NFF, NFN and NFS operators in an A or F code conversion. Dynamically generating the file specifier can:

Note that when the Tfile code is used in conjunction with other conversion codes, the syntactical conventions of the other code must be followed. For example, if the Tfile code is used with an F code conversion, the Tfile code specifications must be enclosed in parentheses.

Special Items

The special items in the translation file have as item-ids values that the attribute subject to translation may be compared with in an English sentence. Attribute inputAttr within these items contains the translate value that will be compared to values on file. Typically, values in an English sentence are output values, so that the special input translation items are effectively the inverse of the output translation items.

Tfile Code Examples

The first two examples show how the Tfile code is used to translate attribute values contained in the GUESTS file for use by the ROOMS file and vice versa.

Example 1

GUESTS file items contain the last name of the guest in attribute 2. The ROOMS file does not list guests. In the dictionary of the ROOMs file the following data definition item is set up:

     GUEST-NAME
001 A
002 0
003 Current Guest
004
005
006
007
008 TGUESTS;X;;2
009 T
010 15

This definition tells the system to take the value of attribute 0 in the ROOMS file item (the item-id) and use it as the item-id of an item in the GUESTS file (the translation file). If the item exists then use its attribute 2 as GUEST-NAME, otherwise use null.

Notice that attribute 2 of the data definition item references item-ids. This is useful in two respects:

Use of the data definition item GUEST-NAME is shown by the following:

:LIST ROOMS WITH GUEST-NAME "Hen]" HDR-SUPP

ROOMS Current Guest..
143   Hennessey

Example 2

Similarly, the GUESTS file contains no information about the room occupied by a guest. That information is translated from the ROOMS file by setting up a number of data definition items in the dictionary of the GUESTS file including the following:

ROOMS file items contain the room-code in attribute 1.

     ROOM-CODE
001 A
002 0
003 Room]Code
004
005
006
007
008 TROOMS;X;;1
009 L
010 4

This definition tells the system to take the value of attribute 0 in the GUESTS file item (the item-id) and use it as the item-id of an item in the ROOMS file (the translation file). If the item exists then use its attribute 1 as ROOM-CODE, otherwise use null.

The following shows the use of ROOM-CODE:

:LIST GUESTS WITH ROOM-CODE = "P" ROOM-CODE NAME HDR-SUPP

GUESTS Room  Guest Name.........
       Code
535    P     Linda P. Evans

Example 3

Assume an inventory/order type data base with a VENDOR file that only contains names and addresses and an ORDERS file that contains source information about the orders.

Each item in the ORDERS file contains:

001  Part Number
002 Quantity
003 Price
004 Date ordered
005 Date received
006 Vendor code (reference value)

Each item in the VENDOR file contains:

001  Vendor name
002 Street address
003 City
004 ZIP code

The appropriate data definition items are set up to convert the dates and prices to a desired format. To combine information about the vendor and the product ordered, the following data definition items are set up in the dictionary of the ORDERS file:

     VENDOR
001 A
002 6
003 Vendor
004
005
006
007 TVENDOR;C;;1
008
009 L
010 12
     V.ADDR
001 A
002 6
003 Address
004
005
006
007
008 F;6(TVENDOR;C;;4);C, ;:;6(TVENDOR;C;;3);:;C, ;:;6(TVENDOR;C;;2);:
009 L
010 35

Note that the Tfile code in V.ADDR is combined with the F code. Although this can be considered as an example of multiple codes, the syntax of the F code governs the syntax for the whole specification. In the context of the F code syntax, the Tfile codes are conversion codes and are preceded by an attribute number.

The F-code functions in reverse Polish format. Therefore, the value that is to be output first is specified last as shown in the following:

F;6(TVENDOR;C;;4);C, ;:;6(TVENDOR;C;;3);:;C, ;:;6(TVENDOR;C;;2);:

where:

F indicates invoke the F-code processor.

6(TVENDOR;C;;4) means take the value of attribute 6 in the ORDERS file item and retrieve from the VENDOR file the item with this item-id. Then extract outputAttr (attribute 4: ZIP code) of this item and push it onto the stack.

C,spacemeans push the literal ', ' onto the stack.

: means concatenate the top stack entry onto the front of the next stack entry to replace the top stack entry.

6(TVENDOR;C;;3) means take the value of attribute 6 in the ORDERS file and retrieve the item in VENDOR with this item-id; then extract the outputAttr (attribute 3: City) of this item and push it onto the stack.

: means concatenate the top two stack entries.

C,spacemeans push the literal ', ' onto the stack.

: means concatenate the top two stack entries.

6(TVENDOR;C;;2) means take the value of ORDERS file attribute 6, retrieve this item from VENDOR, extract outputAttr (attribute 2: Street address) and push it onto the stack.

: means concatenate the top two stack entries.

You can now use the following English sentence to get a report similar to the one shown below:

:LIST ORDERS VENDOR V.ADDR HDR.SUPP
ORDERS Vendor...... Address............................
8801 Schlussel AG 40 Potsdamer St., Berlin 30, D2000
8802 Key Products 35 High St., Maida Vale, NW4 4BT
8803 CEP 100 Main St., Irvine, CA92714

Example 4

In the HOTEL database, the twelfth attribute of each item in the GUESTS file (BILL-AMT) is multivalued, listing several bill totals for each guest. The following item could be set up in the dictionary of the ROOMS file to translate the third multivalue from that attribute:

     BILL
001  A
002  0
003  Amount
004
005
006
007
008  A;(NF:" ":0)(T;X3;;12)
009  R
010  6

This definition retrieves the name of the file using the 'A' function 'NF', and appends a space separator, followed by the contents of attribute 0 as an item ID.

The command:

LIST ROOMS BED-TYPE GUEST-NAME BILL

would then display:

PAGE 1          12:07:13        07 FEB 1994
ROOMS   Bed     Current Guest   Amount
        Type
140     Queen   Lynch   17.00
119     Double  Scott   17.95
147     King    Janson  6.95
428     King    Postma  65.00
309     King    Mendell 78.00
211     King    Lewis   34.88
.
.
.

Example 5

This example shows how, by using the A conversion code, a file name can be dynamically generated. In this way, the same data definition item can be applied to a number of different files (containing yearly archive data, for instance).

The following item is created in a common file called REPOSITORY.

     ITEM
001  A
002  0
003  Product
004  
005  
006  
007  
008  A;(NFF:",CONVERT ":2)(T;X;;4)
009  L
010  6

This definition retrieves the base name of the file using the A function. 'NFF', appends a ",CONVERT " constant section name to the end together with an extra space separator, then finally appends the contents of attribute 2 as an item ID. It therefore translates attribute 2 from the specified file through the CONVERT data-section of the same file and displays attribute 4 of that item.

This common item can then be used to list the contents of different files, provided they have the same format (in this case, provided they have a CONVERT data section). For example

LIST ORDERS ITEM USING REPOSITORY

lists the products in the ORDERS file, and

LIST NEWFILE,1992 ITEM USING REPOSITORY

lists the products in the NEWFILE,1992 file.