Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report processing 3

Status
Not open for further replies.

forumguy

MIS
Feb 5, 2007
16
0
0
US
Hi guys,

Wanted to know in what order the crystal processes the formulas placed in different sections of the report. Is the order of evaluation is:

First the Formulas in Report header then
page header then
group header then
details then
group footer then
page footer then
Report footer?

Are the formulas in group header evaluated before the formulas in details as the group header section comes before the details?

Formulas are on the fields not on constants.

Thanks,

 
Look up evaluation times in the on line help. Crystal does two or three passes of the data to process a report. Formulas are calculated at three stages in the processing cycle.

If the formula has constants or just uses paramters, it is evaulated "BeforeReading records",

If you jsut use database fields, then they are evaluated "WhileReadingRecords".

Then Crystal does record selection, summaries, group selection, TopN, Running Totals, etc.

Finally any formula using summaries, running totals, etc are calculated "WhilePrintingRecords". These formulas can't be summarised as that is only done earlier.

If the order of formulas within one of those steps is an issue, then there is also "EvaulateAfter"

Editor and Publisher of Crystal Clear
 
chelseatech's description is accurate.

Also look at Report Processing Model in your help file. The flow-chart is somewhat clarifying.

Within one of the bubbles in the flow chart you might have a question as to what it will choose to do first. Crystal then picks based on what it 'thinks' you need it to do. And usually it is correct. What it thinks is occasionally based on what section you place the item in. I don't believe I've ever seen it choose based on a right-to-left criteria of any kind.

And the answer to your direct question is yes. Group footer formulas are generally evaluated after the details are evaluated (but not always). However you can put a summary object into the group header and it will evaluate after the details are evaluated even though it is higher on the canvas. So the over-arching concern is the three pass model described by chelseatech and in the help file. The order on the canvas only occasionally comes into play and isn't to be trusted, as a rule.

Also, formulas appearing on the page and report headers/footers can reflect whatever detail record was active at the time the formula was evaluated.

That's why the answer isn't a simple yes or no.

What chelseatech didn't say explicitly but implied is that you can use keywords to move some formulas to different evaluation times. So if you are having trouble with one formula evaluating before another, use keywords to change the evaluation time.

For example;

Code:
evaluateafter({@formulaA});

global numbervar numExample;

numExample:=0;

In this case the report writer might have been trying to do something summary with Formula A and it was showing up as zero because this formula was being evaluated first. And presumably they are in the same evaluation time. Putting the evaluateafter keyword in directs crystal to complete formula A (and display it if visible) before running this formula.

Naturally Crystal will fight you on evaluation time if it has to, such as declining to evaluate a shared variable before reading records. It gives you an error message when it balks.

As a side note, if you tell crystal to evaluateafter a given formula and that formula previously wasn't being fired off by anything (maybe it isn't on the canvas) then this would force it to be run.

 
Thanks for comments, but to understand the report processing, I tested one scenario below:

-From Xtremedatabase used customer table
-pulled some records on detail section and grouped on country
-In the group header inserted this @Formula1:
whilereadingrecords;
global numbervar R1 := 1;
R1;
-In the detail section inserted this @Formula2:
whilereadingrecords;
global numbervar R1 := R1+1;
R1;

I wasn't able to understand the results in the formula fields. The values in the detail remain constant contrary to my expectation that the values of details may increment and reset to 1 in the group header.
Could you please explain whats happenning seeing the results? Which formula is being evaluated first; the group header one or the detail one?
(Though if I use whileprintingrecords in the above formulas, it comes out as expected)

Thanks
 
I'll give it a go.

Okay. Now try the following.
Using your example, with the formulas running as whilereadingrecords pull formula1 from the group area into the details section along side formula2.

Note that formula1 shows '1', and formula2 shows '2' all the way down.

Remove the group; delete it. Same results without as with the group.

This is, in raw form, what you are doing by forcing these formulas into 'whilereadingrecords'. Causing them to activate the formulas before any sorting is applied. In a sense you are confusing the processing model since it doesn't quite know what to do with formula1 in the group when it hasn't applied the grouping yet. So it applies it to all records. Before it does the addition in Formula2.

If you re-examine the information in help on the report processing model, you can see the formulas in question occur at the 'Recurring Formulas' point. BEFORE the grouping. The system doesn't yet know that formula1 is to applied at the group level. So it looks at the two formulas and decides to do each of them all the way down.

Remove formula1 from the canvas. Voila! (or viola if you like music.) The single formula, sans group, is working perfectly to count down the page. Next add a record sort on Country but make it descending. Freaky-deaky. You now have the numbers in descending order. Again, the process is occurring before the sort/group gets applied.

Drop formula1 back in and they all change to your card. In this case 1s and 2s.

But turn them into whileprintingrecords, and everything is different. The sort/grouping options have all been applied. You no longer get the inverted number set.

A lot of this you'll handle intuitively.

I won't deny this is a confusing example situation, though.
 
Appreciate ur comments.

In the actual report that I am developing, in the running total condition I need to refer to a formula that has "whileprintingrecords" statement in it.

I am getting error/empty when I run the report. Shouldn't the above scenario work as running totals are evaluated during 'whileprintingrecords' and the formula that i m refering in the condition includes 'whileprintingrecords' too?

Thanks
 
No. Running totals are evaluated just before print time formulas even though they are both 'whileprintingrecords'.

It goes, in order during 'whileprintingrecords':

Group selection, running totals, Print time formulas (your formula), subreports/charts/maps, Olap/crosstabs, PageOnDemand.

You are probably going to have to recreate your running total as a formula set. If you look in your help file, go to the contents, go down to running totals, creating running totals, creating running totals using a formula.

Not much chance you can avoid this. Tends to work better anyway, though.
 
In the running total condition I tried putting "evaluateafter" to the formula that has 'whileprintingrecords' statement to force running total to be calculated after the whileprintingrecords formula. It wont work!.



 
No, it wouldn't.

I think you are trying to jam the running total object into a job it can't do.

Maybe we can help you work on the real problem you are trying to solve. Why don't you start over with a new thread, define the problem, give your specifics on what your data looks like and what output you are trying to achieve.

Also give your crystal version and database type and version.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top