<?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 Using string functions with variables outside load in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998206#M82664</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I want to load all qvds from a folder but keeping different names for each. My first idea was to use for each filelist, extract the table name from each file name and load the file from within the loop. However, I could not make it work. No string function would work. The resulting variable that should have the table name would be empty.&lt;/P&gt;&lt;P&gt;In the end, I came up with the sub below, where the for each would generate a table with the names, and another for loop would use the values to load the files.&lt;/P&gt;&lt;P&gt;Have any of will used string functions on scripts but not within load instructions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SUB fLoadQvdsWithPrefix(pDataSourcePath,pPrefix);&lt;/P&gt;&lt;P&gt;/**********************************************************&lt;/P&gt;&lt;P&gt;The sub loads all QVDs in pDataSourcePath which start with pPrefix.&lt;BR /&gt;Tables will be named after the qvd, excluding prefix&lt;BR /&gt;defined by pPrefix.&lt;BR /&gt;pDataSourcePath should not include the last /.&lt;/P&gt;&lt;P&gt;***********************************************************/&lt;/P&gt;&lt;P&gt;TRACE **********************************************************;&lt;BR /&gt;TRACE Starting fLoadQvdsWithPrefix sub execution.;&lt;BR /&gt;TRACE **********************************************************;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;FOR EACH File in filelist('$(pDataSourcePath)/$(pPrefix)*.qvd')&lt;BR /&gt;[File]:&lt;BR /&gt;LOAD&lt;BR /&gt;'$(File)' as SourceFile,&lt;BR /&gt;TextBetween(Mid('$(File)',Len('$(pDataSourcePath)')+2),'_','.') as DestinationTable&lt;BR /&gt;autogenerate 1;&lt;BR /&gt;NEXT File&lt;/P&gt;&lt;P&gt;LET vPrefixNbOfChars= Len($(pPrefix));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;LET vNoOfFiles=NoOfRows('File');&lt;/P&gt;&lt;P&gt;TRACE **********************************************************;&lt;BR /&gt;TRACE #files $(vNoOfFiles);&lt;BR /&gt;TRACE **********************************************************;&lt;/P&gt;&lt;P&gt;FOR i=0 to $(vNoOfFiles)-1;&lt;BR /&gt;LET vSourceFile = Peek('SourceFile',$(i),'File');&lt;BR /&gt;LET vDestinationTable = Peek('DestinationTable',$(i),'File');&lt;BR /&gt;TRACE source: $(vSourceFile) table:$(vDestinationTable);&lt;BR /&gt;[$(vDestinationTable)]:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;LOAD * FROM [$(vSourceFile)] (qvd);&lt;BR /&gt;NEXT i;&lt;/P&gt;&lt;P&gt;DROP TABLE [File];&lt;BR /&gt;TRACE **********************************************************;&lt;BR /&gt;TRACE Completed fLoadQvdsWithPrefix sub execution.;&lt;BR /&gt;TRACE **********************************************************;&lt;/P&gt;&lt;P&gt;END SUB;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Oct 2022 18:04:47 GMT</pubDate>
    <dc:creator>jmbenedetto</dc:creator>
    <dc:date>2022-10-28T18:04:47Z</dc:date>
    <item>
      <title>Using string functions with variables outside load</title>
      <link>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998206#M82664</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I want to load all qvds from a folder but keeping different names for each. My first idea was to use for each filelist, extract the table name from each file name and load the file from within the loop. However, I could not make it work. No string function would work. The resulting variable that should have the table name would be empty.&lt;/P&gt;&lt;P&gt;In the end, I came up with the sub below, where the for each would generate a table with the names, and another for loop would use the values to load the files.&lt;/P&gt;&lt;P&gt;Have any of will used string functions on scripts but not within load instructions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SUB fLoadQvdsWithPrefix(pDataSourcePath,pPrefix);&lt;/P&gt;&lt;P&gt;/**********************************************************&lt;/P&gt;&lt;P&gt;The sub loads all QVDs in pDataSourcePath which start with pPrefix.&lt;BR /&gt;Tables will be named after the qvd, excluding prefix&lt;BR /&gt;defined by pPrefix.&lt;BR /&gt;pDataSourcePath should not include the last /.&lt;/P&gt;&lt;P&gt;***********************************************************/&lt;/P&gt;&lt;P&gt;TRACE **********************************************************;&lt;BR /&gt;TRACE Starting fLoadQvdsWithPrefix sub execution.;&lt;BR /&gt;TRACE **********************************************************;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;FOR EACH File in filelist('$(pDataSourcePath)/$(pPrefix)*.qvd')&lt;BR /&gt;[File]:&lt;BR /&gt;LOAD&lt;BR /&gt;'$(File)' as SourceFile,&lt;BR /&gt;TextBetween(Mid('$(File)',Len('$(pDataSourcePath)')+2),'_','.') as DestinationTable&lt;BR /&gt;autogenerate 1;&lt;BR /&gt;NEXT File&lt;/P&gt;&lt;P&gt;LET vPrefixNbOfChars= Len($(pPrefix));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;LET vNoOfFiles=NoOfRows('File');&lt;/P&gt;&lt;P&gt;TRACE **********************************************************;&lt;BR /&gt;TRACE #files $(vNoOfFiles);&lt;BR /&gt;TRACE **********************************************************;&lt;/P&gt;&lt;P&gt;FOR i=0 to $(vNoOfFiles)-1;&lt;BR /&gt;LET vSourceFile = Peek('SourceFile',$(i),'File');&lt;BR /&gt;LET vDestinationTable = Peek('DestinationTable',$(i),'File');&lt;BR /&gt;TRACE source: $(vSourceFile) table:$(vDestinationTable);&lt;BR /&gt;[$(vDestinationTable)]:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;LOAD * FROM [$(vSourceFile)] (qvd);&lt;BR /&gt;NEXT i;&lt;/P&gt;&lt;P&gt;DROP TABLE [File];&lt;BR /&gt;TRACE **********************************************************;&lt;BR /&gt;TRACE Completed fLoadQvdsWithPrefix sub execution.;&lt;BR /&gt;TRACE **********************************************************;&lt;/P&gt;&lt;P&gt;END SUB;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 18:04:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998206#M82664</guid>
      <dc:creator>jmbenedetto</dc:creator>
      <dc:date>2022-10-28T18:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using string functions with variables outside load</title>
      <link>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998420#M82682</link>
      <description>&lt;P&gt;try replacing&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;TextBetween(Mid('$(File)',Len('$(pDataSourcePath)')+2),'_','.') as DestinationTable&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;with below&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;TextBetween(Mid('$(File)',index('$(pDataSourcePath)','\',-1),'_','.') as DestinationTable&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 04:08:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998420#M82682</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2022-10-31T04:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using string functions with variables outside load</title>
      <link>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998613#M82705</link>
      <description>&lt;P&gt;HI,&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/2751"&gt;@vinieme12&lt;/a&gt;&amp;nbsp;. Thanks for your reply. The code I posted work but I need to do a support table for it.&lt;/P&gt;&lt;P&gt;I wanted to do something like this:&lt;/P&gt;&lt;P&gt;Let vDestinationTable =&amp;nbsp;&lt;STRONG&gt;TextBetween(Mid('$(File)',index('$(pDataSourcePath)','\',-1),'_','.');&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;However, it did not work. No string function worked.&lt;/P&gt;&lt;P&gt;Would you have any idea why?&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Benedetto&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 13:27:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998613#M82705</guid>
      <dc:creator>jmbenedetto</dc:creator>
      <dc:date>2022-10-31T13:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using string functions with variables outside load</title>
      <link>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998686#M82715</link>
      <description>&lt;P&gt;Is table [File] generated correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remove single quotes from the $(File) variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Trace this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FOR EACH File in filelist('$(pDataSourcePath)/$(pPrefix)*.qvd')&lt;/P&gt;
&lt;P&gt;Let vDest=TextBetween(Mid($(File),index('$(pDataSourcePath)','\',-1),'_','.');&lt;/P&gt;
&lt;P&gt;Trace $(File);&lt;/P&gt;
&lt;P&gt;Trace $(vDest);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[File]:&lt;/P&gt;
&lt;P&gt;LOAD&lt;/P&gt;
&lt;P&gt;$(File) as SourceFile,&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;TextBetween(Mid($(File),index('$(pDataSourcePath)','\',-1),'_','.')&lt;/STRONG&gt; as DestinationTable&lt;/P&gt;
&lt;P&gt;autogenerate 1;&lt;/P&gt;
&lt;P&gt;NEXT File&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively you can also try using &lt;STRONG&gt;filename()&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;TextBetween(Mid(filename(),index($(pDataSourcePath),'\',-1),'_','.')&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 15:41:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1998686#M82715</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2022-10-31T15:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using string functions with variables outside load</title>
      <link>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1999019#M82747</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/2751"&gt;@vinieme12&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) I have no problem to create the table with the original code.&lt;/P&gt;&lt;P&gt;2) If I use my code without the single quotes around $File, I get an error message as the variable is not interpreted as a string (see first image).&lt;/P&gt;&lt;P&gt;3) I tried to use your suggested line&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Let vDest=TextBetween(Mid($(File),index('$(pDataSourcePath)','\',-1),'_','.');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;instead of&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;TextBetween(Mid('$(File)',Len('$(pDataSourcePath)')+2),'_','.')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, the last dot appears in red, as if there is a syntax error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm open to try any other idea.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Best regards&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 11:55:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1999019#M82747</guid>
      <dc:creator>jmbenedetto</dc:creator>
      <dc:date>2022-11-01T11:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using string functions with variables outside load</title>
      <link>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1999063#M82752</link>
      <description>&lt;P&gt;I'm not sure that I could really comprehend your approach but I would probably use subfield() to pick the wanted string-part, like: subfield('$(File)', '/', -1) to fetch the complete filename from the string.&lt;/P&gt;
&lt;P&gt;Another approach might be to query the meta-data of the qvd like: qvdtablename('$(File)')&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 13:55:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Using-string-functions-with-variables-outside-load/m-p/1999063#M82752</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-11-01T13:55:34Z</dc:date>
    </item>
  </channel>
</rss>

