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.

giakoum
Honored Contributor II

sanity check...

Hi all.

I have a table with 5 values, and I need to concatenate those values forming a string. Since I am going to use this string to load from a table, the 5 values actually represent field names so I need to put them into brackets, because there are spaces in the names.

So I thought of looping through the table and construct the string like this :

SET sectionAccessKeyFields='';

FOR currentFieldNameIndex=1 TO FIELDVALUECOUNT('KeyField')

          LET currentFieldName=FIELDVALUE('KeyField',$(currentFieldNameIndex));

 

          SET sectionAccessKeyFields=$(sectionAccessKeyFields)[$(currentFieldName)];

 

NEXT

The strange thing is that brackets for 1st field seem to just disappear (see red arrows in image) but not for the next 4 fields. I have found a workaround for this, so I need NOT a solution, merely an explanation why this is happening. The workaround I came up with is to start from a non-empty string. but do you have any idea as WHY this is happening? I have attached a file with both the problem and the workaround.

2013-01-23_1124.png

Thank you for your time.

Ioannis.

7 Replies
sujeetsingh
Honored Contributor III

Re: sanity check...

I am nat able to get it ??

giakoum
Honored Contributor II

Re: sanity check...

I am not sure what you mean... you did not understand the problem or...

flipside
Valued Contributor II

Re: sanity check...

Hi Ioannis,

It looks like Qlikview is stripping off the square brackets when it picks up the first pass, probably because they are a reserved character in Qlikview language.

You can see this in action ...

SET sectionAccessKeyFields3=[PRODUCT TYPE ID];

SET sectionAccessKeyFields4=[PRODUCT TYPE ID][REGION ID];

SET sectionAccessKeyFields5=$(sectionAccessKeyFields3)[REGION ID];

The middle variable works fine, but the last variable strips off the brackets.

I tend to use LET instead of SET when building strings so as to avoid confusion ...

SET sectionAccessKeyFields=;

FOR currentFieldNameIndex=1 TO FIELDVALUECOUNT('KeyField')

    LET currentFieldName=FIELDVALUE('KeyField',$(currentFieldNameIndex));

    LET sectionAccessKeyFields='$(sectionAccessKeyFields)' & '[' & '$(currentFieldName)' & ']';

NEXT

flipside

giakoum
Honored Contributor II

Re: sanity check...

Hi flipside.

Thank you for your answer.

My guess also, brackets being a reserved character, but why does not the same apply to the second and subsequent pass? This is what really troubles me.

Ioannis.

MVP & Luminary
MVP & Luminary

Re: sanity check...

Hi,

Try this way

LOAD * INLINE [

    KeyField

    PRODUCT TYPE ID

    REGION ID

    AREA ID

    SUBSALESUNIT ID

    ACCOUNT ID

];

//This makes the brackets for the 1st field disappear

SET sectionAccessKeyFields = '';

FOR currentFieldNameIndex=1 TO FIELDVALUECOUNT('KeyField')

    LET currentFieldName= '[' & FIELDVALUE('KeyField',$(currentFieldNameIndex)) & ']';      

    LET  sectionAccessKeyFields= sectionAccessKeyFields & currentFieldName;   

NEXT

Hope this helps you.

Regards,

Jagan.

giakoum
Honored Contributor II

Re: sanity check...

Hi Jagan.

thank you but I have found already a similar solution. I just need to know WHY QlikView behaves like this.

Regards,

Ioannis.

MVP & Luminary
MVP & Luminary

Re: sanity check...

HI,

I think it is evaluation the value for the first time, I am not sure about this.

Regards,

Jagan.

Community Browser