A better way to suppress sections

Friday 7 December 2012 @ 12:42 am

Crystal allows you to write a formula to conditionally suppress a section. Recently I have found that there are several advantages to putting the suppress logic in a formula field instead of directly into the condition formula.  I then use that formula field inside my suppress condition. I find that this method makes it:

1) Easier to write
I find it easier to think in terms of what I want to see rather than what I want to suppress, especially when the logic gets complex.  So I write a Boolean formula called “Show Details” that will display TRUE on records that should be visible and FALSE on the records I want to suppress.  My section suppress condition is then:

not {@show details}

2) Easier to change
If you want to change a suppress condition you have to open the section expert, highlight the specific section and click the suppress condition button. Then when you are done you have to save the formula, and then click ‘OK’ to exit the Section Expert. It might be just a few extra clicks, but when you are doing testing and have to go in a dozen times, it can be annoying.  But if the logic is in a formula field you simply right-click on the formula and select ‘Edit’.  When you save the formula you are done.

This is especially important if you plan to use the same logic to control several different sections. You can write one formula that has the logic and refer to it in multiple suppress conditions. Any changes can then be done in one place.

3) Easier to test.
If you put the logic into the suppress condition formula, testing to see if it works can be a challenge.  If there is a typo that causes it to suppress too many records, it may not be obvious right away (you can’t notice something if the section is suppressed). But, if you put the criteria into a formula field you can do testing by putting the formula onto the section, and without having to suppress anything. The formula will print TRUE and FALSE values and you can review them to see if the values are on the correct records.

4) Easier to re-use.
Some times other calculations need to take into account which records are suppressed. By creating a “Show Details” field you can incorporate that logic into other formulas like this:

If {@Amount} > 100
and {@Show Details}
then ........

Now if you have to change the logic in the ‘Show Details’ formula, this new formula will respond accordingly.

(For examples of my most popular formulas, please visit the FORMULAS page on my website.)







Leave a Reply

Jeff-Net
Recrystallize Pro

Crystal Reports Server