代码语言:javascript复制
*----------------------------------------------------------------------*
* Local class for report
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
PUBLIC SECTION.
*
DATA: t_data TYPE STANDARD TABLE OF sflight, " Output data
r_carrid TYPE RANGE OF sflight-carrid. " Select Option
*
METHODS:
get_data,
write_list,
generate_alv.
*
ENDCLASS. "lcl_report DEFINITION
*
DATA: o_report TYPE REF TO lcl_report.
*
DATA: v_carrid TYPE sflight-carrid.
*
** Selection Screen
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE aaa.
SELECT-OPTIONS: s_carrid FOR v_carrid.
SELECTION-SCREEN: END OF BLOCK blk1.
*
** Initialization
INITIALIZATION.
aaa = 'Selection Criteria'.
*
** Start of Selection
START-OF-SELECTION.
* object for the report
CREATE OBJECT o_report.
* Get data
o_report->r_carrid = s_carrid[].
o_report->get_data( ).
* generate output
o_report->write_list( ).
o_report->generate_alv( ).
*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
METHOD get_data.
* data selection
SELECT * FROM sflight
INTO TABLE me->t_data
WHERE carrid IN s_carrid.
ENDMETHOD. "get_data
*
METHOD write_list.
WRITE: / 'This list is generated using the Good Old fashioned WRITE'.
WRITE: / ' --- Total number of records', LINES( t_data ).
ENDMETHOD.
*
METHOD generate_alv.
* local data
DATA: lo_dock TYPE REF TO cl_gui_docking_container,
lo_cont TYPE REF TO cl_gui_container,
lo_alv TYPE REF TO cl_salv_table.
DATA: lv_repid TYPE sy-repid,
lv_dynnr TYPE sy-dynnr.
lv_repid = 'SAPMSSY0'.
lv_dynnr = '0120'.
*
* Create a docking control at bottom
CHECK lo_dock IS INITIAL.
CREATE OBJECT lo_dock
EXPORTING
repid = lv_repid
dynnr = lv_dynnr
ratio = 80
side = cl_gui_docking_container=>dock_at_bottom
NAME = 'DOCK_CONT'.
IF sy-subrc <> 0.
MESSAGE 'Error in the Docking control' TYPE 'S'.
ENDIF.
*
* Create a SALV for output
CHECK lo_alv IS INITIAL.
TRY.
* Narrow Casting: To initialize custom container from
* docking container
lo_cont ?= lo_dock.
*
* SALV Table Display on the Docking container
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = if_salv_c_bool_sap=>false
r_container = lo_cont
container_name = 'DOCK_CONT'
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = me->t_data.
CATCH cx_salv_msg .
ENDTRY.
*
* Pf status
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
lo_functions = lo_alv->get_functions( ).
lo_functions->set_default( abap_true ).
*
* output display
lo_alv->display( ).
*
ENDMETHOD. "generate_ALV
*
ENDCLASS. "lcl_report IMPLEMENTATION