关闭

OO实现ALV(三)<转>

369人阅读 评论(0) 收藏 举报
分类:

一、ALV的弹出窗口形式

前面的例子ALV列表都是直接输出在主窗口中,下面我们实现在弹出窗口中实现ALV。在弹出窗口中实现ALV也很简单,只要在实现类CL_SALV_TABLE的一个方法SET_SCREEN_POPUP就可以了。

gr_table->set_screen_popup(

start_column = 1

end_column = 120

start_line = 1

end_line = 20 ).

方法SET_SCREEN_POPUP的是弹出窗口的显示范围。

下面是程序的所有代码:

REPORT y_xin_002.

*变量定义==============================================================

TYPES: BEGIN OF gs_spfli,

mandt TYPE spfli-mandt,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

countryfr TYPE spfli-countryfr,

cityfrom TYPE spfli-cityfrom,

airpfrom TYPE spfli-airpfrom,

countryto TYPE spfli-countryto,

cityto TYPE spfli-cityto,

airpto TYPE spfli-airpto,

fltime TYPE spfli-fltime,

deptime TYPE spfli-deptime,

arrtime TYPE spfli-arrtime,

distance TYPE spfli-distance,

distid TYPE spfli-distid,

fltype TYPE spfli-fltype,

period TYPE spfli-period,

END OF gs_spfli.

TYPES ty_spfli TYPE gs_spfli OCCURS 0.

DATA: gr_table TYPE REF TO cl_salv_table.

*设置屏幕=======================================================

SELECTION-SCREEN PUSHBUTTON 2(20) btn USER-COMMAND clk.

INITIALIZATION.

btn = '点击显示弹出alv窗口'.

*----------------------------------------------------------------------*

* CLASS lcl_alv DEFINITION

*----------------------------------------------------------------------*

* ALV操作类(定义)

*----------------------------------------------------------------------*

CLASS lcl_alv DEFINITION.

PUBLIC SECTION.

METHODS: getdata "取得要显示的数据

RETURNING value(lt_tab) TYPE ty_spfli,

alv_full "全屏Grid列表处理方法

IMPORTING value(lt_tab) TYPE ty_spfli,

main. "主方法

ENDCLASS. "lcl_alv DEFINITION

*----------------------------------------------------------------------*

* CLASS lcl_alv IMPLEMENTATION

*----------------------------------------------------------------------*

* ALV操作类(实现)

*----------------------------------------------------------------------*

CLASS lcl_alv IMPLEMENTATION.

*取得要显示的数据=======================================================

METHOD getdata.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_tab FROM spfli.

ENDMETHOD. "getdata

*输出全屏网格列表的方法================================================

METHOD alv_full.

DATA: lr_functions TYPE REF TO cl_salv_functions.

"创建实例

TRY.

cl_salv_table=>factory(

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = lt_tab).

CATCH cx_salv_msg.

ENDTRY.

"显示ALV的标准功能

lr_functions = gr_table->get_functions( ).

lr_functions->set_all( 'X' ).

"弹出窗口设置

gr_table->set_screen_popup(

start_column = 1

end_column = 120

start_line = 1

end_line = 20 ).

"显示列表

gr_table->display( ).

ENDMETHOD. "alv_full

*主方法,整合数据=======================================================

METHOD main.

DATA: lt_tab TYPE ty_spfli.

"取得要显示的数据

lt_tab = me->getdata( ).

me->alv_full( lt_tab ).

ENDMETHOD. "main

ENDCLASS. "lcl_alv IMPLEMENTATION

*执行按钮点击动作=======================================================

AT SELECTION-SCREEN.

CASE sy-ucomm.

WHEN 'CLK'.

DATA lr_alv TYPE REF TO lcl_alv.

CREATE OBJECT lr_alv.

lr_alv->main( ).

ENDCASE.

二、ALV的选择功能

在ALV的输出结果中,要对它的某一行、某一列或者某一单元格进行选定,我们通常的做法是把鼠标直接点击那一行或者是列就可以了,如果选择多行或多列,在选择的条件按住‘CTRL’键就可以了。这是手动选择的方法,但是在实际情况中,有时候需要用程序来对输出结果进行选择。

1.首先我们要取得类CL_SALV_SELECTIONS的实例。

DATA lr_selections TYPE REF TO cl_salv_selections.

lr_selections = gr_table->get_selections( ).

2. 设置选择模式。

lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

3. 选择行

DATA lt_row TYPE salv_t_row.

APPEND 3 TO lt_row.

APPEND 4 TO lt_row.

lr_selections->set_selected_rows( lt_row ).

4. 选择列

DATA lt_column TYPE salv_t_column.

APPEND 3 TO lt_row.

APPEND 4 TO lt_row.

lr_selections->set_selected_rows( lt_row ).

5. 选择一个单元格

DATA ls_cell TYPE salv_s_cell.

ls_cell-row = 7.

ls_cell-columnname = 'CITYFROM'.

lr_selections->set_current_cell( ls_cell )

6. 选择多个单元格

DATA lt_cell TYPE salv_t_cell,

ls_cell TYPE salv_s_cell.

ls_cell-row = 5.

ls_cell-columnname = 'CITYFROM'.

APPEND ls_cell TO lt_cell.

ls_cell-row = 6.

ls_cell-columnname = 'CITYFROM'.

APPEND ls_cell TO lt_cell.

lr_selections->set_selected_cells( lt_cell ).

下面是程序的所有代码:

REPORT y_xin_002.

*变量定义=======================================================

TYPES: BEGIN OF gs_spfli,

mandt TYPE spfli-mandt,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

countryfr TYPE spfli-countryfr,

cityfrom TYPE spfli-cityfrom,

airpfrom TYPE spfli-airpfrom,

countryto TYPE spfli-countryto,

cityto TYPE spfli-cityto,

airpto TYPE spfli-airpto,

fltime TYPE spfli-fltime,

deptime TYPE spfli-deptime,

arrtime TYPE spfli-arrtime,

distance TYPE spfli-distance,

distid TYPE spfli-distid,

fltype TYPE spfli-fltype,

period TYPE spfli-period,

END OF gs_spfli.

TYPES ty_spfli TYPE gs_spfli OCCURS 0.

DATA: gr_table TYPE REF TO cl_salv_table.

*----------------------------------------------------------------------*

* CLASS lcl_alv DEFINITION

*----------------------------------------------------------------------*

* ALV操作类(定义)

*----------------------------------------------------------------------*

CLASS lcl_alv DEFINITION.

PUBLIC SECTION.

METHODS: getdata "取得要显示的数据

RETURNING value(lt_tab) TYPE ty_spfli,

alv_full "全屏Grid列表处理方法

IMPORTING value(lt_tab) TYPE ty_spfli,

main. "主方法

ENDCLASS. "lcl_alv DEFINITION

*----------------------------------------------------------------------*

* CLASS lcl_alv IMPLEMENTATION

*----------------------------------------------------------------------*

* ALV操作类(实现)

*----------------------------------------------------------------------*

CLASS lcl_alv IMPLEMENTATION.

*取得要显示的数据=======================================================

METHOD getdata.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_tab FROM spfli.

ENDMETHOD. "getdata

*输出全屏网格列表的方法=================================================

METHOD alv_full.

DATA: lr_functions TYPE REF TO cl_salv_functions,

lr_selections TYPE REF TO cl_salv_selections,

lt_column TYPE salv_t_column,

lt_row TYPE salv_t_row,

lt_cell TYPE salv_t_cell,

ls_cell TYPE salv_s_cell.

"创建实例

TRY.

cl_salv_table=>factory(

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = lt_tab).

CATCH cx_salv_msg.

ENDTRY.

"显示ALV的标准功能

lr_functions = gr_table->get_functions( ).

lr_functions->set_all( 'X' ).

"取得类CL_SALV_SELECTIONS的实例

lr_selections = gr_table->get_selections( ).

"设置选择模式

lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

"选择列

APPEND 'FLTIME' TO lt_column.

APPEND 'DISTANCE' TO lt_column.

lr_selections->set_selected_columns( lt_column ).

"选择行

APPEND 3 TO lt_row.

APPEND 4 TO lt_row.

lr_selections->set_selected_rows( lt_row ).

* "选择多个单元格

* ls_cell-row = 5.

* ls_cell-columnname = 'CITYFROM'.

* APPEND ls_cell TO lt_cell.

* ls_cell-row = 6.

* ls_cell-columnname = 'CITYFROM'.

* APPEND ls_cell TO lt_cell.

* lr_selections->set_selected_cells( lt_cell ).

"选择一个单元格

ls_cell-row = 7.

ls_cell-columnname = 'CITYFROM'.

lr_selections->set_current_cell( ls_cell ).

"显示列表

gr_table->display( ).

ENDMETHOD. "alv_full

*主方法,整合数据=======================================================

METHOD main.

DATA: lt_tab TYPE ty_spfli.

"取得要显示的数据

lt_tab = me->getdata( ).

me->alv_full( lt_tab ).

ENDMETHOD. "main

ENDCLASS. "lcl_alv IMPLEMENTATION

*执行动作===============================================================

START-OF-SELECTION.

DATA lr_alv TYPE REF TO lcl_alv.

CREATE OBJECT lr_alv.

lr_alv->main( ).

三、ALV的布局功能

在ALV的输出结果中,我们可以利用ALV提供的标准功能(过滤,排序,汇总)对输出结果正行操作。比如说我们对一个结果进行了排序和过滤等的动作,下次再运行这个报表的时候可以选择一个功能直接运行这些动作。这就需要布局(Layout)的功能了。

1.首先我们设置布局的功能按钮。

ls_key-report = sy-repid.

lr_layout = gr_table->get_layout( ).

lr_layout->set_key( ls_key ).

lr_layout->set_save_restriction( l_restrict ).

lr_layout->set_default( 'X' ).

IF p_lay IS NOT INITIAL.

lr_layout->set_initial_layout( p_lay ).

ENDIF.

2.设置前台选项页面。

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME.

PARAMETERS: p_lay LIKE disvariant-variant.

SELECTION-SCREEN SKIP.

PARAMETERS: p_save1 RADIOBUTTON GROUP rg DEFAULT 'X',

p_save2 RADIOBUTTON GROUP rg,

p_save3 RADIOBUTTON GROUP rg.

SELECTION-SCREEN END OF BLOCK blk.

3.设置前台布局选项功能搜索帮助

DATA: ls_layout TYPE salv_s_layout_info,

ls_key TYPE salv_s_layout_key,

l_restrict TYPE salv_de_layout_restriction.

l_restrict = get_restrict( ).

ls_key-report = sy-repid.

ls_layout = cl_salv_layout_service=>f4_layouts(

s_key = ls_key

restrict = l_restrict ).

layout = ls_layout-layout.

下面是程序的所有代码:

REPORT y_xin_002.

*变量定义=======================================================

TYPES: BEGIN OF gs_spfli,

mandt TYPE spfli-mandt,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

countryfr TYPE spfli-countryfr,

cityfrom TYPE spfli-cityfrom,

airpfrom TYPE spfli-airpfrom,

countryto TYPE spfli-countryto,

cityto TYPE spfli-cityto,

airpto TYPE spfli-airpto,

fltime TYPE spfli-fltime,

deptime TYPE spfli-deptime,

arrtime TYPE spfli-arrtime,

distance TYPE spfli-distance,

distid TYPE spfli-distid,

fltype TYPE spfli-fltype,

period TYPE spfli-period,

END OF gs_spfli.

TYPES ty_spfli TYPE gs_spfli OCCURS 0.

*选择屏幕=======================================================

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME.

PARAMETERS: p_lay LIKE disvariant-variant.

SELECTION-SCREEN SKIP.

PARAMETERS: p_save1 RADIOBUTTON GROUP rg DEFAULT 'X',

p_save2 RADIOBUTTON GROUP rg,

p_save3 RADIOBUTTON GROUP rg.

SELECTION-SCREEN END OF BLOCK blk.

*----------------------------------------------------------------------*

* CLASS lcl_alv DEFINITION

*----------------------------------------------------------------------*

* ALV操作类(定义)

*----------------------------------------------------------------------*

CLASS lcl_alv DEFINITION.

PUBLIC SECTION.

METHODS: getdata "取得要显示的数据

RETURNING value(lt_tab) TYPE ty_spfli,

alv_full "全屏Grid列表处理方法

IMPORTING value(lt_tab) TYPE ty_spfli.

CLASS-METHODS: f4_layout "布局选项的搜索帮助

EXPORTING value(layout)TYPE disvariant-variant,

get_restrict"取得约束选项的值

RETURNING value(restrict) TYPE salv_de_layout_restriction.

PRIVATE SECTION.

DATA: gr_table TYPE REF TO cl_salv_table.

ENDCLASS. "lcl_alv DEFINITION

*----------------------------------------------------------------------*

* CLASS lcl_alv IMPLEMENTATION

*----------------------------------------------------------------------*

* ALV操作类(实现)

*----------------------------------------------------------------------*

CLASS lcl_alv IMPLEMENTATION.

*取得要显示的数据=======================================================

METHOD getdata.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_tab FROM spfli.

ENDMETHOD. "getdata

*输出全屏网格列表的方法=================================================

METHOD alv_full.

DATA: lr_functions TYPE REF TO cl_salv_functions_list,

lr_selections TYPE REF TO cl_salv_selections,

lr_layout TYPE REF TO cl_salv_layout,

ls_key TYPE salv_s_layout_key,

l_restrict TYPE salv_de_layout_restriction.

l_restrict = lcl_alv=>get_restrict( ).

"创建实例

TRY.

cl_salv_table=>factory(

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = lt_tab).

CATCH cx_salv_msg.

ENDTRY.

"设置布局功能按钮

ls_key-report = sy-repid.

lr_layout = gr_table->get_layout( ).

lr_layout->set_key( ls_key ).

lr_layout->set_save_restriction( l_restrict ).

lr_layout->set_default( 'X' ).

IF p_lay IS NOT INITIAL.

lr_layout->set_initial_layout( p_lay ).

ENDIF.

"显示ALV的标准功能

lr_functions = gr_table->get_functions( ).

lr_functions->set_all( 'X' ).

"显示列表

gr_table->display( ).

ENDMETHOD. "alv_full

*前台布局选项搜索帮助===============================================

METHOD f4_layout.

DATA: ls_layout TYPE salv_s_layout_info,

ls_key TYPE salv_s_layout_key,

l_restrict TYPE salv_de_layout_restriction.

l_restrict = get_restrict( ).

ls_key-report = sy-repid.

ls_layout = cl_salv_layout_service=>f4_layouts(

s_key = ls_key

restrict = l_restrict ).

layout = ls_layout-layout.

ENDMETHOD. "f4_layout

*取得约束选项的值===================================================

METHOD get_restrict.

CASE 'X'.

WHEN p_save1.

restrict = if_salv_c_layout=>restrict_none.

WHEN p_save2.

restrict = if_salv_c_layout=>restrict_user_dependant.

WHEN p_save3.

restrict = if_salv_c_layout=>restrict_user_independant.

ENDCASE.

ENDMETHOD. "constructor

ENDCLASS. "lcl_alv IMPLEMENTATION

*&---------------------------------------------------------------------*

*& Form f_main

*&---------------------------------------------------------------------*

* 整合数据,执行

*----------------------------------------------------------------------*

FORM f_main.

DATA: lt_tab TYPE ty_spfli,

lr_alv TYPE REF TO lcl_alv.

CREATE OBJECT lr_alv.

"取得要显示的数据

lt_tab = lr_alv->getdata( ).

lr_alv->alv_full( lt_tab ).

ENDFORM. "f_main

*布局搜索帮助=======================================================

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lay.

CALL METHOD lcl_alv=>f4_layout

IMPORTING

layout = p_lay.

*执行动作==========================================================

START-OF-SELECTION.

PERFORM f_main.

四、ALV的事件

SAP的一个类cl_salv_events_table提供了几个常用的事件,包括链接点击,双击,功能触发之前和触发之后,页眉页脚(其中页眉页脚暂时测试不成功,以后再试)。跟其他事件相比,类CL_SALV_EVENTS_TABLE提供了这几个常用的事件已经和ALV结合在一起,所以我们只要实现这几个事件的处理方法就可以了。

1.首先我们要定义好事件的处理方法。

CLASS-METHODS: on_user_command FOR EVENT added_function OF cl_salv_events_table

IMPORTING e_salv_function,

on_double_click FOR EVENT double_click OF cl_salv_events_table

IMPORTING row column,

on_link_clickFOR EVENT link_click OF cl_salv_events_table

IMPORTING row column,

on_before_salv_function FOR EVENT before_salv_function OF cl_salv_events_table

IMPORTING e_salv_function,

on_after_salv_function FOR EVENT after_salv_function OF cl_salv_events_table

IMPORTING e_salv_function.

2.实现事件的处理方法。

*单击新增功能按钮事件处理方法

METHOD on_user_command.

CONCATENATE 'Function Code is '

e_salv_function

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_user_command

*双击事件处理方法

METHOD on_double_click.

g_string = row.

CONCATENATE 'DOUBLE CLICK'

'ROW'

g_string

'COLUMN'

column

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_double_click

*单击事件处理方法

METHOD on_link_click.

g_string = row.

CONCATENATE 'LICK CLICK'

'ROW'

g_string

'COLUMN'

column

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_link_click

*触发事件之前

METHOD on_before_salv_function.

CONCATENATE 'Before Function '

e_salv_function

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_before_salv_function

*触发事件之后

METHOD on_after_salv_function.

CONCATENATE 'After Function '

e_salv_function

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_after_salv_function

3.取得ALV事件的实例

lr_events = gr_table->get_event( ).

4.注册事件的处理方法

SET HANDLER lcl_handle_events=>on_user_command FOR lr_events.

SET HANDLER lcl_handle_events=>on_double_click FOR lr_events.

SET HANDLER lcl_handle_events=>on_link_click FOR lr_events.

SET HANDLER lcl_handle_events=>on_before_salv_function FOR lr_events.

SET HANDLER lcl_handle_events=>on_after_salv_function FOR lr_events.

下面是程序的所有代码:

REPORT y_xin_002.

INCLUDE .

*变量定义=======================================================

TYPES: BEGIN OF gs_spfli,

mandt TYPE spfli-mandt,

carrid TYPE spfli-carrid,

connid TYPE spfli-connid,

countryfr TYPE spfli-countryfr,

cityfrom TYPE spfli-cityfrom,

airpfrom TYPE spfli-airpfrom,

countryto TYPE spfli-countryto,

cityto TYPE spfli-cityto,

airpto TYPE spfli-airpto,

fltime TYPE spfli-fltime,

deptime TYPE spfli-deptime,

arrtime TYPE spfli-arrtime,

distance TYPE spfli-distance,

distid TYPE spfli-distid,

fltype TYPE spfli-fltype,

period TYPE spfli-period,

hotspot TYPE icon_d,

END OF gs_spfli.

TYPES ty_spfli TYPE gs_spfli OCCURS 0.

*----------------------------------------------------------------------*

* CLASS lcl_handle_events DEFINITION

*----------------------------------------------------------------------*

* 事件操作类(定义)

*----------------------------------------------------------------------*

CLASS lcl_handle_events DEFINITION.

PUBLIC SECTION.

CLASS-METHODS: on_user_command FOR EVENT added_function OF cl_salv_events_table

IMPORTING e_salv_function,

on_double_click FOR EVENT double_click OF cl_salv_events_table

IMPORTING row column,

on_link_clickFOR EVENT link_click OF cl_salv_events_table

IMPORTING row column,

on_before_salv_function FOR EVENT before_salv_function OF cl_salv_events_table

IMPORTING e_salv_function,

on_after_salv_function FOR EVENT after_salv_function OF cl_salv_events_table

IMPORTING e_salv_function.

PRIVATE SECTION.

CLASS-DATA: g_string TYPE string.

ENDCLASS. "lcl_handle_events DEFINITION

*----------------------------------------------------------------------*

* CLASS lcl_handle_events IMPLEMENTATION

*----------------------------------------------------------------------*

* 事件操作类(实现)

*----------------------------------------------------------------------*

CLASS lcl_handle_events IMPLEMENTATION.

*单击新增功能按钮事件处理方法==========================================

METHOD on_user_command.

CONCATENATE 'Function Code is '

e_salv_function

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_user_command

*双击事件处理方法=======================================================

METHOD on_double_click.

g_string = row.

CONCATENATE 'DOUBLE CLICK'

'ROW'

g_string

'COLUMN'

column

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_double_click

*单击事件处理方法=======================================================

METHOD on_link_click.

g_string = row.

CONCATENATE 'LICK CLICK'

'ROW'

g_string

'COLUMN'

column

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_link_click

*触发事件之前=======================================================

METHOD on_before_salv_function.

CONCATENATE 'Before Function '

e_salv_function

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_before_salv_function

*触发事件之后=======================================================

METHOD on_after_salv_function.

CONCATENATE 'After Function '

e_salv_function

INTO g_string SEPARATED BY space.

MESSAGE i000(0k) WITH g_string.

ENDMETHOD. "on_after_salv_function

ENDCLASS. "lcl_handle_events IMPLEMENTATION

*----------------------------------------------------------------------*

* CLASS lcl_alv DEFINITION

*----------------------------------------------------------------------*

* ALV操作类(定义)

*----------------------------------------------------------------------*

CLASS lcl_alv DEFINITION.

PUBLIC SECTION.

METHODS: getdata "取得要显示的数据

RETURNING value(lt_tab) TYPE ty_spfli,

alv_full "全屏Grid列表处理方法

IMPORTING value(lt_tab) TYPE ty_spfli.

PRIVATE SECTION.

DATA: gr_table TYPE REF TO cl_salv_table.

ENDCLASS. "lcl_alv DEFINITION

*----------------------------------------------------------------------*

* CLASS lcl_alv IMPLEMENTATION

*----------------------------------------------------------------------*

* ALV操作类(实现)

*----------------------------------------------------------------------*

CLASS lcl_alv IMPLEMENTATION.

*取得要显示的数据=======================================================

METHOD getdata.

SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_tab FROM spfli.

FIELD-SYMBOLS TYPE gs_spfli.

LOOP AT lt_tab ASSIGNING .

-hotspot = icon_overview.

ENDLOOP.

ENDMETHOD. "getdata

*输出全屏网格列表的方法================================================

METHOD alv_full.

DATA: lr_functions TYPE REF TO cl_salv_functions_list,

lr_events TYPE REF TO cl_salv_events_table,

lr_columns TYPE REF TO cl_salv_columns_table,

lr_column TYPE REF TO cl_salv_column_table,

lr_content TYPE REF TO cl_salv_form_element.

"创建实例

TRY.

cl_salv_table=>factory(

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = lt_tab

).

CATCH cx_salv_msg.

ENDTRY.

"设置GUI Status

gr_table->set_screen_status(

report = sy-repid

pfstatus = 'SALV_STANDARD'

set_functions = gr_table->c_functions_all

).

"设置热点

lr_columns = gr_table->get_columns( ).

TRY.

lr_column ?= lr_columns->get_column( 'HOTSPOT' ).

lr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).

lr_column->set_long_text( 'HOTSPOT' ).

CATCH cx_salv_not_found.

ENDTRY.

"注册事件

lr_events = gr_table->get_event( ).

SET HANDLER lcl_handle_events=>on_user_command FOR lr_events.

SET HANDLER lcl_handle_events=>on_double_click FOR lr_events.

SET HANDLER lcl_handle_events=>on_link_click FOR lr_events.

SET HANDLER lcl_handle_events=>on_before_salv_function FOR lr_events.

SET HANDLER lcl_handle_events=>on_after_salv_function FOR lr_events.

"显示列表

gr_table->display( ).

ENDMETHOD. "alv_full

ENDCLASS. "lcl_alv IMPLEMENTATION

*&---------------------------------------------------------------------*

*& Form f_main

*&---------------------------------------------------------------------*

* 整合数据,执行

*----------------------------------------------------------------------*

FORM f_main.

DATA: lt_tab TYPE ty_spfli,

lr_alv TYPE REF TO lcl_alv.

CREATE OBJECT lr_alv.

"取得要显示的数据

lt_tab = lr_alv->getdata( ).

lr_alv->alv_full( lt_tab ).

ENDFORM. "f_main

*执行动作=======================================================

START-OF-SELECTION.

PERFORM f_main.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:13177次
    • 积分:266
    • 等级:
    • 排名:千里之外
    • 原创:12篇
    • 转载:6篇
    • 译文:0篇
    • 评论:1条
    文章分类
    最新评论