Fetch Overflow is one of those somewhat obscure programming constructs that a “modern” programming language lover would likely scorn or ignore, but it epitomizes what makes a programming language like RPG special.
Fetch Overflow requires Output specifications, which are being used less and less, and it requires the use of an overflow INDICATOR (aaaaaggghhh! See the Java programmer running away into the bushes.) Some RPG programmers may not even know how to use it; more’s the pity.
For those applications that continue to generate reports on real paper, the problem of handling end-of-page conditions, including when to print headings, has always been an issue. RPG’s use of the overflow indicator (which may be OA-OG or OV - OVerflow, get it?) has always been to me a very elegant way to generate proper report appearance. You can condition lines of print on the indicator, if you use O specs. The system default for printing is a 66 line page, with overflow at line 60; but this can be adjusted to suit the needs of the application. Even with an externally defined print file, you can define a numeric overflow indicator and print lines and do jumps to new pages at page overflow.
There is a column (I believe it is 15 on the standard RPG specification,something different on the RPG IV O spec), where you tell whether it is (D)etail, (H)eading, (T)otal, or (E)xception time output. The next space to the right is where you can put an F, for Fetch Overflow. When this occurs, the programmer is assuming that there will also be some other lines conditioned on the overflow indicator, usually specifications that tell the program to advance to the top of the next page and print defined headings, often several lines of them. If the printing on the page has reached up to or past the overflow line (let’s say line 60), and that line meets the requirements for being printed, the program will print all the lines conditioned on the overflow indicator (let’s say OF), then print the line that fetched the headings, then set off OF.
In the past, often the OF indicator would be used in conjunction with the 1P (first page) indicator. But there is available an even slicker way of handling the headings. Use an *INZSR subroutine, which is automatically executed before any files are read. In that subroutine, insert SETON OF or EVAL *INOF=*ON.
Now, what happens when the first detail line is read with the Fetch Overflow flag? It notices that OF is on, so it proceeds to print the heading lines you have conveniently conditioned on OF. OF is then turned off. The next time a real page overflow occurs when that Fetch Overflow Detail (or Except, or Total) line shows up, the headings are printed again.
What is beautiful about this process is that it is almost invisible. There are no calculations telling the program to print headings. Except for that *INZSR line of code, there are no lines of code that set on the OF indicator. The indicator is (except at the start) controlled entirely by the system. No calculating of total lines printed on the page. If there is some chance of there not being any detail lines to print, yet you still want headings, you can generate at the end an Except line with Fetch overflow that says “No records read” - or even a blank line. In either case, it will detect the OF you set on and print the headings before printing the line of desired detail output.
I have not noticed any feature like this in any other general-purpose programming language - but then RPG is NOT a general-purpose programming language. As I have said in earlier posts, it is designed to push data around, update files and print reports. Input, process, output.
Quite frankly, I think Fetch Overflow is the kind of feature that writers of RPG should be proud of. Very slick. More recent applications of the language have tended to shy away from emphasis on the report generation facility of RPG, but that should not detract from our recognition of the terse elegance and power of RPG.