We can display data by factory method which displays like ALV grid. Example is below.
REPORT yft_factory_method.
DATA: v_ersda TYPE ersda.
INITIALIZATION.
SELECT-OPTIONS s_ersda FOR v_ersda.
*----------------------------------------------------------------------*
* CLASS cl_fact DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_fact DEFINITION.
PUBLIC SECTION.
DATA: it_mara TYPE TABLE OF mara.
METHODS: m_fact.
PRIVATE SECTION.
DATA: ob_salv TYPE REF TO cl_salv_table,
ob_disp TYPE REF TO cl_salv_display_settings,
ob_col TYPE REF TO cl_salv_columns_table,
ob_colm TYPE REF TO cl_salv_column,
ob_func TYPE REF TO cl_salv_functions_list,
ob_lay TYPE REF TO cl_salv_layout,
lv_key TYPE salv_s_layout_key.
ENDCLASS. "cl_fact DEFINITION
*----------------------------------------------------------------------*
* CLASS cl_fact IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_fact IMPLEMENTATION.
METHOD m_fact.
SELECT * FROM mara INTO TABLE it_mara
WHERE ersda IN s_ersda
AND mtart EQ 'ZPCB'.
IF sy-subrc = 0.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = abap_false
IMPORTING
r_salv_table = ob_salv
CHANGING
t_table = it_mara.
*-ALV Functions
ob_func = ob_salv->get_functions( ).
ob_func->set_all( ).
*-Zebra Lines
ob_disp = ob_salv->get_display_settings( ).
ob_disp->set_striped_pattern( abap_true ).
*-Column Optimizing
ob_col = ob_salv->get_columns( ).
ob_col->set_optimize( ).
*-ALV Header
ob_disp->set_list_header( 'ALV Display with Factory Method' ).
*-Disable fields
ob_colm = ob_col->get_column( 'ZEINR' ).
ob_colm->set_visible( abap_false ).
ob_colm = ob_col->get_column( 'ZEIAR' ).
ob_colm->set_visible( abap_false ).
ob_colm = ob_col->get_column( 'ZEIVR' ).
ob_colm->set_visible( abap_false ).
ob_colm = ob_col->get_column( 'ZEIFO' ).
ob_colm->set_visible( abap_false ).
*-Layout Save
lv_key-report = sy-repid.
ob_lay = ob_salv->get_layout( ).
ob_lay->set_key( lv_key ).
ob_lay->set_save_restriction( cl_salv_layout=>restrict_none ).
*-Grid Display
ob_salv->display( ).
FREE: ob_salv.
ENDIF.
ENDMETHOD. "m_fact
ENDCLASS. "cl_fact IMPLEMENTATION
START-OF-SELECTION.
DATA: ob_fact TYPE REF TO cl_fact.
CREATE OBJECT: ob_fact.
CALL METHOD: ob_fact->m_fact.
No comments:
Post a Comment