The problem isn't so much clearing as it is where you initialize it.  You can't 
initialize it within the stored procedure if it is called from within a while 
loop.  That takes away one of the advantages of using a stored procedure, 
because you would still have to initialize the variables from the calling code, 
before you run the stored procedure

Karen
 
 
 
-----Original Message-----
From: Randyp <[email protected]>
To: [email protected]
Sent: Sat, May 8, 2021 10:14 am
Subject: Re: [RBASE-L] - Re: SET VAR in WHILE loop

You might set the variable to zero or null rather than clearing it. 

Sent from my iPhone

On May 8, 2021, at 9:00 AM, [email protected] <[email protected]> wrote:




Yeah I'm not sure how the mechanism within R:Base works to track variables, but 
what ever list is used, the named variables have to point to some place in 
system memory (space requested for the Variable Type), so it figures that if 
you clear a variable completely, whatever link from within R:Base to system 
memory (Heap or Stack) is broken and there isn't a good or established 
mechanism within R:Base to restore that within a While Loop (at least I think 
that was the logic when R:Base was originally written), so there exists this 
rule to NOT do it.  Just a Guess!

On Saturday, May 8, 2021 at 4:39:08 AM UTC-4 Doug Hamilton wrote:

  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 
 
 
 

 -- 
 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/343713fe-e9a4-4002-b4f4-eacf9c0b5f4bn%40googlegroups.com.
 
 
 


|      |   |


|  This email has been checked for viruses by Avast antivirus software. 
 |


| www.avast.com   |


 
-- 
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/017f6707-b720-4b1f-b45e-6a43c2024826n%40googlegroups.com.
-- 
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/F181004B-9665-4586-ABA8-B6BBF53ADDB9%40ctags.com.

-- 
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/20871851.1014977.1620487895039%40mail.yahoo.com.

Reply via email to