Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us for a live Q&A! September 21, 10 AM ET - Onboarding Fast in Qlik Sense SaaS! REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
tamilarasu
Champion
Champion

Save All Field Names In New Table

colorful-hello-text-smiley-emoticon.gif All,

I want a script that should store all the field names alone in the document. For example, If I have 5 tables and 35 fields in a document, I want to store all the fields names in a new table or qvd.

Thanks in advance.

1 Solution

Accepted Solutions
sasiparupudi1
Master III
Master III

Hi This is the script from

let vTabName = 'DataStructures';

let vLoadStart = num(now() - today(), '#.########', '.', ',');

for i = 0 to NoOfTables() - 1

    for ii = 1 to NoOfFields(TableName($(i)))

        let vTableName = '[' & TableName($(i)) & ']';

        let vFieldName = '[' & FieldName($(ii), TableName($(i))) & ']';

        let vFieldCounter = 0;

        for j = 0 to NoOfTables() - 1

            for jj = 1 to NoOfFields(TableName($(j)))

                let vFieldNameCounter = '[' & FieldName($(jj), TableName($(j))) & ']';

                let vFieldCounter = if('$(vFieldName)' = '$(vFieldNameCounter)', 1 + $(vFieldCounter), $(vFieldCounter));

            next

        next

        DataStructure:

        Load

            $(i) as TableNumber,

            TableName($(i)) as TableName,

            NoOfRows(TableName($(i))) as Rows,

            $(ii) as FieldNumber,

            FieldName($(ii), TableName($(i))) as FieldName,

            Count($(vFieldName)) as FieldTotalCount,

            Count(distinct $(vFieldName)) as FieldDistinctCount,

            MissingCount($(vFieldName)) as FieldMissingCount,

            TextCount($(vFieldName)) as FieldTextCount,

            NumericCount($(vFieldName)) as FieldNumericCount,

            NullCount($(vFieldName)) as FieldNullCount,

            num(Count($(vFieldName)) / NoOfRows(TableName($(i))), '#.##0%') as FieldDensity,

            if(TextCount($(vFieldName)) >= 1 and NumericCount($(vFieldName)) >= 1, 'mixed',

                if(TextCount($(vFieldName)) >= 1, 'string', 'numeric')) as FieldFormat,

            if($(vFieldCounter) > 1, 'yes (' & $(vFieldCounter) & ')', 'no') as Key

        Resident $(vTableName) Where '$(vTableName)' <> 'DataStructure';

        let vFieldCounter = 0;

    next

next

store DataStructure into $(pApp@03)DataStructure.qvd (qvd);

$(Include=$(pScript@04)Include_LoadLogging.txt);

HTH

View solution in original post

6 Replies
darkhorse
Partner
Partner

Hello,

Check Fieldname() and TableName() from Help.

BR

Serhan

tamilarasu
Champion
Champion
Author

Hi Serhan,

I have lots of tables in my document and wants to store all them in a new table. So I guess the loop should be correct solution for the above scenario. As I am new to qlikview, struggling to get the desired result.

Thanks

Tamil

darkhorse
Partner
Partner

Hello,

Right. Loop would solve.

Something like

for i = 0 to nooffields('tablename')

next i

You can even try it with a nested loop (loop for tables too). There is nooftables() function as well. You can send the table name in the above example parametric with tablenumber().

Just trying pseudo because I don't have the exact code but it's more than possible with the technique above.

BR

Serhan

sasiparupudi1
Master III
Master III

FOR i = 0 to NoOfTables() - 1

    LET vTableName = TableName($(i));

    LET vOutfile = '$(vTableName)' & '_' & '$(vPeriodo).csv';

    STORE [$(vTableName)] INTO [$(vOutfile)] (ansi, txt, delimiter is ';');

NEXT   

sasiparupudi1
Master III
Master III

Hi This is the script from

let vTabName = 'DataStructures';

let vLoadStart = num(now() - today(), '#.########', '.', ',');

for i = 0 to NoOfTables() - 1

    for ii = 1 to NoOfFields(TableName($(i)))

        let vTableName = '[' & TableName($(i)) & ']';

        let vFieldName = '[' & FieldName($(ii), TableName($(i))) & ']';

        let vFieldCounter = 0;

        for j = 0 to NoOfTables() - 1

            for jj = 1 to NoOfFields(TableName($(j)))

                let vFieldNameCounter = '[' & FieldName($(jj), TableName($(j))) & ']';

                let vFieldCounter = if('$(vFieldName)' = '$(vFieldNameCounter)', 1 + $(vFieldCounter), $(vFieldCounter));

            next

        next

        DataStructure:

        Load

            $(i) as TableNumber,

            TableName($(i)) as TableName,

            NoOfRows(TableName($(i))) as Rows,

            $(ii) as FieldNumber,

            FieldName($(ii), TableName($(i))) as FieldName,

            Count($(vFieldName)) as FieldTotalCount,

            Count(distinct $(vFieldName)) as FieldDistinctCount,

            MissingCount($(vFieldName)) as FieldMissingCount,

            TextCount($(vFieldName)) as FieldTextCount,

            NumericCount($(vFieldName)) as FieldNumericCount,

            NullCount($(vFieldName)) as FieldNullCount,

            num(Count($(vFieldName)) / NoOfRows(TableName($(i))), '#.##0%') as FieldDensity,

            if(TextCount($(vFieldName)) >= 1 and NumericCount($(vFieldName)) >= 1, 'mixed',

                if(TextCount($(vFieldName)) >= 1, 'string', 'numeric')) as FieldFormat,

            if($(vFieldCounter) > 1, 'yes (' & $(vFieldCounter) & ')', 'no') as Key

        Resident $(vTableName) Where '$(vTableName)' <> 'DataStructure';

        let vFieldCounter = 0;

    next

next

store DataStructure into $(pApp@03)DataStructure.qvd (qvd);

$(Include=$(pScript@04)Include_LoadLogging.txt);

HTH

View solution in original post

tamilarasu
Champion
Champion
Author

Serhan, Sasidhar: Thanks a lot. happy-day-smiley-emoticon.gif to both of you.