Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Create table dynamically with SUB

Hi everybody,

I want to create many tables dynamically.

Do do that, I have an XLSX file which contains all params like this :

TableNameQvdFileAlias
TableSTTQVD_STT.QVD
TableOSERQVD_OSER_01.QVDAlias Key as NewKey

I wrote a script to loop on each records of this table.

This is how the script below works, the "TRACE" shows all values of records in the report (one "trace" line per record) :

//Load the params from xlsx

TableParams:

LOAD TableName,

     QvdFile,

     Alias

FROM

(ooxml, embedded labels, table is Feuil1);

SUB LoadParams

    NumRows=NoOfRows('TableParams');

    FOR i=0 to $(NumRows)-1

        NameOfTable= Peek('TableName', $(i));

        QVDNameFile = Peek('QvdFile', $(i));

        AliasVariable= Peek('Alias', $(i));

        Trace $(i) and Name of table = $(NameOfTable) QVD Name = $(QVDNameFile );

    NEXT;

ENDSUB;

Now, I want to load my table like this (new code in bold) :

//Load the params from xlsx

TableParams:

LOAD TableName,

     QvdFile,

     Alias

FROM

(ooxml, embedded labels, table is Feuil1);

SUB LoadParams

    NumRows=NoOfRows('TableParams');

    FOR i=0 to $(NumRows)-1

        NameOfTable= Peek('TableName', $(i));

        QVDNameFile = Peek('QvdFile', $(i));

        AliasVariable= Peek('Alias', $(i));

        Trace $(i) and Name of table = $(NameOfTable) QVD Name = $(QVDNameFile );

        If Len($(AliasVariable))>0 Then

            $(AliasVariable);

        ENDIF;

        $(NameOfTable):

        Load *

        From QVD\$(QVDNameFile);

    NEXT;

                         ENDSUB;

My problem is that this script works only for the first line of the XLSX.

After the first load, the Trace Message show empty values.

Could you help me?

Thanx

1 Solution

Accepted Solutions
Not applicable
Author

Hi Beaulieu,

I think a possible solution could be something like:

//SUB CODE

SUB LoadParams

  NumRows=NoOfRows('TableParams');

    FOR i=0 to $(NumRows)-1

        NameOfTable= Peek('TableName', $(i),'TableParams');

        QVDNameFile = Peek('QvdFile', $(i),'TableParams');

        AliasVariable= Peek('Alias', $(i),'TableParams');

        Trace $(i) and Name of table = '$(NameOfTable)' QVD Name = '$(QVDNameFile)';

    

      If Len('$(AliasVariable)')>0 Then

          TRACE  '$(AliasVariable)';

      ENDIF;

    

        '$(NameOfTable)':

      Load *

      From QVD\$(QVDNameFile)(qvd);

    

    NEXT;

ENDSUB;

//Load the params from xlsx

TableParams:

LOAD TableName,

     QvdFile,

     Alias

FROM

Test.xlsx

(ooxml, embedded labels, table is Plan1);

// Call Sub

CALL LoadParams;

Best Regards.

Pablo

View solution in original post

5 Replies
Not applicable
Author

Nobody can help me?

Not applicable
Author

Hi Beaulieu,

I think a possible solution could be something like:

//SUB CODE

SUB LoadParams

  NumRows=NoOfRows('TableParams');

    FOR i=0 to $(NumRows)-1

        NameOfTable= Peek('TableName', $(i),'TableParams');

        QVDNameFile = Peek('QvdFile', $(i),'TableParams');

        AliasVariable= Peek('Alias', $(i),'TableParams');

        Trace $(i) and Name of table = '$(NameOfTable)' QVD Name = '$(QVDNameFile)';

    

      If Len('$(AliasVariable)')>0 Then

          TRACE  '$(AliasVariable)';

      ENDIF;

    

        '$(NameOfTable)':

      Load *

      From QVD\$(QVDNameFile)(qvd);

    

    NEXT;

ENDSUB;

//Load the params from xlsx

TableParams:

LOAD TableName,

     QvdFile,

     Alias

FROM

Test.xlsx

(ooxml, embedded labels, table is Plan1);

// Call Sub

CALL LoadParams;

Best Regards.

Pablo

Not applicable
Author

Yes, I have just find this solution !

Thanx.

Problem solved.

pokassov
Specialist
Specialist

Hi, Beaulieu!

You have to change only one line in your script

If Len('$(AliasVariable)')>0 Then

Sergey

Not applicable
Author

This solution works but i don't understand why the Alias doesn't work.