The expression printing in ABAP means that the output from a report is sent to the
spool system. This does not necessarily mean that it is printed. You can also use the spool system to
save a list for a while. You can also write a list to the spool system exclusively for subsequent optical archiving.
In ABAP, there are two fundamentally different ways of printing a list:
This is the method you use when you execute a report and then print it by choosing System→List→Print.
This method has certain problems:
This method of printing lists would be better called a list dump. Practically its only use is to generate an extract from the screen list for test purposes.
The best way to print a list is to format it for printing right from the start. This works by printing each page and then deleting the page. Since the list never exists in its entirity, you can print large amounts, since the output is only limited by the capacity of the spool system. Because the printing works in this way, you cannot refer to a previous page while you are printing. You can print a list while it is being created as follows:
When you start printing, you need to set the print parameters. You do this using the ABAP Dictionary structure PRI_PARAMS.
As well as the print parameters, there are archiving parameters. You only have to specify these if you have optical archiving switched on (archiving mode 2 or 3). The structure of the archiving parameters is described in the ABAP Dictionary structure ARC_PARAMS.
You can only set the print and archiving parameters using the function module GET_PRINT_PARAMETERS. If you set the parameters directly, the system triggers a runtime error when you next use the parameterse. The function module GET_PRINT_PARAMETERS allows you to do the following:
While printing is active, you can use the PRINT-CONTROL statement to write the list information to the spool system. This is mostly control statements for the output devices (printer) or administration information for optical archiving.
The SET MARGIN x y statement allows you to set the upper and left-hand margins on a print page. The statement sets the system fields SY-MAROW and SY-MACOL, which set the number of lines at the top margin and the number of columns at the left-hand margin.
* Uusual call of NEW-PAGE PRINT ON
DATA: PARAMS LIKE PRI_PARAMS,
VALID TYPE
C.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
IMPORTING OUT_PARAMETERS = PARAMS
VALID =
VALID.
IF VALID <> SPACE.
NEW-PAGE PRINT ON PARAMETERS PARAMS NO-DIALOG.
WRITE / ...
NEW-PAGE PRINT OFF.
ENDIF.
* NEW-PAGE PRINT ON with optical archiving
DATA: PRI_PARAMS LIKE PRI_PARAMS,
ARC_PARAMS
LIKE ARC_PARAMS,
VALID TYPE
C.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
IMPORTING OUT_PARAMETERS
= PRI_PARAMS
OUT_ARCHIVE_PARAMETERS
= ARC_PARAMS
VALID
= VALID.
IF VALID <> SPACE.
NEW-PAGE PRINT ON PARAMETERS
PRI_PARAMS
ARCHIVE
PARAMETERS ARC_PARAMS NO-DIALOG.
PRINT-CONTROL INDEX-LINE ' '.
"Write administration information
WRITE / ....
NEW-PAGE PRINT OFF.
ENDIF.
* SUBMIT ... TO SAP-SPOOL
DATA: PARAMS LIKE PRI_PARAMS,
VALID TYPE
C.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
IMPORTING OUT_PARAMETERS = PARAMS
VALID =
VALID.
IF VALID <> SPACE.
SUBMIT MYREPORT TO SAP-SPOOL WITHOUT SPOOL DYNPRO
SPOOL PARAMETERS PARAMS.
ENDIF.
* Einplanen eines Hintergrund-Jobs
DATA: PARAMS LIKE PRI_PARAMS,
VALID TYPE
C.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING MODE =
'BATCH'
REPORT =
'MYREPORT'
IMPORTING OUT_PARAMETERS =
PARAMS
VALID
= VALID.
IF VALID <> SPACE.
CALL FUNCTION 'JOB_OPEN' .... EXPORTING
JOBCOUNT ...
SUBMIT MYREPORT VIA JOB 'MY_JOB' NUMBER JOBCOUNT
TO SAP-SPOOL WITHOUT SPOOL DYNPRO
SPOOL PARAMETERS PARAMS.
CALL FUNCTION 'JOB_CLOSE' ...
ENDIF.