Well, in my opinion you lack much more than writing into a spooled file!
:-))
On as400 (aka iSeries or system i) for any language, writing into a
spooled file is matter to write a device file of type printer, in other
words an object of type *FILE with PRTF object attribute, called
printer-file.
As any other file, in RPG language you have to declare the file
specifying printer instead of disk (that's foer db tables) or display
(that's for io on screen) or special (tha's for anyinput/output device
of your choice).
A printer-file can be described by DDS (with records and fields) or not
described at all. Anyway, a printerfile hosts all attributes that make
what in other terms are called printer-capabilities (font, lines per
inch, characters per inch, and so on.
When in an RPG program you declare a file thats dds described, you can
use write operation code speciying also the record you want to use for
output, then compiling the program, the compiler will add add fields and
record definitions to the program, you can use them such as any other
variable explicitly defined.
If the printer-file is not dds described, you can still use write
operation code speciying ony the file name, as this kind of printer-file
has no records. Or you can use O specification using EXCPT operation code.
When the program close the printer-file, explicitly with close operation
code, or implicitly returning with LR indicator on, the generated spool
change its status from OPN to RDY or HLD (if the printer-file has
HOLD(*YES) attribute set) or FIN (that means that the program didn't
made any output operation). The satust of FIN is set also when the
spooled file has been printed and no SAVE(*YES) attribute was not set in
the printer-file.
Further more, printing on as400 is a new world, that must be explored
step by step.