Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
hic
Former Employee
Former Employee

There are several good reasons not to use macros in QlikView.

 

First of all, macros are run using Microsoft COM Automation. They will run client-side and work fine if you use the Desktop or the IE PlugIn, which both are Windows executables. But if you use the Ajax client, there are severe limitations since the macros now need to run on the server instead of on the client. For a server, there are both technical limitations and security implications that have forced us to restrict the capabilities of macros.

 

So, if you want to use the Ajax client, you should avoid macros.

 

Trigger.png

 

Secondly, a common beginner’s mistake is to use macros to build logic into QlikView; logic that almost always works better if QlikView’s own out-of-the-box functionality is used.  An example is assigning a value to a variable every time a selection is made: In other tools you would use a trigger and a macro, but in QlikView this is not needed: You should instead define your variable using an equals sign and the appropriate expression.

 

Further, many problems can be solved by using a smart data model instead of macros.

 

Macros often confuse the user. A user wants a predictable behavior and macros often do exactly the opposite: They create behaviors that exist in some places but not in other. This is counter-intuitive.

 

Finally, if the macro is long or complex, it will often push QlikView into an unstable situation. We have often seen this in documents sent to our support organization. The reason is probably a poor fit between the synchronous, sequential execution of a macro and QlikView’s internal asynchronous, multi-threaded computation.

 

From a development perspective, the macro feature is a secondary functionality. In the development process, it will rarely get first priority when compared to the “native” functionality: I.e. in the choice between keeping macro functionality unchanged and improving the out-of-the-box functionality, the QlikView development team will often choose the latter. This means that you can get a changed macro behavior when you upgrade your QlikView installation.

 

Macro1.png

 

Some facts around macros:

 

  • Single-Threaded?
    Macros are in their nature sequential – i.e. in a way single-threaded. But this is not the same as saying that all calculations started by macros are single-threaded. For instance, if a macro makes a selection that causes a chart to be calculated, both the logical inference and the chart calculation are multi-threaded. As they should be.
  • Clears cache?
    No. A macro does not clear the cache. (Unless you use the macro in the picture above...)
  • Clears the Back-Forward stack?
    No. A macro does not clear the Back-Forward stack.
  • Clears the Undo-Redo stack?
    Yes, if the macro contains layout changes, the Undo-Redo stack will be cleared.

 

So, I strongly recommend you don't use macros, unless it is in a Desktop environment. And there they should be short and concise! On a server you should instead use Actions.

 

There is however one thing that may confuse the user more than macros. And that is Triggers. If a macro or an action is started from a nicely labeled button, then the user will understand what happens.

 

But if the macro instead is triggered by some other event, e.g. the changing of a variable value, we have a very different situation. Then you will most likely create a non-intuitive behavior.

 

Macros are Bad, but Triggers are Worse.

 

HIC

 

See also

The Key to Heaven

56 Comments
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Karl Pover

In addition to Henric's explanation of the Action sequence for variables, I've found that I can't update a field and reference the updated field value in a subsequent action. It's like the data available to the actions is a read only copy. I've never figured out if this is because the value expressions are pre-calculated before the actions are executed or what.

For example, consider this chain of "Select In Field" actions:

1. Field = F2, Value = max(F1)

2. Field = F3, Value = max(F2)

F3 will get set with whatever max(F2) was before Action#1 was executed.

2,952 Views
athompsonhp
Contributor III
Contributor III

Although you have some good arguments BUT I disagree in your strong use of BAD.  Macros offer developers a means to write Functions which are NOT included in the native QlikView.  I have written some very complex functions which are confidential and cannot be shared.  If I was not able to do this development then QlikView would be very limited.  Actually it is the Macro functionality of QlikView that separates QlikView from the other BI tools!!  So I would say "Practice Safe Macros" and not "Macros are Bad".

0 Likes
2,952 Views
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Kevin Bertsch

"If QV had any type of user defined function/sub-routine in its scripting tool, I wouldn't need the

macro, but AFAIK, it doesn’t."

QV Script does support subroutines well. Also $include files which allow you to pull in script snippets from external files. Provides great re-usability.

QV Script does not currently support writing true Functions in the script language. It's one of the features I keep lobbying for. Variables with parameters are sort of a User Defined Function that can be used in a script, but they are they are limited to a single expression.

2,952 Views
hic
Former Employee
Former Employee

Andy

I agree with everything you say. The use of "Bad" is provocative - but that was also the intention... Also, "practice safe macros" and "avoid user-facing macros" are certainly more nuanced versions of the same message.

The reason for the blog post is that we at Qlik, fairly often see examples of excessive macro usage; macros that are unnecessary since they just mimic QlikView's native functionality; macros that are unmanageable since they are long and complex; macros that degrade QlikView performance and macros that destroy the simplicity that our users love. And sometimes the files are sent to our support with a question why it doesn't work...

To make a point, I deliberately chose "Macros are Bad" as title.

HIC

0 Likes
2,952 Views
barryharmsen
Luminary Alumni
Luminary Alumni

Henric Cronström wrote:

To make a point, I deliberately chose "Macros are Bad" as title.

Oh Henric, you provocateur

2,884 Views
luciancotea
Specialist
Specialist

Told ya there's going to be a storm of comments

2,884 Views
Jason_Michaelides
Luminary Alumni
Luminary Alumni

Barry Harmsen, for your customized table, check out my post on an alternative and much less time-consuming way to do this - http://community.qlik.com/docs/DOC-6046

Hope it helps,

Jason

0 Likes
2,884 Views
ThornOfCrowns
Specialist II
Specialist II

Badly written code of any stripe is BAD, IMHO.

However, my main gripe is that if I want some control over printing, I need to have some code behind the scenes as it is plain that QV view of " ... the way we see it is that reporting is better done by our partners than by us." isn't going to help me any time soon.

I know, I know, QV isn't a reporting tool, etc., etc., but that viewpoint isn't universally accepted by users, it's sad to say.

0 Likes
2,884 Views
amonjaras
Partner - Creator II
Partner - Creator II

Thank you Henric and everyone for a great discussion that may not have been so active with a different title .

I advocate a "responsible" use of macros by making sure the consultants / developers / clients understand how powerful they are. They need to be aware that they can make an application possible, like Mathias Vanden Auweele points out, or they can completely ruin the associative experience for the end-user.

Needless to say, we strive to make sure that every macro is absolutely necessary.

0 Likes
2,884 Views
Not applicable

Rob, if you get a minute, could you please point me to the QV subroutine documentation, because I'm not aware of how to do it.

And since no one apparently got my Djikstra reference, here's a link to "GOTO Considered Harmful"

https://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.pdf

0 Likes
2,884 Views