本教程介绍如何在SALV列上添加并处理热点hotspot。在大多数alv报表中,hotspot被用来标示有下钻报表的字段,比如能在销售订单号字段上下钻到VA03(销售订单显示)。
为了添加hotspot,具体需要以下步骤:
1,需要从SALV对象(CL_SALV_TABLE)得到CL_SALV_COLUMNS_TABLE的引用。CL_SALV_COLUMNS_TABLE是关于全部字段(column)的对象,由于hotspot是添加到某个具体的列上,所以还要get_column()方法得到单个列CL_SALV_COLUMN_TABLE的引用,这里用到类的强制转换‘?=’。
2,通过方法set_cell_type()为列设置hotspot
3,如果需要响应hotspot的点击,还需要设定对应事件on_link_click的handler
本实例在销售订单列上添加hotspot,单击hotspot探出信息框。
新的UML流程图如下:添加了两个方法,set_hotspot_vbeln()和on_link_click()
原始代码参照-->SALV教程1-创建简单SALV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
*&---------------------------------------------------------------------* *& 一个简单的通过类CL_SALV_TABLE生成SALV的例子 *&---------------------------------------------------------------------* REPORT z_salv_7. * *----------------------------------------------------------------------* * CLASS lcl_report DEFINITION *----------------------------------------------------------------------* CLASS lcl_report DEFINITION. * PUBLIC SECTION. * * 定义SALV输出内表 TYPES: BEGIN OF ty_vbak, vbeln TYPE vbak-vbeln, erdat TYPE erdat, auart TYPE auart, kunnr TYPE kunnr, END OF ty_vbak. * DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak. * * ALV reference DATA: o_alv TYPE REF TO cl_salv_table. * METHODS: * 抽取数据 get_data, * * 生成输出内容 generate_output. * *$*$*.....CODE_ADD_1 - Begin..................................1..*$*$* * * 定义private method来设定SALV不同特性 PRIVATE SECTION. METHODS: set_pf_status CHANGING co_alv TYPE REF TO cl_salv_table. * 设置hotspot METHODS: set_hotspot_vbeln CHANGING co_alv TYPE REF TO cl_salv_table. * * Event Handler for HOTSPOT event METHODS: on_link_click FOR EVENT link_click OF cl_salv_events_table IMPORTING row column . *$*$*.....CODE_ADD_1 - End....................................1..*$*$* ENDCLASS. "lcl_report DEFINITION *----------------------------------------------------------------------* * CLASS lcl_report IMPLEMENTATION *----------------------------------------------------------------------* * 类实现 CLASS lcl_report IMPLEMENTATION. * METHOD get_data. * 抽取数据 SELECT vbeln erdat auart kunnr INTO TABLE t_vbak FROM vbak UP TO 20 ROWS. * ENDMETHOD. "get_data *....................................................................... METHOD generate_output. * New ALV instance * We are calling the static Factory method which will give back * the ALV object reference. * * exception class DATA: lx_msg TYPE REF TO cx_salv_msg. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = o_alv CHANGING t_table = t_vbak ). CATCH cx_salv_msg INTO lx_msg. ENDTRY. * *$*$*.....CODE_ADD_2 - Begin..................................2..*$*$* * * In this area we will call the methods which will set the * different properties to the ALV * 调用status设置方法 CALL METHOD set_pf_status CHANGING co_alv = o_alv. * Set Up the Hotspot & Event Handler CALL METHOD set_hotspot_vbeln CHANGING co_alv = o_alv. *$*$*.....CODE_ADD_2 - End....................................2..*$*$* * * 调用Display方法将数据输出到屏幕上 o_alv->display( ). * ENDMETHOD. "generate_output * *$*$*.....CODE_ADD_3 - Begin..................................3..*$*$* * * In this area we will implement the methods which are defined in * the class definition * status设置方法实现 METHOD set_pf_status. DATA: lo_functions TYPE REF TO cl_salv_functions_list. * 设置默认的标准状态栏 lo_functions = co_alv->get_functions( ). lo_functions->set_default( abap_true ). ENDMETHOD. METHOD set_hotspot_vbeln. * *...HotSpot DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table, lo_col_tab TYPE REF TO cl_salv_column_table. * * get Columns object lo_cols_tab = co_alv->get_columns( ). * * Get VBELN column TRY. lo_col_tab ?= lo_cols_tab->get_column( 'VBELN' ). CATCH cx_salv_not_found. ENDTRY. * * Set the HotSpot for VBELN Column TRY. CALL METHOD lo_col_tab->set_cell_type EXPORTING value = if_salv_c_cell_type=>hotspot. . CATCH cx_salv_data_error . ENDTRY. * *...Events DATA: lo_events TYPE REF TO cl_salv_events_table. * * all events lo_events = o_alv->get_event( ). * * 设定event handler SET HANDLER me->on_link_click FOR lo_events. * ENDMETHOD. "set_hotspot_vbeln * * Handles the UI on the VBELN (HotSpot) METHOD on_link_click. * DATA: la_vbak TYPE ty_vbak. * * 取得销售订单 READ TABLE me->t_vbak INTO la_vbak INDEX row. IF la_vbak-vbeln IS NOT INITIAL. MESSAGE i398(00) WITH 'You have selected' la_vbak-vbeln. ENDIF. * ENDMETHOD. "on_link_click *$*$*.....CODE_ADD_3 - End....................................3..*$*$* * ENDCLASS. "lcl_report IMPLEMENTATION START-OF-SELECTION. DATA: lo_report TYPE REF TO lcl_report. CREATE OBJECT lo_report. * 抽取数据 lo_report->get_data( ). * 生成SALV lo_report->generate_output( ). |
运行后,双击热点会弹出信息框。
以上。
发表评论