Wednesday, June 17, 2009

Test if QlikView table exists within the loadscript

Sometimes, within the loadscript, I need to check if a QlikView table exists or not. Most often this is done after bringing in a separate QlikView document's data with a BINARY statement and I don't know exactly which tables are included in the older document. Sometimes I just need to check if a QlikView table was successfully created earlier in the loadscript.

Here's the way I do it:

If NoOfRows('TABLE_1') > 0 then
  //Put statements here to be
  //used if TABLE_1 exists

Else
  //Put statements here to be
  //used if TABLE_1 does not exist

  End If



 * * *

6 comments:

Anonymous said...

Alos see why QlikView -A need based Comparision at

www.qlikviewvsolap.blogspot.com

Gasi G said...

Another Possibility:

sub tableExists(inputTabName, exists)
exists=false();
for a=0 to NoOfTables()-1
vTabName = TableName(a);
TRACE Vorhandene Table: $(vTabName);
if ('$(vTabName)' = '$(inputTabName)') then
exists=true()
end if
next

if (exists = true()) then
TRACE Table '$(inputTabName)' exists;
else
TRACE Table '$(inputTabName)' does NOT exist;
end if;
end sub

Sheik said...

I doubt this will work when we have a table created but it does not have any row.

Steven White said...

set f_does_table_exist =IF ( IsNull ($1), 'N', IF ( IsNull (TableNumber($1)), 'N', 'Y' ) ) ;

usage:
IF $(f_does_table_exist('tablename')) = 'Y' THEN 'it exists' ELSE 'it doesnt' ;

Unknown said...

How to check if a Map exists?
TableNumber does not work for tables loaded with mapping load

Anonymous said...

A mapping load is transient for the whole duration of a script. Therefore, if you have created it, it exists until the script has completed.

Therefore 'drop table' for a map table would generate an error.

If you go to the Menu: Settings > User Prefs > General tab: tick in "Keep Progress Open after Reload", you should also be able to see all tables being loaded including the map table.