SAP Help SOurce code to demostrate how to write ABAP report staight to printer









Write report straight to printer

The code below demonstrates how send a report created using the write statement straight to the printer, via the print dialog box. Alternative method for doing this would be to use sapscript.

face="Arial monospaced for SAP">*
*Print parameter declarations
DATA: val(1) TYPE c,
      pripar TYPE pri_params,
      arcpar TYPE arc_params,
      lay   TYPE pri_params-paart,
      lines TYPE pri_params-linct,
      rows  TYPE pri_params-linsz.


  lay = 'X_65_255'.
  lines = 255.
  rows  = 65.

CALL FUNCTION 'GET_PRINT_PARAMETERS'
       EXPORTING
            in_archive_parameters  = arcpar
            in_parameters          = pripar
            layout                 = lay
*            line_count             = lines
*            line_size              = rows
*            no_dialog              = 'X'
       IMPORTING
            out_archive_parameters = arcpar
            out_parameters         = pripar
            valid                  = val
       EXCEPTIONS
            archive_info_not_found = 1
            invalid_print_params   = 2
            invalid_archive_params = 3
            OTHERS                 = 4.

check val EQ 'X'.
NEW-PAGE PRINT ON
    NEW-SECTION
    PARAMETERS pripar
    ARCHIVE PARAMETERS arcpar
    NO DIALOG.


Write:/ 'Hello'.

NEW-PAGE PRINT OFF.

face="Arial monospaced for SAP">*Write to printer
  DATA: ld_params LIKE pri_params,
        ld_valid  TYPE c,
        ld_lay   TYPE pri_params-paart,

* Example of seting default layout
  ld_lay = 'X_65_255'.

  CALL FUNCTION 'GET_PRINT_PARAMETERS'
      EXPORTING
*         ARCHIVE_ID             = C_CHAR_UNKNOWN
*         ARCHIVE_INFO           = C_CHAR_UNKNOWN
*         ARCHIVE_MODE           = C_CHAR_UNKNOWN
*         ARCHIVE_TEXT           = C_CHAR_UNKNOWN
*         AR_OBJECT              = C_CHAR_UNKNOWN
*         ARCHIVE_REPORT         = C_CHAR_UNKNOWN
*         AUTHORITY              = C_CHAR_UNKNOWN
*         COPIES                 = C_NUM3_UNKNOWN
*         COVER_PAGE             = C_CHAR_UNKNOWN
*         DATA_SET               = C_CHAR_UNKNOWN
*         DEPARTMENT             = C_CHAR_UNKNOWN
*         DESTINATION            = C_CHAR_UNKNOWN
*         EXPIRATION             =
            immediately            = 'X'
*         IN_ARCHIVE_PARAMETERS  = ' '
*         IN_PARAMETERS          = ' '
            LAYOUT                 = ld_layout            "'X_PAPER'
*         LINE_COUNT             = C_INT_UNKNOWN
*         LINE_SIZE              = C_INT_UNKNOWN
            LIST_NAME              = 'TEST'
            LIST_TEXT              = 'Test page'
*         MODE                   = ' '
            NEW_LIST_ID            = 'X'
            no_dialog              = ' '
*         RECEIVER               = C_CHAR_UNKNOWN
           release                = 'X'
*         REPORT                 = C_CHAR_UNKNOWN
*          SAP_COVER_PAGE         = 'X'
*         HOST_COVER_PAGE        = C_CHAR_UNKNOWN
*         PRIORITY               = C_NUM1_UNKNOWN
*         SAP_OBJECT             = C_CHAR_UNKNOWN
*         TYPE                   = C_CHAR_UNKNOWN
*         USER                   = SY-UNAME
      IMPORTING
*         OUT_ARCHIVE_PARAMETERS =
           out_parameters         = ld_params
           valid                  = ld_valid
      EXCEPTIONS
           archive_info_not_found = 1
           invalid_print_params   = 2
           invalid_archive_params = 3
           OTHERS                 = 4
            .
  IF sy-subrc EQ 0.
    IF ld_valid <> space.
      new-page print on parameters ld_params NO dialog.
      write: 'This text will be printed on page'.
      write: 'This text will be printed on page'.

*     Stop spool report appearing, maybe option to remove this
      leave to screen 0.
    ENDIF.

  ENDIF.