Vartables are stored in ascending sequence of the values in the Key field inside the storage of the SOLVE-or NetMaster-Region. The entries of a Vartable consist of one key field and up to 16 attached Data fields. Access to the entries is possible using NCL verb &VARTABLE GET where the value of the Key needs to be provided.
It may be necessary to read a complete Vartable from the first to the last entry or vice versa. Here you find out how easy this is using NCL.
An easy way to get the first (or the last) entry of a Vartable is by using parameter OPT=FIRST (or OPT=LAST) in the first &VARTABLE GET statement. Just make sure that the Key of the first entry is stored in a variable. In the loop you read the next entry by referencing that key and using OPT=KGT (Key greater than), meaning that the next entry must be greater than the previously read. The loop is controlled by the Feedback provided into variable &ZFDBK. As long as this value is 0, an entry of the Vartable could be read. When trying to read after the last record was read, &ZFDBK contains 4 and the loop ends.
The following example shows how a complete Vartable is read in ascending order:
-*---------------------------------------* -* Reading a Vartable in ascending order * -*---------------------------------------* &VARTABLE GET ID=TABLE SCOPE=REGION + OPT=FIRST + FIELDS=(.KEY,DATA1,DATA2) + VARS=(K,F,L) &DOWHILE &ZFDBK = 0 ... processing of Vartable entry ... &VARTABLE GET ID=TABLE SCOPE=REGION + KEY=K + OPT=KGT + FIELDS=(.KEY,DATA1,DATA2) + VARS=(K,F,L) &DOEND
Note that if using OPT=FIRST there is no need to provide parameter KEY=..., in turn, both parameters are mutually exclusive.
The complete Vartable can be read in descending order, too. Two small changes in the above example will fulfill that:
-*----------------------------------------* -* Reading a Vartable in descending order * -*----------------------------------------* &VARTABLE GET ID=TABLE SCOPE=REGION + OPT=LAST + FIELDS=(.KEY,DATA1,DATA2) + VARS=(K,F,L) &DOWHILE &ZFDBK = 0 ... processing of Vartable entry ... &VARTABLE GET ID=TABLE SCOPE=REGION + KEY=K + OPT=KLT + FIELDS=(.KEY,DATA1,DATA2) + VARS=(K,F,L) &DOEND