READ / IF / AT START OF DATA / WRITE

Hi,
i create a report.

But “AT START OF DATA” do not accept inside “IF…END-IF”

Can i do IF and AT START OF DATA in the same procedure?

AT START OF DATA inside an IF does not make any sense as it is data-driven by the containing processing loop.

I’m not quite clear from your post exactly what you are trying to do but I assume something like the following:

read a-view
if a-view.a ne 0
  at start of data
    ignore
  end-start
end-if

AT START clauses are triggered by an event, and completely independent of their position within the processing loop. The code between AT START and END-START occurs as soon as you enter the processing loop, even if you have it as the last snippet of code before the END-READ and 10 lines of code above it. I assume this is why the above throws a compile error. If however, you are doing the following, I do not know why you are seeing an error.

read a-view
at start of data
  if a-view.a ne 0
    ignore
  end-if
end-start

I understand, thanks.

Hi,
WRITE do not have: “GIVE SYSTEM FUNCTIONS” ?

My source:
write

  • GIVE SYSTEM FUNCTIONS
    cidade habitantes

AT END OF PAGE
SKIP 1
WRITE ‘Página Finaliza na Cidade:’ cidade
/ ‘SUM OF SALARIES:’ SUM(habitantes)
END-ENDPAGE

LINE ERROR:
/ ‘SUM OF SALARIES:’ SUM(habitantes)

Error:
NAT0367 Invalid reference of Natural system function.

TEXT:
Invalid reference of Natural system function.
EXPL:
Natural system functions like MAX, MIN, SUM and AVER may only be
used in an AT END OF PAGE condition if their evaluation per page
has been requested with the GIVE SYSTEM FUNCTIONS clause of a
DISPLAY or WRITE statement.
ACTN:
Check program and correct error.

Hi Claudio,
Well, you should try something like this (although I would not recommend you to use those SYSTEM FUNCTIONS and
count all of them (SYSTEM FUNCTIONS) on your own :slight_smile:
However, the following code should work (unless you get OVERFLOW on SUM :slight_smile:

Best of luck.


DEFINE DATA LOCAL
1 myfile VIEW OF MYDATA-VIEW
2 cidade
2 habitantes
END-DEFINE
**
READ myfile
DISPLAY NOTITLE GIVE SYSTEM FUNCTIONS habitantes

AT END OF PAGE
WRITE sum (habitantes)
END-ENDPAGE
END-READ
END

Yes.
So I have already got.

I spent more on the error, says it should also work for the WRITE.

I believe you have found an erroneous error message, or, the new Natural version (what version are you on?) does something the older versions could not. There never used to be a WRITE GIVE SYSTEM FUNCTIONS, only a DISPLAY.

The reason is somewhat simple. In many respects DISPLAY is a “spreadsheet” statement, while WRITE is a “freeform” statement.

In an AT END OF PAGE clause, I might want to get “page-wise” statistics for a column(s) of a spreadsheet. It really does not make sense to get pagewise statistics for a variable that might appear anywhere in one or more WRITE statements. Hence, the restriction that only the DISPLAY has the GIVE SYSTEM FUNCTIONS option.

steve

I have for Windows 6.3.9
I understand, thanks.

So to create the best reports is WRITE or DISPLAY?

WRITE and DISPLAY are different for a reason, what’s “better” suited to solve a specific requirement depends.

A short list of things that DISPLAY can do, but not WRITE.

Logical tabbing (T*), and data “stacking” (P*)

Column headers and row headers

page wise statistics

The converse.

WRITE arrays is horizontal, not vertical (as with DISPLAY)

More flexible spacing

steve