Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello all,
I am trying to generate a text that will be used to load an inline table, for every table that was previously loaded in the script.
The use case is to get tables with a dimension column with values that are the dimensions of the previously loaded tables.
Here is what I have so far:
let N = NoOfTables();
let fields = '';
trace there are $(N) tables;
for table_number = 0 to NoOfTables()-1
let table_name = TableName(table_number);
let fCount = NoOfFields('$(table_name)');
for field_number = 1 to NoOfFields('$(table_name)')
let field_name = FieldName(field_number,'$(table_name)');
let fields = '$(fields)' & chr(13) & '$(field_name)';
next
// creat inline load statement
let inline_load = 'LOAD * INLINE [dim_$(table_name)';
let inline_load ='$(inline_load)$(fields)';
let inline_load ='$(inline_load)];';
// store inline_load statement into external file for every table
self: load '$(inline_load)' as inlineload AUTOGENERATE 1;
Store self into log_$(table_name).txt;
// clear fields
trace -$(inline_load)-;
let fields='';
next
I have noticed that whenever I think of a solution to something in QVS, I tend to find a 'more elegant' solution some time later here in the forum or somewhere else. I would say that this is due to QV/QVS bases it's programming logic on data tables, while I have been mostly trained in lambda and object oriented programming, but this is just an educated guess on my part. If this approach seems farfetched it would be great to know that it is so, and that there is another way to do what I am trying to accomplish.
You don't need the inline-load - an autogenerate would be enough, maybe something like this:
let vDocument = documentname();
for table_number = 0 to NoOfTables()-1
let table_name = TableName(table_number);
let fCount = NoOfFields('$(table_name)');
for field_number = 1 to NoOfFields('$(table_name)')
let field_name = FieldName(field_number,'$(table_name)');
[Table & Fields]:
load '$(table_name)' as TableName, '$(field_name)' as FieldName AUTOGENERATE 1;
next
next
Store [Table & Fields] into DataStructures_$(vDocument).txt (txt);
- Marcus
You don't need the inline-load - an autogenerate would be enough, maybe something like this:
let vDocument = documentname();
for table_number = 0 to NoOfTables()-1
let table_name = TableName(table_number);
let fCount = NoOfFields('$(table_name)');
for field_number = 1 to NoOfFields('$(table_name)')
let field_name = FieldName(field_number,'$(table_name)');
[Table & Fields]:
load '$(table_name)' as TableName, '$(field_name)' as FieldName AUTOGENERATE 1;
next
next
Store [Table & Fields] into DataStructures_$(vDocument).txt (txt);
- Marcus
That worked marvelously, thank you Marcus.