String Templates - BBj
BBj-Specific Information
For this topic's original documentation, see String Templates.
Some field types have a specific length, and attempting to include a length specification in definitions of these field types will generate an !ERROR=20. The field types with specific lengths are F, D, B, X, Y, and A. The length specification may be omitted from types I and U. If omitted, the length of these types defaults to 4 bytes.
Data Type |
Description |
---|---|
A |
ADJN() Business floating point (8 bytes) |
I |
Signed binary integer (1 to 8 bytes) |
K |
In BBj 11.0 and higher, ordered numeric (1 to 32767 bytes) |
O |
Variablelength binary"BLOB"(4 bytes plus user-specified contents) |
U |
Unsigned binary integer (1 to 8 bytes) |
Type |
Description |
Swap? |
Len |
Min |
Max |
Variable? |
---|---|---|---|---|---|---|
A |
ADJN (8 bytes) |
Y |
8 |
N/A |
N/A |
N |
I |
integer |
Y |
var |
1 |
8 |
N |
K |
ordered numeric |
N |
var |
1 |
32767 |
N |
O |
N |
var |
1 |
2^32-1 |
Y |
|
U |
unsigned integer |
Y |
var |
1 |
8 |
N |
In BBj 5.0 and higher, a new type of variable length field, indicated with a plus sign instead of an asterisk, escapes terminator characters in the body of the field permitting arbitrary field values containing the terminator character. As with the normal variable length fields, the terminator is a newline character by default, but the user can always specify an alternate character. Because this field type escapes terminators, the string contents will not necessarily match the field contents. The actual number of characters in the string may be as much as twice the field data length plus a terminator character. In addition, existing fields with embedded terminators or tilde (~) characters are not compatible with the new field type since it would escape these characters.
DIM B$:"NAME:C(10+)"
DIM B$:"NAME:C(10+=0)"
Ordered NUMERIC - Type K
In BBx/BBj, type N numeric values are stored as simple string representations of the number. While this makes it easy to store any type of number, it means that keys created on these columns can only be used for equality optimization in your applications and in SQL engines. For example:
This could be optimized:
SELECT
* FROM mytable WHERE my_type_n_col = 525.23
This could NOT be optimized:
SELECT
* FROM mytable WHERE my_type_n_col > 500.00
The "K" template type makes it possible to store values that will sort correctly in keys, thus making it possible to fully utilize keys/indexes on these fields/columns. "K" stores the number as a sortable binary value rather than a string. This means that the key value is also a binary value and so an alternate method must be used when performing READ RECORD calls specifying a KEY= option. Look at the following example:
This will work with type "N", but NOT type "K":
READ
RECORD(1, KEY="525.95") myrec$
For type "K" you would need to do the following instead:
DIM
key$:"MY_COL:K(10)"
key.my_col = 525.95
READ RECORD(1, KEY=key$) myrec$
The additional step creates the necessary binary value that can then be used for looking up the appropriate record(s) by key.
REDIM Verb
The REDIM verb redimensions a string template variable. If REC$ is a string template, the following two statements are equivalent:
DIM REC$:FATTR(REC$)
REDIM REC$