Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Not applicable

Variables Not Working In A For Loop

I have been trying to loop through a collection of qvd files to extract field data from them.  However, I keep getting the following error:  "Syntax error, missing/misplaced FROM: QVD_METADATA:"  In the script body displayed in the error message, I also see that the variables have vanished from the places where I placed them in the script (not in the script itself, just in the script body displayed in the error message).

It appears the variables are not being created or assigned values.  But, I can't see where the problem lies.  Does anyone have any experience with this?  Here is the code I am using:

QVD_DATA:

LOAD

   *

  , Date(Today(), 'DD-MMM-YYYY') AS UPDATE_DATE_QVD_METADATASET

;

LOAD

  [QV File Name],

     [QVD Full Path]

FROM

$(vInputFile1)

(ooxml, embedded labels, table is [Data Links]);

Let vRowNum = NoOfRows('QVD_DATA'); /*Get total number of rows for the loop to do its thing*/

For i = 1 To $(vRowNum)

  Let vQvdPath = FieldValue([QVD Full Path],$(i)); /*Assign each qvd file path to a variable to be used as the path in the metadata extraction load*/

  Let vFileName = FieldValue([QV File Name],$(i));

  QVD_METADATA:

  LOAD

     1                      as FieldCount,

     $(vFileName)   as [File Name],

     FieldName              as [Field Name],

     BitOffset              as [Bit Offset],

     BitWidth               as [Bit Width],

     Bias                   as [Bias],

     NoOfSymbols            as [No Of Symbols],

     [NumberFormat/Type]    as Type,

     [NumberFormat/nDec]    as Dec,

     [NumberFormat/UseThou] as UseThou

  FROM $(vQvdPath) (XmlSimple, Table is [QvdTableHeader/Fields/QvdFieldHeader]);

Next i

16 Replies
jsakalis
New Contributor III

Re: Variables Not Working In A For Loop

Hi Eugene,

     Try putting quotes around $(vFileName):     '$(vFileName)'   as [File Name],

chrwolf64
Contributor III

Re: Variables Not Working In A For Loop

There will be spaces in the $(vQvdPath) and $(vFileName) has to be in quotes. Try this:

QVD_METADATA:

  LOAD

     1                      as FieldCount,

     '$(vFileName)'   as [File Name],

     FieldName              as [Field Name],

     BitOffset              as [Bit Offset],

     BitWidth               as [Bit Width],

     Bias                   as [Bias],

     NoOfSymbols            as [No Of Symbols],

     [NumberFormat/Type]    as Type,

     [NumberFormat/nDec]    as Dec,

     [NumberFormat/UseThou] as UseThou

  FROM [$(vQvdPath)] (XmlSimple, Table is [QvdTableHeader/Fields/QvdFieldHeader]);

vinieme12
Esteemed Contributor II

Re: Variables Not Working In A For Loop

Debug your script to see which one of the variables isn't evaluating

Not applicable

Re: Variables Not Working In A For Loop

Thank you, John and Christian, those are good suggestions.  However, the same error keeps getting thrown.  It has something to do with the variables not getting evaluated, because they are not being created or initialized.  If, after execution, I go and look at the variables using 'Settings/Variable Overview', the vRowNum variable is there.  But, the vFileName and vQvdPath variables are not there.

Not applicable

Re: Variables Not Working In A For Loop

The vQvdPath and vFileName variables are not assigned any values, and the [QV File Name] and [QV Full Path] fields from the QVD_DATA load at the start of the script also have NULL values.  Something isn't loading right in the Load portion of the For loop.

Re: Variables Not Working In A For Loop

Well, it's quotes, quotes and some more quotes. You're nearly there.

The two variables that aren't being created appear in a LET assignment with function FieldValue. Those don't seem to be working, correct? You specify the field content as first parameter, but the QV Desktop help carries an example of how this function should be called:

20160726 FieldValue Help.jpg

See? The field name should be specified as a string. Quotes. Damn quotes...

Good luck,

Peter

vinieme12
Esteemed Contributor II

Re: Variables Not Working In A For Loop

What is vRowNum evaluating to, does your code even enter the for loop?

vinieme12
Esteemed Contributor II

Re: Variables Not Working In A For Loop

on the top right corner of the screen , below file menu Click on Debug and Step into your code line by line to check

Not applicable

Re: Variables Not Working In A For Loop

vRowNum evaluates to 1347, which is the correct number of rows.  vQvdPath and vFileName evaluate to NULL.  After these are evaluated the script error is then thrown.