You can write text to stdout with the DISPLAY statement. During execution the stdout of the program can be redirected into a file on the command line.
Another way to write to file with a 4GL program is to define a REPORT function and make calls in the program to it with every line of output. E.g.
REPORT tab_fld (result)
DEFINE result CHAR(603)
LEFT MARGIN 0
RIGHT MARGIN 0
TOP MARGIN 0
BOTTOM MARGIN 0
PAGE LENGTH 1
ON EVERY ROW
PRINT result CLIPPED
This report has to be invoked in the program with something like:
OUTPUT TO REPORT tab_fld (textstring)
And around the program part that contains the OUTPUT TO statements you have to call: