直接上代码
*----------------------------------------------------------------------*
* DEFINE LOCAL CLASS
*----------------------------------------------------------------------*
CLASS lc_application DEFINITION.
************************************************************************
* CLASS NAME: LC_APPLICATION
* DESCRIPTION: RESPONSE EVENTS GENERATED BY USERS COMMANDS
************************************************************************
PUBLIC SECTION.
METHODS:
handle_onf4_help
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data.
METHODS handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS. "lc_application DEFINITION
*---------------------------------------------------------------------*
* CLASS LCL_APPLICATION IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
CLASS lc_application IMPLEMENTATION.
*搜索帮助
METHOD handle_onf4_help.
PERFORM frm_handle_onf4_help USING e_fieldname
es_row_no
er_event_data.
er_event_data->m_event_handled = abap_true.
ENDMETHOD. "handle_on_f4 "handle_user_command
METHOD handle_data_changed.
PERFORM frm_handle_data_changed USING er_data_changed.
ENDMETHOD.
ENDCLASS. "lc_application IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Form frm_display_data
*&---------------------------------------------------------------------*
* text:ALV显示
*----------------------------------------------------------------------*
FORM frm_display_data .
DATA:lt_event TYPE slis_t_event,
ls_event LIKE LINE OF lt_event.
ls_event-name = slis_ev_caller_exit_at_start.
ls_event-form = 'FRM_CALLER_EXIT'.
APPEND ls_event TO lt_event.
gs_layout-zebra = 'X'.
gs_layout-cwidth_opt = 'X'.
gs_layout-stylefname = 'STYLE'.
* 载入ALV需要显示的列
PERFORM frm_append_col .
IF gt_list IS NOT INITIAL.
* 调用function module显示ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
it_fieldcat_lvc = gt_fieldcat[]
is_layout_lvc = gs_layout
i_callback_pf_status_set = 'FRM_SET_PF_STATUS'
i_callback_user_command = 'FRM_USER_COMMAND'
i_save = 'A'
it_events = lt_event[]
TABLES
t_outtab = gt_list
EXCEPTIONS
program_error = 1
OTHERS = 2.
ELSE.
MESSAGE '没有可执行的数据' TYPE 'S' DISPLAY LIKE 'E' .
ENDIF..
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_PF_STATUS
*&---------------------------------------------------------------------*
*& text:ALV自定义工具栏设置
*&---------------------------------------------------------------------*
FORM frm_set_pf_status USING u_extab TYPE slis_t_extab.
DATA lt_func TYPE TABLE OF sy-ucomm.
IF p_radio2 EQ abap_true OR p_radio3 EQ abap_true.
APPEND 'EXECUTE' TO lt_func.
ENDIF.
SET PF-STATUS 'PF_1000' EXCLUDING lt_func.
* 注册f4事件
PERFORM frm_set_f4_event.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*& text:载入显示字段
*&---------------------------------------------------------------------*
FORM frm_user_command USING u_ucomm TYPE syucomm
u_self TYPE slis_selfield.
DATA(lv_ucomm) = u_ucomm.
DATA:lt_rows TYPE lvc_t_row WITH HEADER LINE.
DATA:ls_052 TYPE zmmt0052,
ls_list TYPE zqmt0114.
* 获取alv对象
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
** 判断用户操作
CASE lv_ucomm.
WHEN 'DATA_SAVE'.
WHEN OTHERS.
* Do nothing
ENDCASE.
PERFORM frm_ref_alv.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM frm_caller_exit
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_caller_exit USING u_exit TYPE slis_data_caller_exit.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
* 设置回车事件
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
CALL METHOD go_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
* 设置光标焦点移开被修改单元格后触发事件
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified
EXCEPTIONS
error = 1
OTHERS = 2.
ENDFORM. "CALLER_EXIT
FORM frm_set_f4_event .
DEFINE mcr_fillf4.
CLEAR gs_f4_event.
gs_f4_event-fieldname = &1.
gs_f4_event-register = abap_true.
* gs_f4_event-getbefore = abap_true.
gs_f4_event-chngeafter = abap_true.
gs_f4_event-internal = space.
INSERT gs_f4_event INTO TABLE gt_f4_event.
END-OF-DEFINITION.
CLEAR:gt_f4_event.
mcr_fillf4 'PONDERING_NO'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
IF go_application IS INITIAL.
CREATE OBJECT go_application.
ENDIF.
SET HANDLER go_application->handle_onf4_help FOR go_grid.
SET HANDLER go_application->handle_data_changed FOR go_grid.
CALL METHOD go_grid->register_f4_for_fields
EXPORTING
it_f4 = gt_f4_event.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_handle_onf4_help
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> E_FIELDNAME
*& --> ES_ROW_NO
*& --> ER_EVENT_DATA
*&---------------------------------------------------------------------*
FORM frm_handle_onf4_help USING u_fieldname TYPE lvc_fname
u_row_no TYPE lvc_s_roid
u_event_data TYPE REF TO cl_alv_event_data.
CASE u_fieldname.
WHEN ' '. "F4字段名称
PERFORM frm_f4_get_value USING u_fieldname
u_row_no
u_event_data.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_handle_data_changed
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> ER_DATA_CHANGED
*&---------------------------------------------------------------------*
FORM frm_handle_data_changed
USING er_data_changed TYPE REF TO cl_alv_changed_data_protocol.
DATA es_change TYPE lvc_s_modi.
DATA:ls_052 TYPE zmmt0052.
* lv_planno TYPE zmmt0052-plan_no.
LOOP AT er_data_changed->mt_good_cells INTO es_change.
READ TABLE gt_list ASSIGNING FIELD-SYMBOL(<lfs_list>) INDEX es_change-row_id.
IF sy-subrc = 0.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_f4_get_value
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
FORM frm_f4_get_value USING u_fieldname TYPE lvc_fname
u_row_no TYPE lvc_s_roid
u_event_data
TYPE REF TO cl_alv_event_data.
DATA:lt_fields TYPE TABLE OF sval,
ls_fields TYPE sval.
lv_field = u_fieldname.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = u_fieldname "起作用的字段
value_org = 'S'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = lv_field
callback_program = sy-repid
callback_form = 'FRM_CALLBACK_KOSTL'
TABLES
value_tab = lt_pop_data
return_tab = lt_ret_tab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
LOOP AT lt_ret_tab ASSIGNING FIELD-SYMBOL(<lfs_ret>) WHERE fieldname = 'F0001'.
READ TABLE gt_list ASSIGNING FIELD-SYMBOL(<lfs_list>) INDEX u_row_no-row_id.
IF sy-subrc = 0.
ENDIF.
u_event_data->m_event_handled = 'X'. " 抑制标准的Search Help
ENDLOOP.
ENDIF.
PERFORM frm_ref_alv.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_REF_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_ref_alv .
IF go_grid IS INITIAL .
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
ENDIF.
lv_stable-col = 'X'.
lv_stable-row = 'X'.
CALL METHOD go_grid->refresh_table_display "更新
EXPORTING
is_stable = lv_stable.
CALL METHOD go_grid->set_function_code
CHANGING
c_ucomm = sy-ucomm.
ENDFORM.