ALV配置表管理
一.字段属性配置表
对于可编辑的ALV不用这个,尽可能多的设置一些控制:
单元格类型:默认A,特殊选择
ZLYE_TYPE E A 1 Text Field A
ZLYE_TYPE E A 2 Check Box B
ZLYE_TYPE E A 3 Drop Down C
ZLYE_TYPE E A 4 Link D
ZLYE_TYPE E A 5 Link Url E
ZLYE_TYPE E A 6 Button F
做成配置表,也可以用前面的自建表批导程序批导。
二.配置表在ALV中的使用
1.在WDA Component中添加ALV组件并激活:
2. Component Controller中创建结果节点
3.将ALV组件添加到使用的VIEW中:
METHOD init_alv . DATA: lr_comp_alv TYPE REF TO if_wd_component_usage, lr_comp_if_alv TYPE REF TO iwci_salv_wd_table. DATA:gt_zlyt001 TYPE TABLE OF zlyt001, gw_zlyt001 LIKE LINE OF gt_zlyt001, gv_string TYPE string. DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings, lr_column TYPE REF TO cl_salv_wd_column, lr_column_header TYPE REF TO cl_salv_wd_column_header. DATA: lt_column TYPE salv_wd_t_column_ref, ls_column TYPE salv_wd_s_column_ref. ****"定义特殊格式的类型 DATA: lr_input_field TYPE REF TO cl_salv_wd_uie_input_field, lr_checkbox TYPE REF TO cl_salv_wd_uie_checkbox, lr_button TYPE REF TO cl_salv_wd_uie_button, lr_link TYPE REF TO cl_salv_wd_uie_link_to_action, lr_linu TYPE REF TO cl_salv_wd_uie_link_to_url, lr_image TYPE REF TO cl_salv_wd_uie_image, lr_dropdown_by_key TYPE REF TO cl_salv_wd_uie_dropdown_by_key. DATA lr_column_id TYPE string. **** DATA: lr_field_amnt TYPE REF TO cl_salv_wd_field . DATA: lv_aggr_rule TYPE REF TO cl_salv_wd_aggr_rule, lr_sort_rule TYPE REF TO cl_salv_wd_sort_rule. "创建组件/实例化组件 lr_comp_alv = wd_this->wd_cpuse_alv( ) . IF lr_comp_alv->has_active_component( ) IS INITIAL. lr_comp_alv->create_component( ). ENDIF. DATA lr_config TYPE REF TO cl_salv_wd_config_table. DATA:lr_func_config TYPE REF TO cl_salv_wd_config_table. "获取ALV对象的设置对象 lr_comp_if_alv = wd_this->wd_cpifc_alv( ). lr_config = lr_comp_if_alv->get_model( ). lr_func_config = lr_comp_if_alv->get_model( ). lr_column_settings ?= lr_config . lt_column = lr_column_settings->get_columns( )."获取ALV字段 "取配置表数据 SELECT * INTO TABLE gt_zlyt001 FROM zlyt001 WHERE sales_org = wd_this->sales_org AND component_name = 'ZHSI_INVOICE' AND alv = 'ALV'. SORT gt_zlyt001 BY posit ASCENDING." *========================================================= DATA: l_value TYPE REF TO cl_salv_wd_config_table. l_value = lr_comp_if_alv->get_model( ). l_value->if_salv_wd_table_settings~set_fixed_table_layout( abap_true ). "使列宽不可自动调节 l_value->if_salv_wd_table_settings~set_width( '100%' ) . "设置宽度 l_value->if_salv_wd_table_settings~set_visible_row_count( '15' ). "显示的行数 l_value->if_salv_wd_table_settings~set_scrollable_col_count( '15' )."设置滚动条行数 l_value->if_salv_wd_table_settings~set_read_only( abap_true )."设置只读 l_value->if_salv_wd_table_settings~set_display_empty_rows( abap_false )."设置空表也显示alv行 l_value->if_salv_wd_table_settings~set_selection_mode( cl_wd_table=>e_selection_mode-multi_no_lead )."多选无lead l_value->if_salv_wd_function_settings~set_enabled( abap_true ) ."功能 l_value->if_salv_wd_std_functions~set_edit_check_available( abap_false ) . l_value->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ) . l_value->if_salv_wd_std_functions~set_export_allowed( abap_true ) ."可excel导出 * l_value->if_salv_wd_std_functions~set_view_list_allowed( abap_false ). l_value->if_salv_wd_std_functions~set_pdf_allowed( abap_false ) ."可pdf导出 l_value->if_salv_wd_std_functions~set_edit_append_row_allowed( abap_false ) . l_value->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_false ) . l_value->if_salv_wd_std_functions~set_filter_filterline_allowed( abap_true ). l_value->if_salv_wd_std_functions~set_filter_complex_allowed( abap_true )."多字段筛选 * l_value->if_salv_wd_std_functions~set_dialog_settings_allowed( abap_true ). DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings. lr_table_settings ?= l_value. lr_table_settings->set_data_check( '01' ). lr_table_settings->set_read_only( abap_false ). LOOP AT lt_column INTO ls_column. lr_column_id = ls_column-id. lr_column = ls_column-r_column. lr_column->set_resizable( value = 'X' ). lr_column->set_width( value = '100' ). READ TABLE gt_zlyt001 INTO gw_zlyt001 WITH KEY field = ls_column-id. IF sy-subrc = 0. IF gw_zlyt001-visiable = 'X'. lr_column_header = ls_column-r_column->create_header( ). ls_column-r_column->set_position( gw_zlyt001-posit ). CASE gw_zlyt001-field_type. WHEN 'B'. CREATE OBJECT lr_checkbox EXPORTING checked_fieldname = ls_column-id. lr_column->set_cell_editor( lr_checkbox ). WHEN 'C'. WHEN 'D'. CREATE OBJECT lr_link.
lr_link->set_text_fieldname( ls_column-id ).
ls_column-r_column->set_cell_editor( lr_link ).
lr_column->set_cell_editor( lr_link ). WHEN 'E'. WHEN 'F'. WHEN OTHERS. ENDCASE. IF gw_zlyt001-text CS 'CRM/'."otr text使用特定格式的 gv_string = gw_zlyt001-text. lr_column_header->set_text( zcl_otr=>get_text( gv_string ) ). ELSE. IF gw_zlyt001-text IS NOT INITIAL. gv_string = gw_zlyt001-text. lr_column_header->set_text( gv_string ). ENDIF. ENDIF. ELSE. ls_column-r_column->set_position( gw_zlyt001-posit ). lr_column = lr_column_settings->get_column( ls_column-id ). lr_column->set_visible( if_wdl_core=>visibility_none ). ENDIF. ENDIF. ENDLOOP. DATA lr_buttonui TYPE REF TO cl_salv_wd_fe_button. DATA lv_function TYPE REF TO cl_salv_wd_function. CREATE OBJECT lr_buttonui. lr_buttonui->set_text( zcl_otr=>get_text( 'ZCRM/PRINT') ). lr_buttonui->set_image_source( 'ICON_PRINT' ). lv_function = l_value->if_salv_wd_function_settings~create_function( id = 'PRINT' ). lv_function->set_alignment( '01' ). lv_function->set_editor( lr_buttonui ). lv_function->set_visible( '02' ). ENDMETHOD.
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^