of course, steps below are just my first attempt to use OO way to display a alv report. so i think it is not the only way.
Step1: Define a screen with a custom control in the program.Give the custom control a name.The custom control will for display alv report later.
Step2:Define two reference variables,container_r and grid_r , which refer to Class CL_GUI_CUSTOM_CONTAINER and CL_GUI_ALV_GRID. Then create this two variables as below: CREATE OBJECT container_r EXPORTING container_name = im_con_name. CREATE OBJECT grid_r EXPORTING i_parent = container_r.Hint: This two class's objects should be instanced in PBO.
Step3:Get data you want to display in the alv report.Strictly speak,you can take this step whenever before you call method to output the alv report.
Step4:Create alv field catalog.ABAP Object provide different field catalog type with OP programing way.In ABAP Object , LVC_T_FCAT is the field catalog type.But as OP way's SLIS_T_FIELDCAT_ALV are internal table.
I think it is the basic step to use ABAP Object to display ALV report.Of course there are lot of other parameters for alv report,you can use them if you need.
Below is a simple class that can display a simple alv report. I will modify and add new to them in the future.
*----------------------------------------------------------------------** CLASS lcl_alv DEFINITION*----------------------------------------------------------------------***----------------------------------------------------------------------*CLASS lcl_alv DEFINITION. PUBLIC SECTION. METHODS constructor IMPORTING im_con_name TYPE SCRFNAME. METHODS create_fieldcat IMPORTING im_fieldcat TYPE LVC_T_FCAT. METHODS create_layout IMPORTING im_layout TYPE LVC_S_LAYO. METHODS display_alv CHANGING im_any_table TYPE ANY TABLE. PRIVATE SECTION. DATA: container_r TYPE REF TO CL_GUI_CUSTOM_CONTAINER. DATA: grid_r TYPE REF TO CL_GUI_ALV_GRID. DATA: wa_fieldcatalog TYPE LVC_S_FCAT. DATA: it_fieldcatalog TYPE LVC_T_FCAT. DATA: is_layout TYPE LVC_S_LAYO.ENDCLASS. "lcl_alv DEFINITION
*----------------------------------------
------------------------------** CLASS lcl_alv IMPLEMENTATION*----------------------------------------------------------------------***----------------------------------------------------------------------*CLASS lcl_alv IMPLEMENTATION.** & & & METHOD constructor. IF STRLEN( im_con_name ) NE 0. CREATE OBJECT container_r EXPORTING container_name = im_con_name. CREATE OBJECT grid_r EXPORTING i_parent = container_r. ELSE. MESSAGE 'Container name must not null' TYPE 'E'. ENDIF. ENDMETHOD. "constructor** % % %** & & & METHOD create_fieldcat. IF im_fieldcat[] IS NOT INITIAL. LOOP AT im_fieldcat INTO wa_fieldcatalog. APPEND wa_fieldcatalog TO it_fieldcatalog. ENDLOOP. ENDIF. ENDMETHOD. "create_fieldcat** % % %** & & & METHOD create_layout. MOVE-CORRESPONDING im_layout TO is_layout. ENDMETHOD. "create_layout** % % %** & & & METHOD display_alv. CALL METHOD grid_r->set_table_for_first_display EXPORTING IS_LAYOUT = is_layout CHANGING IT_FIELDCATALOG = it_fieldcatalog IT_OUTTAB = im_any_table. ENDMETHOD. "display_alv** % % %ENDCLASS. "lcl_alv IMPLEMENTATION