Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
datanibbler
Esteemed Contributor

Loop in script returning NULL values?

Hi,

I have a code in my QlikView script doing the following:

- Load an overview table with 15 serial_numbers (some text, some purely numeric) and the respective text;

- Loop from 1 to 15 (there are 15 SN) and load one SN on each iteration;

- Set a variable with the current SN;

<=> At least that's what it is supposed to do.

=> The variable should then be used (still within the Loop) to load one of 15 worksheets, all of which have the same structure with similar data.

I can see afterwards in a listbox that all 15 SN are loaded, one at a time. The variable, however, returns just NULL values.

Might it be that I cannot create variables in a loop at all? If so, how can I achieve this effect (within every loop_iteration, repeat a LOAD statement for the respective SN, which is in the sheet_name)?`

From another software I know I had to initiate variables before a LOOP to be able to use them, but that doesn't seem to work...

Thanks a lot!

Best regards,

DataNibbler

3 Replies

Re: Loop in script returning NULL values?

Hi,

     I am not sure with what expression you are trying to do this, but have a look at the below code.

     DATA:

     Load SN from XYZ;

     Let vCount = NoOfrows('DATA');

     For i=0 to $(vCount) -1

    

          Let vSN = peek('SN',$(i),'DATA');

     ........

     Next

Regards,

Kaushik Solanki

datanibbler
Esteemed Contributor

Re: Loop in script returning NULL values?

Hi Kaushik,

I have a somewhat simplified LOOP construction, I will post it after this. Yours does look better, it is flexible as to the nr. óf rows. I will replace that. Do I have to specify the table and row with the PEEk fct to fill my variable? At that time, there is only one field of that name.

Here is the code I am currently using:

Übersicht_SN:
LOAD A as SN,
     B as Bezeichnung,
     RecNo() as SN_Ct
FROM

(ooxml, no labels, header is 3 lines, table is Übersicht)
WHERE NOT ISNULL (A);

FOR i = 1 TO 15

  Test_Counting:
   LOAD
     SN as SN_test
   RESIDENT Übersicht_SN
     WHERE SN_Ct = $(i)
;

LET v_SN = SN_test;

NEXT i

Re: Loop in script returning NULL values?

Hi,

     Your variable declaration is wrong.

     Try this.

     Let v_SN = peek('SN_test',0,'Test_Counting');

    

      

Regards,

Kaushik Solanki    

Community Browser