分类:
2009-05-26 10:20:26
OO ALV 某一列的F4
一、 全局定义
*--------------------------------------------------------------------*
* TYPES *
*--------------------------------------------------------------------
* types for screen 100 output
TYPES : BEGIN OF ty_result_0100,
chk TYPE c LENGTH 1,
cdnm TYPE zpsct0012-cdnm,
avg_price TYPE zcsjt00010-part_price,
min_price TYPE zcsjt00010-part_price,
min_qty TYPE eine-minbm,
max_price TYPE zcsjt00010-part_price,
max_qty TYPE eine-minbm,
total TYPE i,
END OF ty_result_0100.
* types for CDNM
TYPES: BEGIN OF ty_cdnm,
cd TYPE zpsct0012-cd,
cdnm TYPE zpsct0012-cdnm,
END OF ty_cdnm.
*--------------------------------------------------------------------*
* GOLBAL DATA DEFINITION *
*--------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION DEFERRED.
DATA : grf_event_handler TYPE REF TO lcl_event_handler.
DATA : gt_result_0100 TYPE TABLE OF ty_result_0100.
二、 CLASS 定义 、实现
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
onf4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
e_fieldvalue
es_row_no
er_event_data
et_bad_cells
e_display.
ENDCLASS. "lcl_event_handler DEFINITION
*&---------------------------------------------------------------------*
*& calss lcl_event_handler IMPLEMENTATION
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
* Handle F4
METHOD onf4.
PERFORM process_event_onf4 USING e_fieldname
e_fieldvalue
es_row_no
er_event_data
et_bad_cells
e_display.
ENDMETHOD. "onf4
ENDCLASS. "lcl_event_handler IMPLEMENTATION
三、 100屏 PBO 里注册F4
*&-------------------------------------------------------------------
* MODULE PBO_0100 OUTPUT
*&-------------------------------------------------------------------
MODULE pbo_0100 OUTPUT.
IF grf_grid_0100 IS INITIAL.
PERFORM init_0100.
PERFORM select_data.
PERFORM set_layout.
perform set_grid_onF4.
PERFORM write_data_0100.
ENDIF.
ENDMODULE. "pbo_0100 OUTPUT
四、相关FORM
*&---------------------------------------------------------------------*
*& Form PROCESS_EVENT_ONF4
*&---------------------------------------------------------------------*
FORM process_event_onf4 USING l_fieldname TYPE lvc_fname
l_fieldvalue TYPE lvc_value
ls_row_no TYPE lvc_s_roid
pr_event_data TYPE REF TO cl_alv_event_data
pt_bad_cells TYPE lvc_t_modi
l_display TYPE char01. "#EC *
DATA: l_row TYPE char10.
DATA: lt_cdnm TYPE TABLE OF ty_cdnm,
lt_field TYPE TABLE OF dfies,
lt_ret TYPE TABLE OF ddshretval,
lw_ret LIKE LINE OF lt_ret,
l_retfield TYPE dfies-fieldname,
l_dynprofield TYPE dynfnam,
l_window_title TYPE c,
lw_result_0100 TYPE ty_result_0100.
l_row = ls_row_no-row_id.
* get Possible Entries value for field CDNM
* PERFORM get_value_for_cdnm TABLES lt_cdnm .
CHECK lt_cdnm IS NOT INITIAL .
SORT lt_cdnm BY cdnm.
DELETE ADJACENT DUPLICATES FROM lt_cdnm COMPARING cdnm.
l_retfield = l_fieldname.
l_dynprofield = ''.
l_window_title = ''.
* show base F4 help
PERFORM show_f4_help TABLES lt_cdnm
lt_field
lt_ret
USING l_retfield
l_dynprofield
l_window_title.
READ TABLE lt_ret INTO lw_ret INDEX 1.
IF sy-subrc = 0.
READ TABLE gt_result_0100 INDEX l_row INTO lw_result_0100.
lw_result_0100-cdnm = lw_ret-fieldval.
MODIFY gt_result_0100 INDEX l_row FROM lw_result_0100.
CALL METHOD grf_grid_0100->refresh_table_display.
ENDIF.
ENDFORM. " PROCESS_EVENT_ONF4
*&---------------------------------------------------------------------*
*& Form SHOW_F4_HELP
*&---------------------------------------------------------------------*
* show f4 input help
*----------------------------------------------------------------------*
* --> pt_value text
* <-- p_field text
*----------------------------------------------------------------------*
FORM show_f4_help TABLES pt_value
pt_field
pt_ret
USING p_retfield TYPE dfies-fieldname
p_dynprofield TYPE dynfnam
p_window_title TYPE c.
* create search help
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = p_retfield
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = p_dynprofield
window_title = p_window_title
value_org = 'S'
TABLES
value_tab = pt_value
field_tab = pt_field
return_tab = pt_ret
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.
ENDIF.
ENDFORM. " SHOW_F4_HELP
*&---------------------------------------------------------------------*
*& Form SET_GRID_ONF4
*&---------------------------------------------------------------------*
* SET_GRID_ONF4
*----------------------------------------------------------------------*
FORM set_grid_onf4 .
DATA: l_field TYPE lvc_fname,
lt_f4 TYPE lvc_t_f4,
ls_f4 TYPE lvc_s_f4.
ls_f4-fieldname = 'CDNM'.
ls_f4-register = 'X'.
ls_f4-getbefore = 'X'.
ls_f4-chngeafter = 'X'.
ls_f4-internal = ''.
INSERT ls_f4 INTO TABLE lt_f4.
CHECK NOT lt_f4 IS INITIAL.
CALL METHOD grf_grid_0100->register_f4_for_fields
EXPORTING
it_f4 = lt_f4.
ENDFORM. " SET_GRID_ONF4