Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Can IF..THEN.....ELSE...ENDIF control statements be nested in QlikView

Question: Can IF..THEN.....ELSE...ENDIF control statements be nested in QlikView.

I am trying to catch an error, and take actions depending on criteria

basics of script are:

IF condition1 THEN

     IF Condition2 THEN

          Do one thing here - eg. handle error and continue

     ELSE

          Do something else here - eg exit script

     ENDIF

ELSE

     Do something else here

ENDIF

What appears to happen is that when condition 1 in the outer IF is not met, the ELSE from the Inner IF is executed rather than the ELSE for the outer IF

Capture.PNG.png

1 Solution

Accepted Solutions

Re: Can IF..THEN.....ELSE...ENDIF control statements be nested in QlikView

The script:

IF condition1 THEN

     IF Condition2 THEN

          Do one thing here - eg. handle error and continue

     ELSE

          Do something else here - eg exit script

     ENDIF

ELSE

     Do something else here

ENDIF

is absolutely correct, the error can be related to the things you do ... one question, at the end of each instruction in IF have you written the semicolon?

Do one thing here - eg. handle error and continue;

4 Replies

Re: Can IF..THEN.....ELSE...ENDIF control statements be nested in QlikView

The script:

IF condition1 THEN

     IF Condition2 THEN

          Do one thing here - eg. handle error and continue

     ELSE

          Do something else here - eg exit script

     ENDIF

ELSE

     Do something else here

ENDIF

is absolutely correct, the error can be related to the things you do ... one question, at the end of each instruction in IF have you written the semicolon?

Do one thing here - eg. handle error and continue;

datanibbler
Esteemed Contributor

Re: Can IF..THEN.....ELSE...ENDIF control statements be nested in QlikView

Hi Eddie,

I haven't tried such a thing - not in Qlikview, anyway.

Maybe you could just use one IF THEN control statement and put the other one into something like e.g. a subroutine? Or, instead of nesting them (which is more elegant, of course), you could "flatten it out" and write sth like >>> IF ([condition 1] AND [condition 2]) THEN

...

ELSEIF [condition 1]

...

ELSE

...

ENDIF <<<

Try it out - in my experience from other scripting languages, you should always account for the most special case - that is likely to be true in the smallest nr. of instances - first.

Best regards,

DataNibbler

eduardo_sommer
Valued Contributor

Re: Can IF..THEN.....ELSE...ENDIF control statements be nested in QlikView

Hi Eddie

Look at the semicolon in the end of the first IF

          THEN;

This can be the problem

Eduardo

Not applicable

Re: Can IF..THEN.....ELSE...ENDIF control statements be nested in QlikView

Looks like the issue was to do with trying to interrogate the ScriptError and ScriptErrorDetails within the inner IF. These system variables appear to have Cleared/Reset on successful execution of the outer if....

Community Browser