Skip to content

DTR

Data to Record Conversion

This string function converts a string that contains fields without field separators into a data record format with fields and field separators, based on a data definition table for the file that is to contain the data record.

DTR (string, data-defn-table [,ERR=line-ref|,ERC=error-code]
[,SEP=field-sep] )
string
is a string that contains fields but not field separators.
data-defn-table
is a string that contains a four-byte definition for each field in the record:

Bytes 0 and 1 represent, in binary, the starting byte position (1-based) of a field in a string. This is used by the DTR function to convert a string or substring into a field with a field separator.

Bytes 2 and 3 represent, in binary, the length of a field. This is used by the DTR function to convert a field into a string or substring.

line-ref
is the program line number or label to branch to if an error is produced by this function.
error-code
is a programmer-defined error code. Valid values are positive or negative whole numbers.
field-sep
is a character that separates each field within a record.

The principal use of this function is to convert a string with imbedded fields, which allows for more efficient use by a Thoroughbred Basic program, into fields with field separators, which allows for more efficient use of disk storage space.

The SEP= field-sep option is generally available starting with release level 8.2. This option is to be used if the string is going to be converted using a field separator other than the default, usually $8A$.

raw_data$ = "ABC"+SEP+"DEF"+SEP+"GHIJKLM"+SEP
! Results of a READ RECORD
! Maximum length for each field:
tbl$ = BIN(1,2)+BIN(3,2)+ ! Field 1 starts at position 1 for a
! length of 3
BIN(4,2)+BIN(5,2)+ ! Field 2 starts at position 4 for a
! length of 5
BIN(9,2)+BIN(10,2) ! Field 3 starts at position 9 for a
! length of 10
fix_len_data$ = RTD(raw_data$,tbl$)
! Fixed length data looks like: "ABCDEF GHIJKLM "
new_data$ = DTR(fix_len_data$,tbl$)
! This string would be used in a READ RECORD and look like:
! "ABC"+$8A$+"DEF "+$8A$+"GHIJKLM "+$8A$

RTD Function

From the Thoroughbred Basic Language Reference, Volume I: A–E, version 8.9.1. Open this page in the PDF