这里并不介绍类cl_gui_alv_grid的用法,所以此博文的先决条件是会使用基本的cl_gui_alv_grid显示ALV。
Sample code:
Definition:
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA:
gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
g_grid TYPE REF TO cl_gui_alv_grid,
g_event_receiver TYPE REF TO lcl_event_receiver.
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname es_row_no er_event_data et_bad_cells e_display,
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD on_f4.
CASE e_fieldname.
WHEN 'KOSTL'.
READ TABLE gt_output INTO gs_output INDEX es_row_no-row_id.
IF sy-subrc = 0.
PERFORM sub_help_kostl CHANGING gs_output-kostl.
IF gs_output-kostl IS NOT INITIAL.
MODIFY gt_output FROM gs_output INDEX es_row_no-row_id.
CALL METHOD g_grid->refresh_table_display.
ENDIF.
ENDIF.
WHEN 'POSID'.
READ TABLE gt_output INTO gs_output INDEX es_row_no-row_id.
IF gs_output-prctr = gc_prctr.
PERFORM sub_help_posid CHANGING gs_output-posid.
IF gs_output-posid IS NOT INITIAL.
MODIFY gt_output FROM gs_output INDEX es_row_no-row_id.
CALL METHOD g_grid->refresh_table_display.
ENDIF.
ENDIF.
CLEAR gs_output.
ENDCASE.
ENDMETHOD. "on_f4
定义ALV列字段的时候:
gs_fieldcat-f4availabl = 'X'.
gs_fieldcat-edit = 'X'.
Screen 2000 PBO:
PERFORM d0100_register_f4.
CREATE OBJECT g_event_receiver.
SET HANDLER g_event_receiver->on_f4 FOR g_grid.
Subrouting:
FORM d0100_register_f4 .
DATA lt_f4 TYPE lvc_t_f4 WITH HEADER LINE.
lt_f4-fieldname = 'KOSTL'.
lt_f4-register = 'X'.
lt_f4-getbefore = 'X'.
lt_f4-chngeafter = 'X'.
lt_f4-internal = 'X'.
INSERT table lt_f4.
CALL METHOD g_grid->register_f4_for_fields
EXPORTING
it_f4 = lt_f4[].
ENDFORM. " d0100_register_f4
FORM sub_help_kostl CHANGING pc_kostl.
DATA: t_shfields LIKE help_value OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF t_shvalue OCCURS 0,
string(60),
END OF t_shvalue.
DATA: BEGIN OF lt_cskt OCCURS 0,
kostl LIKE csks-kostl,
ktext LIKE cskt-ktext,
END OF lt_cskt.
SELECT csks~kostl cskt~ktext INTO TABLE lt_cskt
FROM csks INNER JOIN cskt
ON csks~kokrs = cskt~kokrs
AND csks~kostl = cskt~kostl
AND csks~datbi = cskt~datbi
AND cskt~spras = '1'
WHERE csks~kokrs = '××'
AND csks~datbi GT sy-datum
AND csks~bukrs = p_bukrs.
t_shfields-tabname = 'CSKS'.
t_shfields-fieldname = 'KOSTL'.
t_shfields-selectflag = 'X'.
APPEND t_shfields.
CLEAR t_shfields.
t_shfields-tabname = 'CSKT'.
t_shfields-fieldname = 'KTEXT'.
APPEND t_shfields.CLEAR t_shfields.
LOOP AT lt_cskt.
t_shvalue-string = lt_cskt-kostl.
APPEND t_shvalue.CLEAR t_shvalue.
t_shvalue-string = lt_cskt-ktext.
APPEND t_shvalue.CLEAR t_shvalue.
ENDLOOP.
CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE'
EXPORTING
title_in_values_list = '成本中心'
titel = '请选择'
IMPORTING
select_value = pc_kostl
TABLES
fields = t_shfields
valuetab = t_shvalue.
IF sy-subrc NE 0.
MESSAGE 'No value selected!' TYPE 'S'.
ENDIF.
ENDFORM. " sub_help_kostl
FORM sub_help_posid CHANGING pc_posid.
CALL FUNCTION 'HELP_VALUES_GET_WITH_MATCHCODE'
EXPORTING * DISPLAY = ' '
* FIELDNAME = ' '
* INPUT_VALUE = ' '
matchcode_object = 'PRP'
* TABNAME = ' ' IMPORTING
select_value = pc_posid .
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. " sub_help_posid
阅读(1750) | 评论(0) | 转发(1) |