这篇文章主要是记录一下cl_gui_alv_grid 和 cl_salv_table 两种方式的ALV的字段,事件等的处理
举例,下面这个是用一个screen,显示2个ALV;上面这一个是用alv grid的;下面那一个是用salv去实现的
alv grid 主要涉及:自定义事件(toolbar),下拉列表的值,ALV显示和编辑模式的切换; 字段的显示隐藏等
salv主要涉及:自定义事件(add function); checkbox的处理; 还有当点"Previous Result“这个按钮时,跳出的第3个alv,也是salv的形式,会涉及到怎么用icon表示处理的
第一个screen里的两个ALV
screen的定义:
第三个ALV:
废话不多说,下面直接代码展示:
三个ALV的事件的声明和定义:
解释下这里面的一些参数:
以input结尾的是第一个alv,以contract结尾的是第2个alv,以result结尾的是第3个alv
事件的处理:
事件处理的相关代码:
FORM on_double_click_contract USING row TYPE salv_de_row
column TYPE salv_de_column.
DATA lv_row TYPE i.
lv_row = row.
READ TABLE gt_data ASSIGNING FIELD-SYMBOL(<data>) INDEX lv_row.
IF <data> IS ASSIGNED.
SET PARAMETER ID 'RECNNR' FIELD <data>-recnnr.
SET PARAMETER ID 'BUK' FIELD gc_bukrs_1000.
CALL TRANSACTION 'RECN' AND SKIP FIRST SCREEN.
ENDIF.
ENDFORM.
FORM on_double_click_result USING row TYPE salv_de_row
column TYPE salv_de_column.
DATA lv_row TYPE i.
lv_row = row.
READ TABLE gt_result ASSIGNING FIELD-SYMBOL(<result>) INDEX lv_row.
IF <result> IS ASSIGNED.
SET PARAMETER ID 'RECNNR' FIELD <result>-recnnr.
SET PARAMETER ID 'BUK' FIELD gc_bukrs_1000.
CALL TRANSACTION 'RECN' AND SKIP FIRST SCREEN.
ENDIF.
ENDFORM.
FORM on_link_click_contract USING row TYPE salv_de_row
column TYPE salv_de_column.
DATA lv_row TYPE i.
lv_row = row.
READ TABLE gt_data ASSIGNING FIELD-SYMBOL(<data>) INDEX lv_row.
CHECK sy-subrc = 0.
IF <data>-selected IS INITIAL.
<data>-selected = 'X'.
ELSE.
CLEAR <data>-selected.
ENDIF.
go_salv_contract->refresh( ).
ENDFORM.
FORM on_user_command_contract USING e_salv_function TYPE salv_de_function.
DATA: lr_selections TYPE REF TO cl_salv_selections,
lt_rows TYPE salv_t_row.
CASE e_salv_function.
WHEN 'SEL_ALL'.
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<data>).
APPEND sy-tabix TO lt_rows.
<data>-selected = abap_true.
ENDLOOP.
lr_selections = go_salv_contract->get_selections( ).
lr_selections->set_selected_rows( lt_rows ).
go_salv_contract->refresh( ).
WHEN 'DESEL_ALL'.
LOOP AT gt_data ASSIGNING <data>.
<data>-selected = ''.
ENDLOOP.
CLEAR lt_rows.
lr_selections = go_salv_contract->get_selections( ).
lr_selections->set_selected_rows( lt_rows ).
go_salv_contract->refresh( ).
WHEN 'CONFIRM'.
PERFORM on_confirm.
IF gv_error <> abap_true.
PERFORM build_alv_200.
ENDIF.
WHEN 'SHOW_RES'.
IF gt_result IS NOT INITIAL.
PERFORM build_alv_200.
ELSE.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
titel = 'Info!'
textline1 = 'No previous result list existed'
start_column = 40
start_row = 15.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM.
FORM on_confirm.
DATA: lt_selected TYPE tty_data,
ls_result TYPE ty_alv_result,
lv_conv_date TYPE string,
lv_year TYPE string,
lv_validto TYPE string,
ls_add_cond TYPE ty_add_cond,
lt_add_cond TYPE TABLE OF ty_add_cond,
lt_tmp_cond TYPE TABLE OF ty_add_cond,
ls_bapi_cond TYPE bapi_re_condition_datc,
lt_return TYPE STANDARD TABLE OF bapiret2,
lv_errmsg TYPE string.
CLEAR gv_error.
CLEAR: gt_result, gt_add_condition.
"get selected rows
lt_selected = gt_data.
DELETE lt_selected WHERE selected <> abap_true.
IF lt_selected IS INITIAL.
gv_error = abap_true.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
titel = 'Error Occurred!!!'
textline1 = 'No entry selected!'
start_column = 20
start_row = 5.
EXIT.
ENDIF.
**********************************************************************
LOOP AT gt_alv_input ASSIGNING FIELD-SYMBOL(<input>).
LOOP AT lt_selected ASSIGNING FIELD-SYMBOL(<sel>)
WHERE sgenr = <input>-sgenr
AND condvalidfrom LE <input>-condvalidfrom
AND condvalidto GE <input>-condvalidfrom.
CLEAR: ls_result, ls_add_cond.
MOVE-CORRESPONDING <sel> TO ls_result.
MOVE-CORRESPONDING <input> TO ls_result.
IF <sel>-calcrule <> <input>-calcrule.
"Calculation Rule Text
READ TABLE gt_calcrule_txt ASSIGNING FIELD-SYMBOL(<txt>)
WITH KEY calcruleext = <input>-calcrule BINARY SEARCH.
IF sy-subrc = 0.
CONCATENATE <input>-calcrule '-' <txt>-xmcalcrule INTO ls_result-calcrule_txt.
ENDIF.
ENDIF.
"set Valid To
CLEAR: lv_conv_date, lv_year, lv_validto.
lv_conv_date = <input>-condvalidfrom.
lv_year = lv_conv_date+0(4) + 1.
CONDENSE lv_year.
CONCATENATE lv_year '0331' INTO lv_validto.
ls_result-condvalidto = lv_validto.
IF ls_result-condvalidto > <sel>-condvalidto.
ls_result-condvalidto = <sel>-condvalidto.
ENDIF.
**********************************************************************
ls_add_cond-recnnr = ls_result-recnnr.
ls_add_cond-distribution_object_type = 'IM'.
ls_add_cond-calculation_object_type = 'IM'.
ls_add_cond-valid_from = ls_result-condvalidfrom.
ls_add_cond-valid_to = ls_result-condvalidto.
ls_add_cond-calculation_object_id = ls_result-rental_object.
ls_add_cond-distribution_object_id = ls_result-rental_object.
ls_add_cond-currency = ls_result-condcurr.
ls_add_cond-condition_type = ls_result-condtype.
ls_add_cond-unit_price = ls_result-unitprice.
ls_add_cond-calc_rule = ls_result-calcrule.
ls_add_cond-external_purpose = <sel>-condpurposeext.
IF ls_add_cond-calc_rule = 'D'.
ls_add_cond-calc_rule_parameter1 = <sel>-calcrulepara1. "measure type
ls_add_cond-calc_rule_parameter2 = <sel>-calcrulepara2. "measure unit
ENDIF.
ls_add_cond-dist_rule = <sel>-distrule.
ls_add_cond-dist_rule_parameter1 = <sel>-distrulepara1.
ls_add_cond-dist_rule_parameter2 = <sel>-distrulepara2.
APPEND ls_result TO gt_result.
APPEND ls_add_cond TO lt_add_cond.
ENDLOOP.
ENDLOOP.
CHECK lt_add_cond IS NOT INITIAL.
"handle data on Contract level
SORT lt_add_cond BY recnnr.
lt_tmp_cond = lt_add_cond.
DELETE ADJACENT DUPLICATES FROM lt_tmp_cond COMPARING recnnr.
"add Conditions to Contract
LOOP AT lt_tmp_cond ASSIGNING FIELD-SYMBOL(<tmp>).
CLEAR: gt_add_condition, lt_return, gv_error, lv_errmsg.
LOOP AT lt_add_cond ASSIGNING FIELD-SYMBOL(<add_cond>) WHERE recnnr = <tmp>-recnnr.
MOVE-CORRESPONDING <add_cond> TO ls_bapi_cond.
ls_bapi_cond-change_indicator = 'I'. "Insert
APPEND ls_bapi_cond TO gt_add_condition.
ENDLOOP.
CALL FUNCTION 'BAPI_RE_CN_CHANGE'
EXPORTING
compcode = gc_bukrs_1000
contractnumber = <tmp>-recnnr
TABLES
condition = gt_add_condition
return = lt_return.
"get error
SORT lt_return BY message.
DELETE ADJACENT DUPLICATES FROM lt_return COMPARING message.
LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<return>) WHERE type = 'E' OR type = 'A'.
gv_error = abap_true.
IF lv_errmsg IS NOT INITIAL.
CONCATENATE lv_errmsg ';' <return>-message INTO lv_errmsg.
ELSE.
lv_errmsg = <return>-message.
ENDIF.
ENDLOOP.
IF gv_error <> abap_true.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
LOOP AT gt_result ASSIGNING FIELD-SYMBOL(<result>) WHERE recnnr = <tmp>-recnnr.
<result>-status = icon_green_light.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT gt_result ASSIGNING <result> WHERE recnnr = <tmp>-recnnr.
<result>-status = icon_red_light.
<result>-msg = lv_errmsg.
ENDLOOP.
ENDIF.
ENDLOOP.
CLEAR gv_error.
ENDFORM.
FORM on_user_command_input USING e_ucomm TYPE sy-ucomm.
CASE e_ucomm.
WHEN 'TOOGLE_EDIT'.
PERFORM toogle_edit_input.
WHEN 'EXTRACT'.
PERFORM check_alv_input.
PERFORM toogle_edit_input.
PERFORM select_data.
PERFORM display_alv_contract.
WHEN OTHERS.
ENDCASE.
ENDFORM.
FORM on_toolbar_input USING i_object TYPE REF TO cl_alv_event_toolbar_set
i_interactive TYPE char01.
DATA ls_toolbar TYPE stb_button.
DELETE i_object->mt_toolbar WHERE function = '&DETAIL'
OR function = '&&SEP00'
OR function = '&CHECK'
OR function = '&REFRESH'
OR function = '&&SEP01'
OR function = '&LOCAL&APPEND'
OR function = '&SORT_ASC'
OR function = '&SORT_DSC'
OR function = '&FIND'
OR function = '&FIND_MORE'
OR function = '&MB_FILTER'
OR function = '&&SEP04'
OR function = '&MB_SUM'
OR function = '&MB_SUBTOT'
OR function = '&&SEP05'
OR function = '&PRINT_BACK'
OR function = '&MB_VIEW'
OR function = '&COL0'
OR function = '&&SEP06'
OR function = '&&SEP07'
OR function = '&INFO'.
APPEND VALUE #( butn_type = 3 function = '&&SEP00' ) TO i_object->mt_toolbar.
APPEND VALUE #( butn_type = 0 quickinfo = 'Display/Edit' icon = '@0Z@' "ICON_CHANGE'
text = 'Display / Edit' function = 'TOOGLE_EDIT') TO i_object->mt_toolbar.
APPEND VALUE #( butn_type = 3 function = '&&SEP01' ) TO i_object->mt_toolbar.
APPEND VALUE #( butn_type = 0 quickinfo = 'Extract' icon = '@41@' "ICON_RETRIEVE
text = 'Extract Contracts' function = 'EXTRACT') TO i_object->mt_toolbar.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
gv_okcode = ok_code.
CLEAR ok_code.
CASE gv_okcode.
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
PERFORM init_variables.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
**&---------------------------------------------------------------------*
**& Module USER_COMMAND_0200 INPUT
**&---------------------------------------------------------------------*
*MODULE user_command_0200 INPUT.
* gv_okcode = ok_code.
* CLEAR ok_code.
* CASE gv_okcode.
* WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
* LEAVE TO SCREEN 100.
* WHEN OTHERS.
* ENDCASE.
*ENDMODULE.
显示/编辑的切换的处理:
第1个第2个ALV的构建,和事件注册
第3个ALV的构建和事件注册,以及字段处理
这里的STATUS字段,是以icon形式显示的,我只用了两个,一个红,一个绿
第一个ALV的字段处理:
dropdown list的值的处理:
这里引用了宏,因为不想重复写太多代码,所以把宏都给封装到一个INCLUDE里了:
*&---------------------------------------------------------------------*
*& Include ZBC_ALV_FIELDCAT_MACRO
*&---------------------------------------------------------------------*
"隐藏列
DEFINE alv_no_out.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-no_out = abap_true.
ENDIF.
END-OF-DEFINITION.
"列不可编辑
DEFINE alv_no_edit.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
CLEAR <fs_fieldcat>-edit.
ENDIF.
END-OF-DEFINITION.
"列可编辑
DEFINE alv_editable.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-edit = abap_true.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_outputlen.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-outputlen = &2.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_fix_column.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-fix_column = abap_true.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_alignment.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-just = &2.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_do_sum.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-do_sum = abap_true.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_col_text.
lv_s = &2.
lv_m = &2.
lv_l = &2.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-coltext = <fs_fieldcat>-scrtext_l = lv_l.
<fs_fieldcat>-scrtext_m = lv_m.
<fs_fieldcat>-scrtext_s = lv_s.
ENDIF.
END-OF-DEFINITION.
*数值字段没有小数点
DEFINE alv_no_decimals.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-datatype = 'DEC'.
<fs_fieldcat>-decimals = '0'.
<fs_fieldcat>-decimals_o = '0'.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_set_dropdown.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-drdn_hndl = &2.
ENDIF.
END-OF-DEFINITION.
*在第几列输出
DEFINE alv_pos.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-col_pos = &2.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_no_domain_check.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-valexi = '!'.
ENDIF.
END-OF-DEFINITION.
DEFINE alv_emphasize.
READ TABLE ct_fieldcat ASSIGNING <fs_fieldcat> WITH KEY fieldname = &1.
IF <fs_fieldcat> IS ASSIGNED.
<fs_fieldcat>-emphasize = &2.
ENDIF.
END-OF-DEFINITION.
第2个ALV的字段 处理
代码如下:
FORM init_alv_input.
IF gt_alv_input IS INITIAL.
DO 3 TIMES.
APPEND INITIAL LINE TO gt_alv_input.
ENDDO.
ENDIF.
ENDFORM.
FORM toogle_edit_input.
CHECK gv_error <> abap_true.
IF gv_alv_editable = abap_true.
gv_alv_editable = abap_false.
gs_layout_input-edit = abap_false.
ELSE.
gv_alv_editable = abap_true.
gs_layout_input-edit = abap_true.
ENDIF.
"refresh ALV table
IF go_alvgrid_input IS BOUND.
CALL METHOD go_alvgrid_input->set_table_for_first_display(
EXPORTING
is_layout = gs_layout_input
CHANGING
it_outtab = gt_alv_input
it_fieldcatalog = gt_fieldcat_input ).
go_alvgrid_input->refresh_table_display( ).
ENDIF.
ENDFORM.
FORM build_alv_100.
IF go_cont IS NOT BOUND.
"Get Container
CREATE OBJECT go_cont
EXPORTING
container_name = 'CONT_100'.
"Create Splitter
CREATE OBJECT go_spliter
EXPORTING
parent = go_cont
rows = 2
columns = 1.
**********************************************************************
"Create Entry Input ALV
CALL METHOD go_spliter->set_row_height
EXPORTING
id = 1
height = 11.
CALL METHOD go_spliter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cont_input.
CREATE OBJECT go_alvgrid_input
EXPORTING
i_parent = go_cont_input.
"Register Event Handler
CREATE OBJECT go_handler_input.
SET HANDLER go_handler_input->on_toolbar_input FOR go_alvgrid_input.
SET HANDLER go_handler_input->on_user_command_input FOR go_alvgrid_input.
"set default editable
gv_alv_editable = abap_true.
gs_layout_input-edit = abap_true.
PERFORM set_dropdown_4_calcrule.
PERFORM build_fieldcat_input CHANGING gt_fieldcat_input.
CALL METHOD go_alvgrid_input->set_table_for_first_display(
EXPORTING
is_layout = gs_layout_input
CHANGING
it_outtab = gt_alv_input
it_fieldcatalog = gt_fieldcat_input ).
**********************************************************************
"Create Contract List ALV
CALL METHOD go_spliter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = go_cont_contract.
TRY.
CALL METHOD cl_salv_table=>factory(
EXPORTING
r_container = go_cont_contract
IMPORTING
r_salv_table = go_salv_contract
CHANGING
t_table = gt_data ).
* t_table = gt_contract ).
"Register Event Handler
go_salv_events_table = go_salv_contract->get_event( ).
go_salv_events = go_salv_contract->get_event( ).
CREATE OBJECT go_handler_contract.
SET HANDLER go_handler_contract->on_double_click_contract FOR go_salv_events_table.
SET HANDLER go_handler_contract->on_link_click_contract FOR go_salv_events_table.
SET HANDLER go_handler_contract->on_user_command_contract FOR go_salv_events.
go_salv_selection = go_salv_contract->get_selections( ).
go_salv_selection->set_selection_mode( 2 ). "Multiple
PERFORM build_fieldcat_contract.
CATCH cx_salv_msg INTO DATA(lo_ex).
ENDTRY.
ELSE.
"refresh ALV table
IF go_alvgrid_input IS BOUND.
go_alvgrid_input->refresh_table_display( ).
ENDIF.
IF go_salv_contract IS BOUND.
go_salv_contract->display( ).
ENDIF.
ENDIF.
ENDFORM.
FORM build_alv_200.
DATA lo_functions TYPE REF TO cl_salv_functions_list.
DATA lo_functional_settings TYPE REF TO cl_salv_functional_settings.
DATA lo_tooltips TYPE REF TO cl_salv_tooltips.
DATA lv_value TYPE lvc_value.
DATA lo_columns TYPE REF TO cl_salv_columns.
DATA lo_column TYPE REF TO cl_salv_column_table.
DATA lo_col TYPE REF TO cl_salv_column.
DEFINE hide_field.
lo_col = lo_columns->get_column( &1 ).
lo_col->set_visible( if_salv_c_bool_sap=>false ).
END-OF-DEFINITION.
DEFINE set_len.
lo_col = lo_columns->get_column( &1 ).
lo_col->set_output_length( &2 ).
END-OF-DEFINITION.
DEFINE set_medium_txt.
lo_col = lo_columns->get_column( &1 ).
lo_col->set_medium_text( &2 ).
END-OF-DEFINITION.
**********************************************************************
IF go_salv_result IS NOT BOUND.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = go_salv_result
CHANGING
t_table = gt_result ).
"Register Event Handler
go_salv_events_table_res = go_salv_result->get_event( ).
CREATE OBJECT go_handler_result.
SET HANDLER go_handler_result->on_double_click_result FOR go_salv_events_table_res.
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
"enable default toolbar
go_salv_result->get_functions( )->set_all( ).
TRY.
"set to display as Icon
lo_columns = go_salv_result->get_columns( ).
lo_column ?= lo_columns->get_column( 'STATUS' ).
lo_column->set_icon( if_salv_c_bool_sap=>true ).
lo_column->set_long_text( 'Status' ).
lo_column->set_alignment( if_salv_c_alignment=>centered ).
lo_column->set_output_length( 10 ).
hide_field 'CALCRULE'.
hide_field 'RENTAL_OBJECT'.
set_len 'XMETXT' 20.
set_len 'MSG' 50.
set_len 'UNITPRICE' 16.
set_len 'CALCRULE_TXT' 25.
set_medium_txt 'CALCRULE_TXT' 'Formula'.
set_medium_txt 'MSG' 'Error Message'.
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
*...Tooltips,
lo_functional_settings = go_salv_result->get_functional_settings( ).
lo_tooltips = lo_functional_settings->get_tooltips( ).
TRY.
"when Green
lv_value = icon_green_light.
lo_tooltips->add_tooltip(
type = cl_salv_tooltip=>c_type_icon
value = lv_value
tooltip = 'Successful' ). "#EC NOTEXT
"when Red
lv_value = icon_red_light.
lo_tooltips->add_tooltip(
type = cl_salv_tooltip=>c_type_icon
value = lv_value
tooltip = 'Error' ). "#EC NOTEXT
CATCH cx_salv_existing. "#EC NO_HANDLER
ENDTRY.
ENDIF.
IF go_salv_result IS BOUND.
go_salv_result->display( ).
ENDIF.
ENDFORM.
FORM build_fieldcat_contract.
DATA lr_columns TYPE REF TO cl_salv_columns_table.
DATA lr_col TYPE REF TO cl_salv_column.
DATA lo_col_list TYPE REF TO cl_salv_column_list.
DATA lv_medium_txt TYPE scrtext_m.
DATA lr_ex_notfound TYPE REF TO cx_salv_not_found.
DATA: lo_functional_settings TYPE REF TO cl_salv_functional_settings,
lo_specific_groups TYPE REF TO cl_salv_specific_groups,
lv_text TYPE cl_salv_specific_groups=>y_text.
DEFINE hide_field.
lr_col = lr_columns->get_column( &1 ).
lr_col->set_visible( if_salv_c_bool_sap=>false ).
END-OF-DEFINITION.
DEFINE set_len.
lr_col = lr_columns->get_column( &1 ).
lr_col->set_output_length( &2 ).
END-OF-DEFINITION.
DEFINE set_medium_txt.
lr_col = lr_columns->get_column( &1 ).
lr_col->set_medium_text( &2 ).
END-OF-DEFINITION.
DEFINE add_function.
go_salv_contract->get_functions( )->add_function(
EXPORTING
name = &1
icon = &3
text = &2
tooltip = &2
position = if_salv_c_function_position=>right_of_salv_functions ).
END-OF-DEFINITION.
**********************************************************************
TRY.
lr_columns = go_salv_contract->get_columns( ).
go_salv_contract->get_functions( )->set_all( ).
lo_functional_settings = go_salv_contract->get_functional_settings( ).
lo_specific_groups = lo_functional_settings->get_specific_groups( ).
**********************************************************************
* Group for column which start with HSL, as group ID GRP1
lv_text = 'Contract'.
lo_specific_groups->add_specific_group( id = 'GRP1' text = lv_text ).
**********************************************************************
"add custom function
add_function 'SEL_ALL' 'Select All' '@4B@'. "ICON_SELECT_ALL
add_function 'DESEL_ALL' 'Deselect All' '@4D@'. "ICON_DESELECT_ALL
add_function 'CONFIRM' 'Confirm to Add' '@5Y@'. "ICON_RELEASE
add_function 'SHOW_RES' 'Previous Result' '@10@'. "ICON_DISPLAY
**********************************************************************
"add selection field as checkbox
lo_col_list ?= lr_columns->get_column( 'SELECTED' ).
lo_col_list->set_cell_type( if_salv_c_cell_type=>checkbox_hotspot ).
"Group Column
lo_col_list ?= lr_columns->get_column( 'RECNNR' ).
lo_col_list->set_specific_group( id = 'GRP1' ).
lo_col_list ?= lr_columns->get_column( 'RECNBEG' ).
lo_col_list->set_specific_group( id = 'GRP1' ).
lo_col_list ?= lr_columns->get_column( 'RECNENDABS' ).
lo_col_list->set_specific_group( id = 'GRP1' ).
**********************************************************************
hide_field 'INTRENO'.
hide_field 'OBJNRDIST'.
hide_field 'RENTAL_OBJECT'.
hide_field 'CALCRULE'.
hide_field 'RECNTXT'.
hide_field 'CALCRULEPARA1'.
hide_field 'CALCRULEPARA2'.
hide_field 'DISTRULE'.
hide_field 'DISTRULEPARA1'.
hide_field 'DISTRULEPARA2'.
hide_field 'CONDPURPOSEEXT'.
**********************************************************************
set_len 'RECNNR' 10.
set_len 'SELECTED' 8.
set_len 'XMETXT' 20.
set_len 'UNITPRICE' 13.
set_len 'CONDTYPE' 6.
set_len 'CALCRULE_TXT' 22.
**********************************************************************
set_medium_txt 'SELECTED' 'Selected'.
set_medium_txt 'RECNENDABS' 'Contract End'.
set_medium_txt 'XMETXT' 'RO Name'.
set_medium_txt 'PARTNER' 'Customer'.
set_medium_txt 'CUSTOMER_NAME' 'Customer Name'.
set_medium_txt 'CALCRULE_TXT' 'Formula'.
CATCH cx_salv_wrong_call cx_salv_existing INTO DATA(lo_ex).
CATCH cx_salv_not_found INTO lr_ex_notfound.
ENDTRY.
ENDFORM.
FORM set_dropdown_4_calcrule.
DATA lt_dral TYPE lvc_t_dral.
DATA lt_drop_down TYPE lvc_t_drop.
CHECK go_alvgrid_input IS BOUND.
* lt_dral = CORRESPONDING #( gt_calcrule_txt MAPPING int_value = xmcalcrule value = calcruleext ).
* LOOP AT lt_dral ASSIGNING FIELD-SYMBOL(<dral>).
* <dral>-handle = 1.
* ENDLOOP.
lt_drop_down = CORRESPONDING #( gt_calcrule_txt MAPPING value = calcruleext ).
LOOP AT lt_drop_down ASSIGNING FIELD-SYMBOL(<drop>).
<drop>-handle = '1'.
ENDLOOP.
CALL METHOD go_alvgrid_input->set_drop_down_table
EXPORTING
* it_drop_down_alias = lt_dral.
it_drop_down = lt_drop_down.
ENDFORM.
FORM build_fieldcat_input CHANGING ct_fieldcat TYPE lvc_t_fcat.
DATA: lv_s TYPE scrtext_s,
lv_m TYPE scrtext_m,
lv_l TYPE scrtext_l.
FIELD-SYMBOLS <fs_fieldcat> TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZSRE_ZFI012R_ALV_INPUT'
i_client_never_display = 'X'
CHANGING
ct_fieldcat = ct_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
alv_set_dropdown 'CALCRULE' '1'.
alv_outputlen 'CONDTYPE' 16.
alv_outputlen 'SGENR' 16.
alv_outputlen 'CONDVALIDFROM' 22.
alv_outputlen 'UNITPRICE' 17.
alv_outputlen 'CALCRULE' 30.
alv_col_text 'SGENR' 'Building'.
alv_col_text 'CONDVALIDFROM' 'Condition Start Date'.
alv_col_text 'UNITPRICE' 'Amount'.
alv_col_text 'CALCRULE' 'Fixed or by Object Management'.
ENDFORM.
FORM display_alv_contract.