basic steps for using classes to display alv report

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值