Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
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
alexandros17
Partner - Champion III
Partner - Champion III

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;

View solution in original post

4 Replies
alexandros17
Partner - Champion III
Partner - Champion III

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
Champion
Champion

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
Partner - Specialist
Partner - Specialist

Hi Eddie

Look at the semicolon in the end of the first IF

          THEN;

This can be the problem

Eduardo

Not applicable
Author

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....