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

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

  End If

 * * *


Anonymous said...

Alos see why QlikView -A need based Comparision at

Gasi G said...

Another Possibility:

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

if (exists = true()) then
TRACE Table '$(inputTabName)' exists;
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' ) ) ;

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.