Thanks Mike.  The CLEAR VAR in the RUN SELECT code was typical "good housekeeping" we see on a lot of sample code.

But, as I now understand, code that is in the RUN SELECT is treated as if that code were explicitly written within the WHILE loop.

Which means, like you said, any variables in a RUN SELECT called within a WHILE loop should be defined outside the WHILE loop so they get, and keep, their place in line.

Doug


On 5/4/2021 11:10 AM, [email protected] wrote:
Doug,
  When you Clear a Var, you have removed it from it's location in memory, so when you recreate it by issuing a SET VAR in the while loop, you are violating the rules.   You can simply SET VAR SomeVar = NULL without loosing your place in line.

Mike

On Tuesday, May 4, 2021 at 11:31:40 AM UTC-4 Doug Hamilton wrote:

    I know VARIABLES should not be defined inside a WHILE loop.
    Does that apply to variables that are defined in a RUN SELECT that is
    run inside a WHILE loop?

    Specifically, I have a RUN SEL clump of code that generates
    sequential
    alpha-numeric numbers.
    In it, I clear 9 variables, SET VAR those 9 (all are TEXT), run about
    100 lines of code, and then clear 8 of the variables.
    It runs in a WHILE loop of anywhere from 1 to 30 iterations.

    This is the code in the RUN SELECT, command name 'GenTaskBarCode':
    CLEAR VAR  +
    vTaskBarcode, +
     vDigit1, +
     vDigit2, +
     vDigit3, +
     vDigit4, +
     vDigit5, +
     vMaxDigit, +
     vMinDigit, +
     vNextDigit

    SET VAR  +
      vTaskBarcodeTEXT, +
      vDigit1 TEXT, +
      vDigit2 TEXT, +
      vDigit3 TEXT, +
      vDigit4 TEXT, +
      vDigit5 TEXT, +
      vMaxDigit TEXT, +
      vMinDigit TEXT, +
      vNextDigit TEXT

    Runs about 100 lines of code

    CLEAR VAR  +
    [8 variables, not vTaskBarcode]
    RETURN

    The WHILE loop is:

    WHILE SQLCODE <> 100 THEN
      RUN SELECT CmdCode FROM InternalCode WHERE CmdName='GenTaskBarCode'

      UPDATE tSHPT SET tTaskBarcode  =('1467'+.vTaskBarcode) +
        WHERE PIKD_ID = .vPIKD_ID
      FETCH c#1 INTO vPIKD_ID vi1
    ENDWHILE

    TIA,
    Doug

-- This email has been checked for viruses by Avast antivirus software.
    https://www.avast.com/antivirus <https://www.avast.com/antivirus>

--
For group guidelines, visit http://www.rbase.com/support/usersgroup_guidelines.php <http://www.rbase.com/support/usersgroup_guidelines.php>
---
You received this message because you are subscribed to the Google Groups "RBASE-L" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/rbase-l/343713fe-e9a4-4002-b4f4-eacf9c0b5f4bn%40googlegroups.com <https://groups.google.com/d/msgid/rbase-l/343713fe-e9a4-4002-b4f4-eacf9c0b5f4bn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
For group guidelines, visit 
http://www.rbase.com/support/usersgroup_guidelines.php
--- You received this message because you are subscribed to the Google Groups "RBASE-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rbase-l/1e6114d5-85bd-08b5-e34f-2e724c5b7470%40wi.rr.com.

Reply via email to