<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SUB inside IF ... THEN statement in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275688#M623962</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I noticed that sub statements that are created/included inside an if statement is not available for calls outside of the IF statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;// This IF statement will work&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;IF 1=1 THEN&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; SUB HelloWorld&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRACE Hello World;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; ENDSUB&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp; CALL HelloWorld;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ENDIF&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;// This IF-statement will not work and throw an error.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;IF 1=1 THEN&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; SUB &lt;SPAN style="font-size: 13.3333px;"&gt;HelloQlik&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRACE Hello Qlik;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; ENDSUB&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ENDIF&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;CALL &lt;SPAN style="font-size: 13.3333px;"&gt;HelloQlik&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems that subs inside an IF acts as a private SUB. Can anyone explain and/or refer to any Qlik documentation that refers to this behavior?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Vegar Lie Arntsen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jan 2017 07:36:27 GMT</pubDate>
    <dc:creator>Vegar</dc:creator>
    <dc:date>2017-01-19T07:36:27Z</dc:date>
    <item>
      <title>SUB inside IF ... THEN statement</title>
      <link>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275688#M623962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I noticed that sub statements that are created/included inside an if statement is not available for calls outside of the IF statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;// This IF statement will work&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;IF 1=1 THEN&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; SUB HelloWorld&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRACE Hello World;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; ENDSUB&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp; CALL HelloWorld;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ENDIF&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;// This IF-statement will not work and throw an error.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;IF 1=1 THEN&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; SUB &lt;SPAN style="font-size: 13.3333px;"&gt;HelloQlik&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRACE Hello Qlik;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp; ENDSUB&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ENDIF&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;CALL &lt;SPAN style="font-size: 13.3333px;"&gt;HelloQlik&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems that subs inside an IF acts as a private SUB. Can anyone explain and/or refer to any Qlik documentation that refers to this behavior?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Vegar Lie Arntsen&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2017 07:36:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275688#M623962</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2017-01-19T07:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: SUB inside IF ... THEN statement</title>
      <link>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275689#M623963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://help.qlik.com/en-US/sense/3.0/Subsystems/Hub/Content/Scripting/ScriptControlStatements/Sub.htm" title="http://help.qlik.com/en-US/sense/3.0/Subsystems/Hub/Content/Scripting/ScriptControlStatements/Sub.htm"&gt;Sub..end sub ‒ Qlik Sense&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the operator sub defined within another operator control, such as For ... Next loop or If the design ... Then, the subroutine will be available only within the application of this operator control. In other words, the operator can sub not be defined within another operator control if a subprogram call must be made outside the control of the operator.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2017 08:22:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275689#M623963</guid>
      <dc:creator>ahaahaaha</dc:creator>
      <dc:date>2017-01-19T08:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: SUB inside IF ... THEN statement</title>
      <link>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275690#M623964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the explanation. It is probably a correct answer, but I can't see that the &lt;A class="jive-link-external-small" data-vivaldi-spatnav-clickable="1" href="http://help.qlik.com/en-US/sense/3.0/Subsystems/Hub/Content/Scripting/ScriptControlStatements/Sub.htm" rel="nofollow" style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3778c7;" target="_blank"&gt;Sub..end sub ‒ Qlik Sense&lt;/A&gt;‌‌ &lt;SPAN style="font-size: 10pt;"&gt;documentation handles this feature. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was aware of variables inside a sub was local(private) but I didn't know that SUB inside a FOR... NEXT or a IF THEN where local. I was expecting the code inside the SUB to run.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2017 09:55:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275690#M623964</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2017-01-19T09:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: SUB inside IF ... THEN statement</title>
      <link>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275691#M623965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333px;"&gt;This becomes an issue for when using a conditional QDF initiation.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Eg. QlikView and Sense is initiated by different syntax.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;IF Qlikview&amp;nbsp; Then&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(Include=..\3.include\1.basevariable\1.init.qvs);&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ELSE&amp;nbsp; //Is Qlik Sense&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET vG.HomeContainer= 'lib://Finance';&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(Include=$(vG.HomeContainer)\InitLink.qvs);&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ENDIF&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;The QDF initiation contains subs that we want to use later on in the script. By capsulate the init-script into an IF we loose the QDF SUBs. &lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Have you run into this issue/feature before &lt;A href="https://community.qlik.com/qlik-users/4595"&gt;mbg&lt;/A&gt;‌ ?&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Ping: &lt;A href="https://community.qlik.com/qlik-users/2999"&gt;cosmo_k&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2017 10:13:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275691#M623965</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2017-01-19T10:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: SUB inside IF ... THEN statement</title>
      <link>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275692#M623966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is nothing much you can do about this (has something to do with scope and visibility of definitions, a language constant).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can however circumvent the problem by setting the path to the include file in an IF THEN ELSE statement, and then just including whatever it has been set to. Like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;IF Qlikview Then&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SET vSubFile = ..\3.include\1.basevariable\1.init.qvs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;ELSE&amp;nbsp; //Is Qlik Sense&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SET vG.HomeContainer= 'lib://Finance';&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; SET vSubFile = $(vG.HomeContainer)\InitLink.qvs;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;ENDIF&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;$(Include=$(vSubFile)) // No semicolon needed&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;Best,&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2017 10:25:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275692#M623966</guid>
      <dc:creator>Peter_Cammaert</dc:creator>
      <dc:date>2017-01-19T10:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: SUB inside IF ... THEN statement</title>
      <link>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275693#M623967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Vegar, yes, I know this "limitation" If you define a variable in the if that you will use in the include after the if statement, that will work. Example: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if trim(lower('$(vG.QVCDisable)'))='true' then&lt;/P&gt;&lt;P&gt;// This is used to disable/enable QlikView Components library (Qvc)&lt;/P&gt;&lt;P&gt;&amp;nbsp; set vG.QVCDisable='$(vG.$(vL.QDF.LinkShared_Folders)SubPath)'; // vG.QVCDisable = true removes Qvc.qvs filename&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;&amp;nbsp; set vG.QVCDisable='$(vG.$(vL.QDF.LinkShared_Folders)SubPath)Qvc.qvs'; // Not disabled will state the Qvc.qvs filename&lt;/P&gt;&lt;P&gt;endif&lt;/P&gt;&lt;P&gt;$(Include=$(vG.QVCDisable)); &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2017 14:15:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/SUB-inside-IF-THEN-statement/m-p/1275693#M623967</guid>
      <dc:creator>Magnus_Berg</dc:creator>
      <dc:date>2017-01-19T14:15:01Z</dc:date>
    </item>
  </channel>
</rss>

