Re: Re[2]: Local variable acting static in 4GL report
Posted in 1997
>Date: Wed, 05 Feb 97 15:15:54 PST >From: "Peter Neilson" <peter_neilson@lendlease.com.au> >X-Informix-List-Id: <list.12985> > >Neil Gall wrote: > >>I seem to recall that I-4GL's report functions do not behave like true >>functions in terms of privacy of locally declared variables. Perhaps you >could try a global tv variable instead, with something like: >> >>function report_driver() >>... >> foreach processed_row >> ... >> let tv = 0 >> output to report your_rpt(your_row.*) >... >> end foreach >> ... >>end function > >>To my knowledge, global variables behave as they should in report >>functions. Sorry I couldn't tell you why though. I made a posting yesterday explaining that local variables in a report are declared as local static variables in the C code reports (and operate equivalently in p-code). >I have a feeling that global variables *may* not always do what you expect >within report blocks. If the report is ordered internally, the values of >the global variables, when read within the report block, may not be in step >with the program? Your warning is valid! It depends on what you expect the global variable values to be in a two-pass (ORDER {INTERNAL} BY) report... A two-pass report operates roughly as follows: START REPORT - creates a temporary table in the database, and an insert cursor for it. OUTPUT TO REPORT - inserts the parameters passed into the report into the temporary table. FINISH REPORT - closes the insert cursor. - selects all the data from the temp table in sorted order and then executes the various report control blocks. When the body of the report is executed, therefore, any global variables which are referenced in the report will always have the same value as they had at the point when the FINISH REPORT statement is executed (subject to the report and any functions it calls not changing the global variables). Consequently, you cannot use global variables as a way of passing per-row data into a 2-pass report. It isn't recommended for 1-pass reports either, because you get into bad habits, but it will actually work. Note that you can create a 2-pass report without using an ORDER {INTERNAL} BY clause. Using a GROUP PERCENT aggregate will do it (surprise!), and so will printing overall aggregates anywhere except in the ON LAST ROW block. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>