Fixed and based variables
A string variable can be declared as fixed so that its current length always equals the maximum length. For example:
STRING name(10) FIXED
name = "andrew" | the string is always filled up with spaces
The keyword FIXED is applicable to one-dimensional strings only. Multi-dimensional string arrays are always fixed and do not need to be declared with the keyword FIXED.
The BASED mechanism is applicable to strings or arrays of all possible types. It determines that a variable will be based on another variable. For based variables, no memory space is reserved when they are declared. At runtime they use the same memory space as the variable on which they are based. So by using this mechanism, the same section of memory can be accessed via different names.
You use the following construction to base one variable on another:
BASE var_1 AT var_2
In the case of a string, the based variable is always fixed. You must ensure that the based variable always fits in the variable on which it is based. So it will be safe to declare the basic variable as FIXED.
STRING a(10) FIXED
STRING b(5) BASED
BASE b AT a(3) | This indicates that the space occupied
| by b is the same as the space for a(3;5)
b(2;3) = "yes" | a(4;3) now also contains "yes"
a(1;8) = "12345678" | b now contains "34567"
Variable and fixed length strings
The following points summarize the rules for variable and fixed length strings:
- Strings with variable length are 1-dimensional strings not declared as based or fixed. All other strings are fixed- that is, database table fields, string arrays, and variables declared as FIXED or BASED.
- Normally, variable length strings are not filled up with spaces except when a start position is specified in the assignment.
- Fixed length strings are always filled up with spaces, except when a length is specified. In the latter case, the remaining positions are not overwritten by spaces.
- If a string (of variable or fixed length) is filled from a certain start position, the part of that string preceding the start position is filled up with spaces if it was not filled before.