Informix Error -4309: Printing cannot be done within a loop or CASE statement contained in report headers or trailers.
Cause and resolution
Printing cannot be done within a loop or CASE statement contained in report headers or trailers.
4GL needs to know how many lines of space will be devoted to page headers and trailers; otherwise, it does not know how many detail rows to allow on a page. Since it cannot predict how many times a loop will be executed, or which branch of a CASE will be execute, it forbids the use of PRINT in these contexts within FIRST PAGE HEADER, PAGE HEADER, and PAGE TRAILER sections. You have to rearrange the code to place the PRINT statement where it will always be executed.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-4309 fires when PRINT appears inside a loop or CASE statement within a FIRST PAGE HEADER, PAGE HEADER, or PAGE TRAILER section — per the official guidance, 4GL needs to
know in advance exactly how many lines headers/trailers occupy, and it can't predict how many
times a loop executes or which CASE branch runs.
- A
PRINTstatement inside a loop orCASEstatement within a header/trailer section, per the official guidance — the direct, only cause.
Solutions / Resolution
- Rearrange the code so
PRINTis placed where it will always execute, per the official guidance, outside any loop orCASEbranch within the header/trailer.
Examples
PRINT inside a loop in a page header
FIRST PAGE HEADER
FOR i = 1 TO 3
PRINT COLUMN 1, "Header line ", i
-- -4309: loop count isn't statically known
END FOR
Corrected
FIRST PAGE HEADER
PRINT COLUMN 1, "Header line 1"
PRINT COLUMN 1, "Header line 2"
PRINT COLUMN 1, "Header line 3"
Diagnostic Checks
- Check every
PRINTstatement inside a header/trailer section, and confirm it isn't inside a loop orCASEbranch.
Related Errors / Related Topics
- -4310 — "Files cannot be printed within report headers or trailers." A related
header/trailer restriction, about
PRINT FILEspecifically rather than loops/CASE. - -4313 — "The NEED statement cannot be used within report headers or trailers." A
related header/trailer restriction, about
NEEDrather thanPRINT.
PRINT appears inside a loop or CASE branch within a header/trailer section — move it
outside so it always executes.