TRANS(), XLATE(), RTRANS() |
![]() ![]() ![]() |
The TRANS() function returns a field or the entire record from a named data file. It is normally only used in dictionary I-type items. The synonym XLATE() may be used.
The RTRANS() function is similar but has a slight difference described below for closer compatibility with some other environments.
Format
TRANS({DICT} file.name, record.id, field, action) RTRANS({DICT} file.name, record.id, field, action)
where
In a QMBasic program, file.name is evaluated in the same way as any other expression. In a dictionary I-type record, file.name may be specified as a quoted string or as the actual name of the file, optionally preceded by the DICT qualifier.
the name of a D or I-type item defined in the same dictionary which contains the id of the record to be retrieved. a literal record id enclosed in quotes.
A D or I-type field name as defined in the target file's dictionary. A field number @RECORD or -1 to return the entire record. An expression that evaluates to the field position. This must be enclosed in brackets to avoid potential syntactic ambiguity.
The TRANS() function returns the specified data with any mark characters lowered by one level (e.g. value marks become subvalue marks).
If record.id is multi-valued, the TRANS() function extracts each requested record and returns a multi-valued result with the data from each record separated by a value mark.
The RTRANS() function is identical to TRANS() except that it does not lower the mark characters. This makes it impossible to distinguish between the results of retrieving a multivalued field from a single record and retrieving a single valued field from multiple records.
Examples
TOTAL.VALUE = QTY * TRANS('STOCK', PART.NO, 'PRICE', 'X')
The above statement reads from the STOCK file a record (or list of records) whose id(s) can be found in the PART.NO variable. The X error code causes the TRANS() function to return a null value for any record that cannot be found.
X = TRANS(DICT 'ORDERS', 'DISCOUNT', 'X') X = TRANS('DICT ORDERS', 'DISCOUNT', 'X')
Both of the above statements perform the same action. Either might be used, for example, to retrieve an I-type item named DISCOUNT from the dictionary of the ORDERS file. |