Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

atsushi_saijo
Contributor II

Autogenerate inside Loop

Dear Gurus,

I stumbled in a requirement where I must autogenerate NoOfRow() inside loop.

Specifically, this application is used as a source file for labels. The user put an excel file, where [a.] part number; [b.] Maximum number of labels to print.

Part NumberMaximum Number of Labels
A2
B5
C3

The script should produce such result:

A     1

A     2

B     1

B     2

...

B     5

C     1

C     2

C     3

[Attempted Script]

I have initially authored such script:

//Initial Load

T1: Load [Part Number] as P#, [Maximum Number of Labels] as Max from (Source Excel);

//Getting maximum number of rows in the source file

Let noRows = NoOfRows('T1')

//define loop condition

for i=0 to $(noRows)-1

     Let a = peek ('P#', $(i), 'T1');

     Let b = peek ('Max', $(i), 'T1');

//Generate serialised number

T2: Load RowNo() as Serial Autogenerate $(b),

Next;

[Issue]

However; it seems $(b) is not passed. Just error and stops execution.

I would appreciate for any help on this script.

Atsushi

Tags (2)
1 Solution

Accepted Solutions
MVP & Luminary
MVP & Luminary

Re: Autogenerate inside Loop

Try using the while keyword:

LOAD *, iterno() as RecNo

while IterNo() <= [Maximum Number of Labels]

From ...somewhere...;


talk is cheap, supply exceeds demand
5 Replies
MVP & Luminary
MVP & Luminary

Re: Autogenerate inside Loop

Try using the while keyword:

LOAD *, iterno() as RecNo

while IterNo() <= [Maximum Number of Labels]

From ...somewhere...;


talk is cheap, supply exceeds demand
atsushi_saijo
Contributor II

Re: Autogenerate inside Loop

Thanks, I am trying now.

atsushi_saijo
Contributor II

Re: Autogenerate inside Loop

Excellent it is working. IterNo() is used as serial, and while ..... close was used as condition. I appreciate for your fast and elegant resolution.

MVP
MVP

Re: Autogenerate inside Loop

Temp:

Load * Inline

[

  Part Number, Label

  A, 2

  B, 5

  C, 3

];

Load

  [Part Number],

  IterNo() as NO

Resident Temp

While IterNo() <= Label;

Drop Table Temp;

atsushi_saijo
Contributor II

Re: Autogenerate inside Loop

I appreciate for your support too. Your solution is working. I deeply appreciate for your fast resolution. Atsushi