Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Issue with sending list parameter in Subroutine

This is my Sub:

sub FilesLoad(Root,FileName,RunIdList)

  let vTableName = '$(FileName)';

  let vRunList = '$(RunIdList)';

  let vConcatenate = ;   

  sub ScanFolder(Root)           

        for each FoundFile in filelist(Root&'\*.csv') 

        let vTemp= subfield('$(FoundFile)','\',-3);

  if(match(subfield('$(FoundFile)','\',-3), '$(vRunList)')) then

  if (match(upper(left(mid('$(FoundFile)', index('$(FoundFile)', '\', -1) +1), len(mid('$(FoundFile)', index('$(FoundFile)', '\', -1) +1)) -19)),'$(vTableName)')) then 



                LOAD *  

                FROM '$(FoundFile)' (txt, codepage is 1252, no labels, delimiter is '|', msq);   


                Set vConcatenate = Concatenate;


         next FoundFile  

    for each SubDirectory in dirlist( Root & '\*' )   

        call ScanFolder(SubDirectory)   

    next SubDirectory

    STORE '$(vTableName)' into 'C:\test\$(vTableName).qvd' (qvd);   

  end sub

  call ScanFolder(Root)

end Sub

This is how I call the sub:

set vList = 1;

  set vRoot = 'C:\decisioning\log\dcs\';

  call FilesLoad('$(vRoot)','DCS_META_DATA','$(vList)')

When I send it like this, it works and creates a table.

but when I send it with a list in the last param it crashes.

set vList = 1,3;

  set vRoot = 'C:\decisioning\log\dcs\';

  call FilesLoad('$(vRoot)','DCS_META_DATA','$(vList)')

It crashes in the Sub in the : for each FoundFile in filelist(Root&'\*.csv')

What can be wrong?



3 Replies

Re: Issue with sending list parameter in Subroutine


Have you tried calling without the $ expansions?

call FilesLoad(vRoot, 'DCS_META_DATA', vList)



Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable

Re: Issue with sending list parameter in Subroutine

I am suspecting the vList should have only one value. Try Like below:

Let vList = '1,3';

For i= 1 to substringcount('$(vList)' , ',' ) +1

Let vListi = subfield('$(vList)' ,',' , $(i)) ;

call FilesLoad('$(vListi)', 'DCS_META_DATA', '$(vList)')

Next i;

Re: Issue with sending list parameter in Subroutine

The error is caused by the sub line above the "for each FileFound" line.

You cannot define another subroutine within the first subroutine.

Define the inner subroutine first, then call it from the outer subroutine.

Community Browser