Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  User Dialogs →  Classic Lists →  printing lists 

Lists, Printing

The example demonstrates how to print lists and how to stack print list levels.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_list_print LINE-COUNT 10 LINE-SIZE 50.

DATA params LIKE pri_params.
DATA valid  TYPE c LENGTH 1.

PARAMETERS para TYPE c LENGTH 1.

CLASS print_demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS print IMPORTING text TYPE string.
ENDCLASS.

INITIALIZATION.

  CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
      destination    = 'LOCL'
      immediately    = ' '
      no_dialog      = 'X'
      line_count     = 10
      line_size      = 50
    IMPORTING
      out_parameters = params
      valid          = valid.

  IF valid <> 'X'.
    LEAVE PROGRAM.
  ENDIF.

  params-prtxt = 'Parameter 1'.
  CALL FUNCTION 'SET_PRINT_PARAMETERS'
    EXPORTING
      in_parameters = params.

START-OF-SELECTION.

  WRITE / 'AAAA'.

  params-prtxt = 'Parameter 2'.
  NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.

  WRITE / 'BBBB'.

  CALL SCREEN 100.

  WRITE / 'GGGG'.

  NEW-PAGE PRINT OFF.

  WRITE / 'HHHH'.

MODULE status_0100 OUTPUT.

  SUPPRESS DIALOG.
  LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.

  WRITE / 'CCCC'.

  params-prtxt = 'Parameter 3'.
  NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.
  WRITE / 'DDDD'.
  print_demo=>print( 'EEEE' ).
  NEW-PAGE PRINT OFF.

  WRITE / 'FFFF'.

ENDMODULE.

CLASS print_demo IMPLEMENTATION.
  METHOD print.

    params-prtxt = 'Parameter 4'.
    TRY.
        NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.
      CATCH cx_sy_nested_print_on.
        NEW-PAGE PRINT ON PARAMETERS params NO DIALOG NEW-SECTION.
    ENDTRY.
    WRITE / text.
    NEW-PAGE PRINT OFF.

  ENDMETHOD.
ENDCLASS.

Description

The program creates five lists. If the user chooses Execute on the selection screen, one screen list and four print lists are created. If the user chooses Execute + Print on the selection screen, five print lists are created.

In the event block INITIALIZATION, by calling function module GET_PRINT_PARAMETERS, the print parameters are placed into the structure params. By passing the initial value to parameter IMMEDIATELY, the spool requests are stored in the spool system, but not printed immediately. Function module SET_PRINT_PARAMETERS is used to pre-fill the input fields of the print dialog window of the selection screen.

The spool reqeusts created and the content of the print lists can be displayed by choosing System → Own Spool Requests.

  • Depending on the user action, the first list on the selection screen is either a two-page screen list (basic list) or a two-page print list with the title "Parameter 1". The first page contains a line "AAAA". The second page contains a line "HHHH".
  • The second list is a one-page print list explicitly created with NEW-PAGE PRINT ON and carries the title "Parameter 2". It contains the lines "BBBB" and "GGGG". Its print list level is stacked upon the screen list or upon the print list level with the title "Parameter 1".
  • The third list is a two-page print list explicitly created by the call of a screen sequence with CALL SCREEN and carries the title "Parameter 2". The first page contains a line "CCCC". The second page contains a line "FFFF". Its print list level is stacked upon the print list level of the previous print list with the title "Parameter 2", from which the print parameters are also taken.
  • The fifth list is a one-page print list explicitly created with NEW-PAGE PRINT ON carrying the title "Parameter 3". It contains the line "DDDD". Its print list level is stacked upon the print list level of the previous list with the title "Parameter 3".
  • The fifth list is a one-page print list explicitly created with NEW-PAGE PRINT ON carrying the title "Parameter 4". It contains the line "EEEE". Its print list level is stacked upon the print list level of the previous list with the title "Parameter 3".

The fifth list is created in the static method print of class print_demo. The first attempt to create a new print list with the title "Parameter 4" raises the exception CX_SY_NESTED_PRINT_ON, because the print list created with NEW-PAGE PRINT ON and carrying the title "Parameter 3" is still open. When the exception is handled, a new print list is opened using the addition NEW SECTION. Since the used print parameters differ, the opened print list is closed and a new print list is opened, no longer raising an exception. If identical print parameters are used, the output is appended to the existing print list. Because the print list opened using NEW-PAGE PRINT ON is closed already in the method, the statement NEW-PAGE PRINT OFF in the dialog module status_0100 no longer has an effect.