Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Issue with If in load script at column level

Hello Community,

My understanding is that, for IF condition, wherever condition is satisfied, it comes out of the IF, but it does not seem like that.

In below, I do not have Bname as column in the table, but the hardcode condition should actually skip the else aprt, but it is not.

test:

LOAD

if('A'='A',Aname,Bname) as TName,

* INLINE [

Aname, Aqty

Angad,2

Singh,3

];

This gives error that Bname column not found.

Thanks,

Angad

Tags (3)
1 Solution

Accepted Solutions
MVP
MVP

Re: Issue with If in load script at column level

No. The error message comes as a result of parsing test(syntax). Even before going to execute your if statement or any other statement in the context of original data load, the QV parser has to check for the valid syntax. And there fails your statement, because when the parser finds Bname , it expects it to be a field which can't be sourced. Hence the error. Therefore, in brief your script fails at parsing and not at if statement execution (it doesn't even go to that phase of execution). Hope this helps comprehend.

9 Replies
crusader_
Valued Contributor

Re: Issue with If in load script at column level

Hi,

Of course you'll get this error, because you don't have a definition of Bname in your inline table.

Just add it there and you can leave it empty, error will gone.

Hope this helps.

update: this code will work without errors

LOAD

if('A'='A',Aname,Bname) as TName,

* INLINE [

Aname, Aqty,Bname

Angad,2

Singh,3

];

Andrei

anbu1984
Honored Contributor III

Re: Issue with If in load script at column level

It fails during syntax validation in script, since it didn't find the field Bname.

At runtime, expression 'A'='A' is evaluated and assigns Aname

Not applicable

Re: Issue with If in load script at column level

Hi,

If you use Bname as 'Bname' then it will work and it won't throw any error while loading.

if('A'='A',Aname,'Bname') as TName,

Qlikview throws error as it searches for all fields written in the load script.

s_kunte23
Contributor III

Re: Issue with If in load script at column level

Hi

i thin this isn't 100 % correct. There isn't a column with the name 'A', also you don't have a fieldvalue like 'A', so this won't work. Have a look at the example, this gives you an idea how if works: 

LOAD

if(Aname='Angad',Aname,Bname) as TName,

* INLINE [

Aname, Aqty,Bname

Angad,2

Singh,3

];

Best regards

Stefan

Not applicable

Re: Issue with If in load script at column level

Thanks Andrei, but in original request I cannot add the dummy column in my qvd. So you mean that the if condition traverses the whole line irrespective of condition in case of using columns. Isnt it?

MVP
MVP

Re: Issue with If in load script at column level

No. The error message comes as a result of parsing test(syntax). Even before going to execute your if statement or any other statement in the context of original data load, the QV parser has to check for the valid syntax. And there fails your statement, because when the parser finds Bname , it expects it to be a field which can't be sourced. Hence the error. Therefore, in brief your script fails at parsing and not at if statement execution (it doesn't even go to that phase of execution). Hope this helps comprehend.

Re: Issue with If in load script at column level

Its failed on Syntax check, Since there is no field called Bname

You could do it by using variable instead.

LET vFieldAB = If('A'='A','Aname','Bname');


and use the variable in LOAD statement like below


test:

LOAD $(vFieldAB) as TName, * INLINE [

Aname, Aqty

Angad,2

Singh,3

];

Re: Issue with If in load script at column level

Use something like below

test:

LOAD

if('A'='A',Aname,Null()) as TName,

* INLINE [

Aname, Aqty

Angad,2

Singh,3

];

er_mohit
Honored Contributor II

Re: Issue with If in load script at column level

Set ErrorMode = 0 ;

Community Browser