Data types
ASTER attempts to simplify the usual challenges in using scripting languages, related to mixed data types, operators and so called promotion rules. In order to achieve that it explores the underlying ABAP techniques to simplify the variety of possible information and at the same time help avoid operational pitfalls.
It’s OK conceptually and, to an extent, technically, to assume that ASTER has just one composite data type, which is a indexed list of values, allowing automatic scalar access to the first element, and accelerated by sorted key access to the indexed values.
Operating on values
First thing to note is the distinction between numeric and text operations. One needs to be explicit with operator selection whether a numeric or text output is expected. So 2+2
or "2"+"2"
will be always 4
. In case a non-numeric value is provided to a numeric operation, error will occur. Trying to do "A"+2
will fail.
On the other hand text operations are always working on text, so that 2 & "22"
will be "222"
. Of course, one can then operate it as number, so (2&"22") + 222
will evaluate to 444
as expected. As the only string operator is concatenation &
, string functions are provided for more involved text operations - like LEFT
, SUBSTR
, FIND
, REPLACE
and regular expression based ones. To convert a text to list of characters use the STL
function.
Lists, tables, and equality
A data element, e.g. during processing or stored in variable, may be either a scalar value (so a single text or text representing a number) or an array of data elements. So the elements themselves may contain scalar values, array of data elements, and so on - allowing to build tree-like or multi-dimensional table-like deep structures convenient for processing larger blocks of data in a structured way.
A list is characterized by the order in which elements were inserted, their keys (scalar indexes) and of course, their actual values.
To compare scalar list elements use ==
for numbers and $==
for texts. In order to compare more complex list items, complete lists or tables, use the dedicated deep equality operator EQL
.
To check if a specific value (either text, number or a composite one) is contained in a list, use the IN
operator.
Lists constructed in ASTER, and those returned by built-in functions are indexed starting with 1
. It’s possible and OK to use index zero 0
as well.
A stored value can be either a scalar or a list. Some rules apply.
Assignment operations using indexed access
[]
will clear the variable scalar value.Writing a scalar value to a variable will clear out any list items associated to that variable.
If the value is a list, trying to read it as a scalar will return the value at the first index.
Example
# declaring a list and assigning an empty value behave the same
A = '';
# constructing list
# approach 1 - by adding elements directly
A[1] = 5;
A[2] = 10;
A[3] = 15;
# approach 2 - by constructing directly
B=(5,10,15);
# approach 3 - by appending using the , operator
C='';
FOR(I=5, I<=15, I+=5, C=(C,I));
(A EQL B) AND (B EQL C); # evals to true, these lists are functionally equal
(A[1] IN B) AND (B[2] IN C); # also evals to true, these elements are found in other lists