Focal Point
Define Vs Compute

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3251087642

September 14, 2007, 01:57 AM
focuzsambit
Define Vs Compute
What is the difference between define and Compute ?

sambit/wf 7.1.6/aix/oracle8i
September 14, 2007, 02:08 AM
Pete
Hi,

The difference between a define and a compute , is that , compute are being performed on the result set and defines on the table , in short define are executed before any where clauses or by statements have been processed.

Hope this helps a bit

P.


D: WF 7.6.2 P. : WF 7.6.2 on W2003
------------------------------------------------------------------
I see myself as an intelligent, sensitive human, with the soul of a clown which forces me to blow it at the most important moments.

-Jim Morrison-

September 14, 2007, 09:28 AM
Prarie
Check this post
https://forums.informationbuilders.com/eve/forums/a/tpc/...411098331#6411098331


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
still kinda what i said , right? Smiler


D: WF 7.6.2 P. : WF 7.6.2 on W2003
------------------------------------------------------------------
I see myself as an intelligent, sensitive human, with the soul of a clown which forces me to blow it at the most important moments.

-Jim Morrison-

Yep...sure is.


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
The definition Pete gave you and the link Prairie sent you to both explain the differences between a Define and a Compute.

Another tip would be to download a copy of "Creating Reports With WebFOCUS Language" for your version and do a search on "Compute" and "Define". You will learn what you can and cannot do with each type of temporary field as well as pick up other useful pieces of information you can use in WebFOCUS such as "tiling".

You can use a temporary field created by a DEFINE command, or by the DEFINE attribute in a Master File, as a sort field. However, you cannot use a temporary field created by a COMPUTE command as a sort field UNLESS you first creating a HOLD file that includes the field, and then reporting from the HOLD file.

The COMPUTE command cannot be used to create a tile field.

I had no idea about tiling until I began searching for "Define" versus "Compute". So search away and it will open up avenues you have yet to consider.

Good Luck


Glenda

In FOCUS Since 1990
Production 8.2 Windows
The way I like to describe the difference:

1) DEFINE : Works on each row retrieved
2) COMPUTE: Works on summarized level of data

E.G. When calcualting TAX on a sales receipt, TAX has to calculated on a line item basis, this accomodates products that are non-tax rated:. use DEFINE
If you were to use a COMPUTE and summarised the receipt to transaction level, then tax would be calculated on the total not just those items which were non-zero rated.

P
Never say never.

One can sometimes also sort by a computed field without using an interim hold file as the following request demonstrates.

TABLE FILE CAR
PRINT COMPUTE CNTR/I9=CNTR + 1;
BY HIGHEST TOTAL CNTR
BY COUNTRY
END

Gives these results.

CNTR COUNTRY CNTR
---- ------- ----
5 W GERMANY 5
4 JAPAN 4
3 ITALY 3
2 FRANCE 2
1 ENGLAND 1


FOCUS 7.6 MVS PDF,HTML,EXCEL
FOCUS processes things using an Internal Matrix. There are a number of steps on what the order of operations are in this matrix but basically, a DEFINE will create these types of temporary fields for each row in the database. If you have 2millions rows in the db, then the temp fields created this way will have 2mil also. These types are done on a line-by-line instance.

A COMPUTE uses only the values that have been summed down by the BY statements. They are more efficient because there are less rows in the matrix at this point, but they are also summed, meaning you will not get the same results as a DEFINE. Any WHERE tests MUST use WHERE TOTAL.

I have some examples from a class that I taught if you need more details.
Carol


------------------------------------------
last version used: v7.1; truly miss the wonderful things I did with WebFOCUS, HTML, & JavaScript.
ET,

I guess you found an error in the manual then. I'll continue to hold first just to be on the safe side.

Thanks,


Glenda

In FOCUS Since 1990
Production 8.2 Windows
Glenda,

My intent was not to correct you. I sincerely apologize if that is what you took my response to be. I also did not find an error in the manual. What the manual states is 100% correct. This is also not an undocumented and unsuported feature. You really can't sort a computed field using just a BY. But I used "BY TOTAL".

My intent was really to point out that "BY TOTAL" can sometimes be used to in effect sort a computed field resulting in one physical pass through the data and could be viewed as a tip/technique item that the FOCUS community may not be aware of. (A parallel to this is "if/where total" against a computed field can act like screening against a defined field).

In my case the computed field involved nested if/then/else logic against a large joined db2 table structure returning millions of rows. If I had used a define and then sorted by the defined field, then the request resulted in the join not being passed to db2 (just selects and focus then had to manage the join) making it piggy and inefficient. Using a compute and then holding and passing the hold file would mean I would have to write millions of records once and then read, sort and write it out again. Using "BY TOTAL" I did it all in one pass.


ET


FOCUS 7.6 MVS PDF,HTML,EXCEL
Hey There -

No insult taken. I learn through mistakes (and it usually only takes one time per mistake Big Grin). Actually, had I continued to search the manual for further occurrences of "compute", I would have come across the tidbit "by total".


Glenda

In FOCUS Since 1990
Production 8.2 Windows