Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

jchang_snwl
New Contributor II

for each loop on a field

Hello,

Would it be possible to use "for each" loop on a field of a table?

Like:

Let vfileList = Some_Kind_of_Function('fieldName'); //fieldName is a field of a table

for each vfile in $vfileList

  Do something....

next

Thanks,

Josh

5 Replies
MVP
MVP

Re: for each loop on a field

Use this code pattern:

For i = 0 To NoOfRows('tableName') - 1

     Let vVal = Peek('fieldName', i, 'tableName');

     // do something ....

Next

Edit - added the '-1'

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

Re: for each loop on a field

Can you please explain the scenario?

Data:

Load  Field1,

         Field 2

From Table

let vFieldValueCount = FieldValueCount ('Field1');

For i=1 to $(vFieldValueCount)

let vFieldValue = FieldValue('Field1',$(i));

...

...

Next i

jchang_snwl
New Contributor II

Re: for each loop on a field

Hello,

Thanks for answer.

Sorry I forgot the mention he point.

I want to drop the table as soon as the field is set to a list variable.

Thanks,

Josh

MVP
MVP

Re: for each loop on a field

OK, so add the line

Drop Table tablename;


What precisely do you mean by "list variable"?

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

Re: for each loop on a field

Data:

Load  Field1,

         Field 2

From Table

let vFieldValueCount = FieldValueCount ('Field1');

For i=1 to $(vFieldValueCount)

let vFieldValue = FieldValue('Field1',$(i));

...

...

Next i

drop table Data;

Community Browser