Skip to content

RTD

Record to Data Conversion

This string function expands a data record, which contains field separators and truncated fields, into fixed-length fields with no field separators, based on a data definition table for the file that contained the data record.

RTD ( data-record, data-defn-table [,ERR=line-ref|,ERC=error-code]
[,SEP=field-sep] )
data-record
is a string containing the actual data record, with field separators, resulting from a FIND RECORD, INPUT RECORD, [P]EXTRACT RECORD, or [P]READ RECORD directive.
data-defn-table
is a string consisting of one or more 4-byte definitions of fields such that:

Bytes 0 and 1 represent, in binary, the starting byte position (1-based) of a field in a fully expanded data record; this is used by the DTR function to compress a fixed-length string into its variable-length fields with field separators.

Bytes 2 and 3 represent, in binary, the length of a field in its fully expanded form; this is used by the RTD function to expand a variable-length field into its fixed-length string. If the first entry is $00 00 00 00$, then all ERR=01 processing is ignored and all data fields are truncated or padded to match the attribute table.

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.

This function is generally available starting with release level 8.1.

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

The principal use of this function is to convert variable-length data records that have field separators, which allow for more efficient use of disk storage space, into fixed-length string format, which allows for more efficient use by a Thoroughbred Basic program.

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$

DTR function

From the Thoroughbred Basic Language Reference, Volume III: R–Z, version 8.9.1. Open this page in the PDF