• ABAP通过自定义类使用ALV(相应事件)的代码


    Class Definition

    *----------------------------------------------------------------------*
    *       CLASS lcl_alv DEFINITION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_alv DEFINITION.
      PUBLIC SECTION.

        METHODS select_alv IMPORTING amount TYPE i.

        METHODS display_alv.

        METHODS on_link_click
                    FOR EVENT link_click OF cl_salv_events_table
                    IMPORTING row column.

      PROTECTED SECTION.

        DATA t_alv TYPE STANDARD TABLE OF alv_tab.

        DATA: o_table   TYPE REF TO cl_salv_table,
              o_columns TYPE REF TO cl_salv_columns_table,
              o_column  TYPE REF TO cl_salv_column_table,
              o_events  TYPE REF TO cl_salv_events_table.

    ENDCLASS.                    "lcl_alv DEFINITION

    Class Implementation

    *----------------------------------------------------------------------*
    *       CLASS lcl_alv IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_alv IMPLEMENTATION.

      METHOD select_alv.

        SELECT *
          FROM alv_tab
          INTO TABLE t_alv
              UP TO amount ROWS.

      ENDMETHOD.                    "SELECT_ALV

      METHOD display_alv.

        TRY.
            cl_salv_table=>factory(
              IMPORTING
                r_salv_table = o_table
              CHANGING
                t_table      = t_alv ).
          CATCH cx_salv_msg.                                "#EC NO_HANDLER
        ENDTRY.

        o_columns = o_table->get_columns( ).
        o_columns->set_optimize( abap_true ).

        TRY.
            o_column ?= o_columns->get_column( 'CARRID' ).
            o_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
          CATCH cx_salv_not_found.
        ENDTRY.

        o_events = o_table->get_event( ).

        SET HANDLER me->on_link_click FOR o_events.

        o_table->display( ).

      ENDMETHOD.                    "display_alv

      METHOD on_link_click.

        DATA: l_row_string TYPE string,
              l_col_string TYPE string,
              l_row        TYPE char128.

        MESSAGE i000(0k) WITH 'You Clicked on Line'
                               row
                               'Of Column'
                               column.

      ENDMETHOD.                    "on_single_click
    ENDCLASS.                    "lcl_alv IMPLEMENTATION

    Defining Objects

    DATA o_alv TYPE REF TO lcl_alv.Instance Creation

    START-OF-SELECTION.

      CREATE OBJECT o_alv.

    Calling Methods

    o_alv->select_alv( 30 ).
    o_alv->display_alv( ).

  • 相关阅读:
    在C#中如何使用资源的方法
    C#调用windows API的一些方法
    Uml学习-类图简介
    Uml学习-用例建模简介
    sqlserver中DATE类型的数据转化 CONVERT
    mysql database和schema区别
    nginx buffer
    django pk 和id用法
    sed正则
    kong 插件开发分析
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157150.html
Copyright © 2020-2023  润新知