3 Replies Latest reply: Jan 12, 2018 9:44 AM by Michael Granillo RSS

    Subroutine creating dozens of variables

    Michael Granillo

      I run a subroutine in my script and pass a variable name as the input parameter.  Every time it runs, Qlik creates a new variable with the name and value equal to the input variable parameter.  I found in Qlik documentation that this is standard functionality:

      subDoc.jpg

      My issue is that my QVW now has hundreds of variables and it's growing by the day.  Does anyone have any experience with this issue and how to prevent it from happening? 

        • Re: Subroutine creating dozens of variables
          Evan Kurowski

          Recently ran into this, and my issue sounds the same, if I passed my subroutine the parameter 4, then it created a variable 4 and assigned the variable '4' the value =4.

           

          Not sure if it was always this way, but when I always single quoted the variables being passed as parameters in the call statement, while making sure no quoting was used in the receiving subroutine, this issue did not occur.

           

          I.e. pairing

           

          Sub MyProc(var1NoQuotes, var2NoQuotes)

           

          Call MyProc('$(vquotedArg1)','4')

           

          Even though my hardcode parameter of 4 was going to the subroutine in quotes, I think by default I was still able to work it as a number, without requiring a data type conversion like Num() or Num#().

          • Re: Subroutine creating dozens of variables
            Marcus Sommer

            I remember some years ago to read some discussions about the topic and what the technical backgrounds could be and if it should be considered as bug or not - I believe the conclusion was it's not a bug else an intended feature.

             

            Because it's not easy to find these old postings I didn't try it yet - particularly because it's just an explanation and not a solution in your case. I think the only solution would be to drop the variables within the routine (or maybe within some additionally routines) after using them. Just var = null(); will delete the variable (only within the script - does the variable already exists within the GUI they must be deleted there first).

             

            - Marcus

            • Re: Subroutine creating dozens of variables
              Michael Granillo

              Thanks Evan. This worked for me.  I never would have thought of that so thanks for taking the time to share the information.

               

              Mike