Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Fill an empty table with stuff.

Hi!

So I'm in qvscript and trying to fill an empty table with new stuff through a loop and an if-statement. If the if-statement is true I call a sub (that I put first in the script) that creates a string with variables from the if-statement. So far so good. Then my problem is creating an empty table and filling it with new strings for each time the if-statement is fullfilled. Ideally I would like that the table had two columns, one for the new string coming in, and if the same string comes up twice, in the next column I would like it to be counted. I think this is known as a hash table... sort of

So, how to do this? Do I create the empty table in the beginning of the script or in the Sub where each of the new strings are created? Any help would be much appreciated!

3 Replies
Gysbert_Wassenaar

This creates an empty table:

NewTable:

Load '' as Field1, '' as Field2

autogenerate 0;

In a loop you can do something like this:

for i=1 to 100

     if 1=1 then

          NewTable:

          load 'a' as Field1, 123 as Field2

          autogenerate 1;

     end if

next i


talk is cheap, supply exceeds demand
Not applicable
Author

Hey Gysbert, thanx again!

Can't get it to work though. I'm trying sort of like this:

//Creating the empty table

NewTable:

Load '' as Field1, '' as Field2

autogenerate 0;

//My sub where i want to fill the table every time its called. Note that I want to fill one of the fields with pos, which is a string that is different each time it's called. Eventually I would like the second Field to have the count of the different pos coming in.

Sub crtTw(a,b)

     let pos=a & ',' & b;

     load pos as Field1, 123 as Field2

     autogenerate 1;

end sub

//My loop where my sub get's called when a certain condition is met.

for i=0 to 100

    let s=Peek('RECEIPT_NUMBER',i,'table1');

    let t=Peek('RECEIPT_NUMBER',i+1,'table1');

   

    if s=t then

        let a=Peek('%Key_Trans_Item',i,'table1');

        let b=Peek('%Key_Trans_Item',i+1,'table1');

       

        CALL crtTw(a,b);

       

       

       

    ENDIF

   

NEXT i

Not sure if this is comprehensible, but I'll throw it out anyway!

Not applicable
Author

bumpin this!