This example shows how an application program calls and uses an externally described printer file to control how your printed output will look.
This example consists of:
This is the RPG-coded application program. The numbers within the program correspond to the list on the following pages. That list explains how this program works and specifically how the program opens and uses the printer file.
Note: Read the Code disclaimer information for important legal information.
************************************************************************ FADDRESS IF E K DISK (1) FLABELPR3O E PRINTER ************************************************************************ CTAR 20 1 CSAR 30 1 STAR 2 1 ZPAR 8 1 READ ADDRESS 10 ************************************************************************ WRITEHEADNG *IN10 DOWEQ'0' EXSR CKCITY (2) WRITEDETAIL1 ADD2 IFNE *BLANKS WRITEDETAIL3 END WRITEDETAIL4 READ ADDRESS 10 END ************************************************************************ ************************************************************************ (3) MOVE '1' *INLR ************************************************************************ CKCITY BEGSR MOVEA*BLANKS CTAR MOVEA*BLANKS STAR MOVEA*BLANKS ZPAR MOVEA*BLANKS CSAR MOVEACITY CTAR MOVEAST STAR MOVEAZIP ZPAR Z-ADD1 X 20 Z-ADD1 Y 20 EXSR LOOKBL 1ST WORD
ADD 1 X
CTAR,X IFGT *BLANKS 2ND WORD
MOVE ' ' CSAR,Y
ADD 1 Y
EXSR LOOKBL
ADD 1 X
CTAR,X IFGT *BLANKS 3RD WORD
MOVE ' ' CSAR,Y
ADD 1 Y
(4) EXSR LOOKBL
END
END
MOVE ',' CSAR,Y
ADD 1 Y
MOVE ' ' CSAR,Y
ADD 1 Y
MOVE STAR,1 CSAR,Y
ADD 1 Y
MOVE STAR,2 CSAR,Y
ADD 1 Y
MOVE ' ' CSAR,Y
ADD 1 Y
MOVE ' ' CSAR,Y
ADD 1 Y
Z-ADD1 X
X DOWLT9
MOVE ZPAR,X CSAR,Y
ADD 1 Y
ADD 1 X
END
MOVEACSAR CTSTZP 30
MOVEACSAR CTSTZ2 30
ENDSR
LOOKBL BEGSR
CTAR,X DOWGT*BLANKS
MOVE CTAR,X CSAR,Y
ADD 1 X
ADD 1 Y
END
ENDSR
******************************************************************
Open processing
Part (1) of the application program opens files that are called by the application program. Among those, and of particular interest at this point, is the printer file whose name is LABELPR3. You can locate LABELPR3 next to (1) in the program listing.A printer file is opened to prepare the system so that the application can put data into a spooled file or print it out directly to a printer. Information from the high-level language application program, the printer file, and any printer file overrides is combined.
The printer file open operation is controlled by parameters specified in the printer file, in the high-level language program, and in printer file overrides (through the OVRPRTF command). See Printer file overrides for more information on overrides.
As an example, if the printer file specified lines per inch (LPI) of 8, and an Override with Printer File (OVRPRTF) command specified an LPI of 6, the LPI of 6 would be used since the override value specified by the OVRPRTF command takes precedence over the LPI value specified in the printer file.
The following list contains parameters from the printer file LABELPRT. These are the parameters that the application program accesses or looks at when it opens the printer file. They are the majority of the parameters in the printer file, but not all of them. When the application looks at each parameter, it finds a value specified for each parameter. For a description of each parameter, see the Create Printer File (CRTPRTF) CL command.
FILE DEV DEVTYPE CVTLINDTA PAGESIZE LPI UOM CPI OVRFLW RPLUNPRT FIDELITY CTLCHAR PRTQLTY FORMFEED DRAWER OUTBIN FONT CHRID DECFMT FNTCHRSET CDEFNT PAGDFN FORMDF AFPCHARS TBLREFCHR PAGRTT PRTTXT JUSTIFY DUPLEX IPDSPASTHR USRRSCLIBL CORNERSTPL EDGESTITCH SADLSTITCH FNTRSL SPOOL SCHEDULE USRDTA SPLFOWN USRDFNOPT USRDFNDTA USRDFNOBJ IGCDTA IGCEXNCR IGCCHRTT IGCCPI IGCSOSI IGCCDEFNT WAITFILE SHARE LVLCHK AUT TEXT
Output processing
Part (2) of the application program performs the operations of reading, compiling, and sending the output to the output queue specified in the OUTQ parameter of the CRTPRTF command, or to the printer specified in the DEV parameter of the CRTPRTF command. In this example, the SPOOL parameter has a value of (*YES), which means the output will become a spooled file in the designated output queue.The following printer file parameters from the CRTPRTF command are parameters that are looked at by the application program during the output processing. The DDS is compiled before the application program runs. The application program never looks at the DDS file and member, only at the compiled results.
Since this example uses DDS, look at (1) in the program listing and see that the name of the printer file is LABELPR3. LABELPR3 was compiled using the source from the member and file that are listed here.
SRCFILE SRCMBR FOLD ALIGN CHLVAL PRTTXT REDUCE MULTIUP FRONTMGN BACKMGN FRONTOVL BACKOVL MAXRCDS DFRWRT OPTION GENLVL
Data description specifications
Below is the example of the compiled DDS used by the RPG program. You can update the DDS; however, you must then recompile it.000100900115 R HEADNG 000200900115 3 2'MAILING LABELS' 000300900115 000400900115 R DETAIL1 000500900115 NAME 25 2 2UNDERLINE 000600900115 ADD1 25 3 2 000700900115 R DETAIL3 000800900115 ADD2 25 2SPACEB(1) 000900900115 R DETAIL4 001000900115 CTSTZP 30 2HIGHLIGHT SPACEB(1)This example uses three DDS keywords: SPACEB, UNDERLINE, and HIGHLIGHT.
DDS and its associated keywords can only be used if the SRCFILE parameter contains the name of the file and the SRCMBR parameter contains the name of the member that the DDS source resides in.
For a description of DDS keywords for printer files and more detailed information on DDS source files, see DDS Reference: Printer files in the Programming category.
Close processing
Part (3) of the application program performs the close operations of the application program.When the application program has finished the output processing part of the application program, it performs a close operation on all the files it opened during the open processing of the application program.
The application program looks at the SCHEDULE parameter from the CRTPRTF command during the close portion of the application program.
Output from the example
Ann White Box 123 RR 1 Anytown, IA 12345 Tom Smith 123 Main St. Somewhere, IN 54321