Created On:  28 March 2011

Problem:

Displaying a data item that contains the form feed character x'0c' causes the screen to be cleared. How does one prevent this character from clearing the screen?

In the following example, 'Hello world!" will be displayed first, and the screen will be cleared upon displaying the form feed character on the next line. The program will stop with the 'Hello world again!' line only on screen.

000070 WORKING-STORAGE SECTION.
    77 Form-Feed-Char PIC X VALUE X'0C'.
000109
000110 PROCEDURE DIVISION.
        DISPLAY 'Hello world!'
        DISPLAY Form-Feed-Char
        DISPLAY 'Hello world again!'
        GOBACK.

Resolution:

Here are two alternatives to prevent the form feed character from clearing the screen:

a) Always build the program as an executable - this means all console I/O is done via stdout (where the control character gets displayed as a graphic character)

-or-
 
b) To execute as INT or GNT, ensure the program explicitly re-enables the default stdout behavior by using X"A7" function 18.
 
e.g.
000070 WORKING-STORAGE SECTION.
    77 Form-Feed-Char PIC X        VALUE X'0C'.
    01 Fn-Code        PIC X COMP-X VALUE 18.
    01 Fn-Parm        PIC X COMP-X VALUE 1.
000109
000110 PROCEDURE DIVISION.
        CALL X"A7" USING Fn-Code Fn-Parm
        DISPLAY 'Hello world!'
        DISPLAY Form-Feed-Char
        DISPLAY 'Hello world again!'
        GOBACK.
    
The above program will stop with three lines displayed on the screen:
Hello world!
♀
Hello world again!
Incident #2431082