Reports & Selection Screens

Keep event blocks thin and delegate to a local class:

17.1 Report events

Rarely used initialization Before the selection screen is shown Default values (e.g. dates) AT SELECTION-SCREEN OUTPUT PBO of the selection screen Hide/show/disable fields dynamically AT SELECTION-SCREEN ON <field> Error messages for one field

AT SELECTION-SCREEN ON VALUE-REQUEST FOR <field> Custom value help

AT SELECTION-SCREEN ON HELP-REQUEST FOR <field> AT SELECTION-SCREEN PAI of the selection screen

Output (historically with logical databases) TOP-OF-PAGE / END-OF-PAGE Page header/footer in lists AT LINE-SELECTION / AT USER-COMMAND

17.2 PARAMETERS and SELECT-OPTIONS

SELECT-OPTIONS creates a ranges table (SIGN, OPTION, LOW, HIGH) used with IN.

Additions: OBLIGATORY, DEFAULT, NO-DISPLAY, LOWER CASE, MATCHCODE OBJECT, VALUE CHECK, MODIF ID, NO-EXTENSION, NO INTERVALS, AS LISTBOX VISIBLE LENGTH n.

Since 7.40 you can avoid TABLES by declaring a typed helper variable: DATA gv_fldate TYPE s_date. and SELECT-OPTIONS s_date FOR gv_fldate.

Selection texts (labels) are maintained in *Text Elements → Selection Texts*; tick "Dictionary ref." to reuse DDIC labels.

Variants save selection values (needed for background jobs).

REPORT zflight_report.

TABLES sflight.  " needed only for SELECT-OPTIONS FOR with a table work area (classic)

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
  PARAMETERS:     p_carr  TYPE s_carr_id OBLIGATORY DEFAULT 'LH',
                  p_max   TYPE i DEFAULT 100.
  SELECT-OPTIONS: s_date  FOR sflight-fldate,
                  s_conn  FOR sflight-connid NO INTERVALS.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
  PARAMETERS: p_alv  RADIOBUTTON GROUP out DEFAULT 'X' USER-COMMAND chg,
              p_list RADIOBUTTON GROUP out,
              p_test AS CHECKBOX DEFAULT 'X',
              p_file TYPE string LOWER CASE MODIF ID fil.
SELECTION-SCREEN END OF BLOCK b2.

17.3 Events in action

INITIALIZATION.
  s_date[] = VALUE #( ( sign = 'I' option = 'BT' low = sy-datum - 30 high = sy-datum ) ).

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF screen-group1 = 'FIL'.
      screen-active = COND #( WHEN p_list = abap_true THEN '1' ELSE '0' ).
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

AT SELECTION-SCREEN ON p_carr.
  SELECT SINGLE @abap_true FROM scarr WHERE carrid = @p_carr INTO @DATA(lv_ok).
  IF lv_ok <> abap_true.
    MESSAGE e001(zflight) WITH p_carr.   " stays on screen, field ready for input
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  DATA lt_files TYPE filetable.
  DATA lv_rc    TYPE i.
  cl_gui_frontend_services=>file_open_dialog( CHANGING file_table = lt_files rc = lv_rc ).
  IF lv_rc = 1.
    p_file = lt_files[ 1 ]-filename.
  ENDIF.

START-OF-SELECTION.
  SELECT * FROM sflight
    WHERE carrid = @p_carr AND fldate IN @s_date AND connid IN @s_conn
    INTO TABLE @DATA(gt_flights)
    UP TO @p_max ROWS.
  IF sy-subrc <> 0.
    MESSAGE 'No data found' TYPE 'S' DISPLAY LIKE 'E'.
    RETURN.
  ENDIF.
  " output with ALV or WRITE (§18)

17.4 Structuring a report the modern way

Keep event blocks thin and delegate to a local class:

CLASS lcl_report DEFINITION.
  PUBLIC SECTION.
    METHODS run.
  PRIVATE SECTION.
    DATA mt_flights TYPE STANDARD TABLE OF sflight WITH EMPTY KEY.
    METHODS select_data.
    METHODS display.
ENDCLASS.

CLASS lcl_report IMPLEMENTATION.
  METHOD run.
    select_data( ).
    display( ).
  ENDMETHOD.
  METHOD select_data.
    SELECT * FROM sflight WHERE carrid = @p_carr AND fldate IN @s_date
      INTO TABLE @mt_flights.
  ENDMETHOD.
  METHOD display.
    TRY.
        cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv) CHANGING t_table = mt_flights ).
        lo_alv->display( ).
      CATCH cx_salv_msg INTO DATA(lx).
        MESSAGE lx TYPE 'E'.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  NEW lcl_report( )->run( ).

17.5 Calling reports and transactions

Parameter IDs (SET PARAMETER ID 'AUN' FIELD lv_vbeln.) pre-fill fields on the called transaction's screen.

SUBMIT zflight_report WITH p_carr = 'AA' WITH s_date IN lr_dates AND RETURN.
SUBMIT zflight_report VIA SELECTION-SCREEN AND RETURN.
SUBMIT zflight_report EXPORTING LIST TO MEMORY AND RETURN.
CALL TRANSACTION 'VA03' WITH AUTHORITY-CHECK AND SKIP FIRST SCREEN.
LEAVE TO TRANSACTION 'SE38'.