Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

northerner
New Contributor III

FieldName not working as expected?

Hi All,

I'm trying to create a table that holds the names and position numbers of fields in a QVD. 

For example if I have a QVD with the following fields:

FIELDA, FIELDB, FIELDC

The table would be:

FIELDNAME FIELDPOSITION

FIELDA          1

FIELDB          2

FIELDC          3

The script I've written for this is:

EMPTYTABLE:
LOAD *
FROM QVDNAME (qvd)
where 1 = 0;

TABLE_FIELDS:
load IterNo() as FIELD_NUMBER,
FieldName(IterNo(), 'EMPTYTABLE') as FIELD_NAME
autogenerate 1
while IterNo() < NoOfFields('EMPTYTABLE');

This produces a table with the correct number of rows.  FIELD_NUMBER is populated correctly but FIELD_NAME is null. 

Have I missed something obvious?  I'd be greatful for any help/explanations!

Tags (2)
1 Solution

Accepted Solutions
flipside
Valued Contributor II

Re: FieldName not working as expected?

I wouldn't do it that way. Access the XML structure as this ...

TABLE_FIELDS:

LOAD

    Rowno() as FIELD_NUMBER,

    FieldName as FIELD_NAME

FROM [{name}.qvd] (XmlSimple, Table is [QvdTableHeader/Fields/QvdFieldHeader]);

.. really simple and quick.

flipside

EDIT: If querying multiple qvds, then the Rowno() will continue incrementing from last stored value, so RecNo() might be neaded to give you the Field_Number within the QVD.

1 Reply
flipside
Valued Contributor II

Re: FieldName not working as expected?

I wouldn't do it that way. Access the XML structure as this ...

TABLE_FIELDS:

LOAD

    Rowno() as FIELD_NUMBER,

    FieldName as FIELD_NAME

FROM [{name}.qvd] (XmlSimple, Table is [QvdTableHeader/Fields/QvdFieldHeader]);

.. really simple and quick.

flipside

EDIT: If querying multiple qvds, then the Rowno() will continue incrementing from last stored value, so RecNo() might be neaded to give you the Field_Number within the QVD.