SOLVE

 View Only
  • 1.  Tuesday Tip: How to read a Vartable sequentially using NCL

    Posted Aug 20, 2014 11:47 AM

    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 done by 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. 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:

    -   Change OPT=FIRST to OPT=LAST in the &VARTABLE GET preceeding the loop

    -   Change KEY=KGT to KEY=KLT in the &VARTABLE GET inside the loop. Then the next lower Key value is read.

     

    -*----------------------------------------*

    -* 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



  • 2.  Re: Tuesday Tip: How to read a Vartable sequentially using NCL

    Community Manager
    Posted Aug 22, 2014 09:33 AM

    Thanks for posting this, Piesenecker_Alexander. Great information!

     

    Going forward, could you please try to use the tags "tips" and "Tuesday Tips" (no underscore)? We're trying to consolidate all of the related tags under those two to make it easier for folks to find these tips. Thanks!



  • 3.  Re: Tuesday Tip: How to read a Vartable sequentially using NCL

    Posted Aug 22, 2014 10:14 AM

    Hi @Lenn_Thompson,

    can we automate the tag creation for the Tuesday Tips (and only for them) using this rule: "Tuesday Tips", "Tuesdays tip", "Tuesday's", Tuesday Tipp", "Tuesday_Tip" ... and all those variations are to be changed to the two tags "Tuesday Tips" and "tips"?

    Regards,

    Alexander