IBI WebFOCUS - Difference between DEFINE and COMPUTE

In our day to day coding in WebFOCUS we would have used DEFINE and COMPUTE many a times. Even if you go for an interview this is the most common question (More than 90%). Surprising fact is there are many who cannot answer this question properly.

Answering this question doesn't guaranty you the job but it is expected from a WebFOCUS developer to know the difference. First of all what is DEFINE and COMPUTE in WeBFOCUS term?

The Answer is simple. Both does create virtual fields. They are used in WebFOCUS to perform calculated fields. Now when both does calculation, why do we have 2 options to do that?

There are few differences listed below:
1) Calculation using DEFINE is on row by row basis meeting the selection criteria and Calculation using COMPUTE is done when all aggregation and sorting is done. For example- if the database has 100000 records for sales transaction and we want to aggregate it by 4 Regions. In case of DEFINE the calculation will happen 100000 times however in case of COMPUTE the calculation will happen only 4 times.
Now the question comes to our mind is how to choose from DEFINE and COMPUTE. Well! the answer depends on the requirement. 
a) If you are able to get the same result in both the cases, it is always preferred to use COMPUTE since performing computation 4 times is always better than doing it 100000 times.
b) If you are printing data at TABLE FILE level, then both will report same output and efficiency will also remain same.
c) If you need to filter on COMPUTE'd column, you need to use "WHERE TOTAL" with the column name however in case of DEFINE'd one you can simply use WHERE clause.

Example:
Below is the detail of number of marks obtained by an student. Percentage column will be the calculated column based on general calculation of percentage of marks:



If we need aggregated Marks and Percentage for the Student, the percentage would be (79+81+90 =250) in case of DEFINE, which is not correct. So be more careful in choosing from DEFINE and COMPUTE when you are doing division and multiplication in your calculation. 

One more thing. It is always suggested to use least number of possible DEFINE'd and COMPUTE'd field to maintain the report performance.

Comments

Popular posts from this blog

IBI WebFOCUS - Functions available and syntax to use

IBI WebFOCUS - Testing and Debugging in WebFOCUS codes

IBI WebFOCUS - Difference (Preference) between Join and Match: