
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looping Through all Tables in existing Data Model
Hi All,
I want to loop through all of the tables in my data model and store them down into QVDs. I have created the below script to test but it keeps failing. For whatever reason once it gets to the third table the Tables variable returns null(). Any idea why this isnt working. I know I could just write store statements after each load but I have a use case for this and cant understand why its not working.
A:
Load * Inline
[A];
NoConcatenate
B:
Load * Inline
[B];
NoConcatenate
C:
Load * Inline
[C];
NoConcatenate
[D]:
Load * Inline
[D];
let vTables = NoOfTables();
Let i = 0;
Do While i < vTables
Let Table = TableName(i);
NoConcatenate
[Temp]:
Load *
Resident [$(Table)];
Store Temp into [lib://Test\$(Table).txt](txt);
Drop Table $(Table);
Drop Table Temp;
i = i + 1;
Loop;
Exit script
Thanks!
Mark
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah I got it.
Since I was dropping tables in the Loop by doing i + 1 I was skipping tables.
Using the below works
Let i = 0;
Do While i < NoOfTables()
Let Table = TableName(i);
NoConcatenate
[Temp]:
Load *
Resident [$(Table)];
Store Temp into [lib://Test\$(Table).txt](txt);
Drop Table [$(Table)];
Drop Table Temp;
;
Loop;
Exit script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah I got it.
Since I was dropping tables in the Loop by doing i + 1 I was skipping tables.
Using the below works
Let i = 0;
Do While i < NoOfTables()
Let Table = TableName(i);
NoConcatenate
[Temp]:
Load *
Resident [$(Table)];
Store Temp into [lib://Test\$(Table).txt](txt);
Drop Table [$(Table)];
Drop Table Temp;
;
Loop;
Exit script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Further more there is no reason to Load the tables again just the below is sufficient
Let i = 0;
Do While i < NoOfTables()
Let Table = TableName(i);
Store [$(Table)] into [lib://Test\$(Table).txt](txt);
Drop Table [$(Table)];
;
Loop;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Two years later and glad that you documented your outcome 😊
