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: 
datanibbler
Champion
Champion

Tablename()?

Hi,

can anybody please explain to me the use of this function which is not detailed in the help_file?

I have been proposed this as part of a code to clean up all existing tables (but for specific ones), but I guess it can also be used in combination with the TRACE command to see which tables exist at a given point, e.g. within a subroutine, each time it is called.

From the help_file I know that it takes the table_number as a parameter - but what is the table_number?

Thanks a lot!

Best regards,

DataNibbler

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Table_number is the sequence number of loaded tables. The first loaded table has number 0, second one 1, .. 2, .... That means if you have loaded tables like :

Tab1:

Load

          * From <>;

Tab2:

Load

          * From <>;

TableName(0) -> returns 'Tab1'

TableName(1) -> returns 'Tab2'

Hoep this helps.

View solution in original post

7 Replies
tresesco
MVP
MVP

Table_number is the sequence number of loaded tables. The first loaded table has number 0, second one 1, .. 2, .... That means if you have loaded tables like :

Tab1:

Load

          * From <>;

Tab2:

Load

          * From <>;

TableName(0) -> returns 'Tab1'

TableName(1) -> returns 'Tab2'

Hoep this helps.

datanibbler
Champion
Champion
Author

Hi tresesco,

it does help. I supposed so much, but having it from someone who knows is better.

Unfortunately, in the context I want to use this currently, I don't know the sequence, so that doesn't really help me - but it is good to know. I might be able to use this lateron.

Thanks!

Best regards,

DataNibbler

maxgro
MVP
MVP

for tab=1 to 3

  trace **********;

  Table$(tab):

  load

  rand() * 100  as [Field Table$(tab)]

  AutoGenerate 10;

  // trace with tablename and tablenumber

  for i=0 to NoOfTables()-1

   let t=TableName(i);

   let n=TableNumber(TableName(i));

   trace TableName is $(t);

   trace TableNumber is $(n);

  next;

next;

tresesco
MVP
MVP

DataNibbler wrote:

I have been proposed this as part of a code to clean up all existing tables (but for specific ones),...

So you know the names of the tables before hand, if so, would not simply using Drop Tables help? Am I missing something?

datanibbler
Champion
Champion
Author

Hi tresesco,

the context was a subroutine and for some reason some fragmented tables were being created in the individual iterations, but I didn't know for sure where and why - and I cannot write a DROP statement for a fragment anyway beecause of the "-" ...

Of course, whenever you know the names of interim tables, dropping them right away with this statement is the more elegant solution.

Also, I am having trouble with the TRACE: I can set a variable to TableName(0) and then write a TRACE statement with the value of that - but somehow writing TRACE TableName(0) or something like that won't work.

Can you help me there?

Thanks a lot!

tresesco
MVP
MVP

Alternative could be, like:

vTab=TableName(0);

Trace $(vTab); sleep 1000;

datanibbler
Champion
Champion
Author

Hi,

yep, exactly as I thought. It works fine. Only the TableName() can't be directly inserted into the TRACE for whatever reason. You have to go via a variable.

In the log_file, you then always have two lines - one with the complete TRACE_statement and one with its output 😉