ITPub博客

首页 > Linux操作系统 > Linux操作系统 > CLASS_ALV_F4_LISTBOX

CLASS_ALV_F4_LISTBOX

原创 Linux操作系统 作者:hzq2010 时间:2011-05-07 15:27:58 0 删除 编辑
 
REPORT z_barry_class_alv_f4_listbox.
TYPE-POOLS: rsds.
DATA: BEGIN OF itab OCCURS 0 ,
        mblnr LIKE mseg-mblnr ,
        kostl LIKE mseg-kostl ,
        bwart LIKE mseg-bwart ,
        handle_drdn           ,
      END OF itab .
DATA: ok_code LIKE sy-ucomm .
DATA: l_valid(1) TYPE c.
DATA: go_grid             TYPE REF TO cl_gui_alv_grid,
      go_custom_container TYPE REF TO cl_gui_custom_container.
DATA: gt_fieldcat TYPE lvc_t_fcat,
      gs_fieldcat TYPE lvc_s_fcat,
      gs_variant  TYPE disvariant ,
      gt_sort     TYPE lvc_t_sort,
      gs_sort     TYPE lvc_s_sort,
      gt_filt     TYPE lvc_t_filt,
      gs_filt     TYPE lvc_s_filt,
      ls_cell     TYPE lvc_s_styl,
      sla         TYPE lvc_s_layo,
      gt_f4       TYPE lvc_t_f4,
      gs_f4       TYPE lvc_s_f4.
*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS handle_f4
      FOR EVENT onf4 OF cl_gui_alv_grid
      IMPORTING e_fieldname
                es_row_no
                er_event_data
                et_bad_cells.
ENDCLASS.                    "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_f4.
    PERFORM. f4 USING e_fieldname
                     es_row_no
                     er_event_data
                     et_bad_cells.
  ENDMETHOD.                                                "handle_f4
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
DATA: event_receiver TYPE REF TO lcl_event_receiver.
INITIALIZATION.
*  gd_repid = sy-repid.
  PERFORM. fieldcat_init USING gt_fieldcat[].
START-OF-SELECTION.
  CALL SCREEN '100'.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE ok_code.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'CHANGE'.
      PERFORM. change.
  ENDCASE.
  CLEAR ok_code .
ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  load_data_into_grid
*&---------------------------------------------------------------------*
FORM. load_data_into_grid.
  SELECT * FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab
  UP TO 10 ROWS .
  LOOP AT itab.
    itab-handle_drdn = 4.
    MODIFY itab.
  ENDLOOP.
  sla-cwidth_opt = 'X'.
  sla-zebra      = 'X'.
  PERFORM. set_grid_drdn CHANGING gt_fieldcat.
  CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
      is_variant                    = gs_variant
      i_save                        = 'A'
      is_layout                     = sla
    CHANGING
      it_outtab                     = itab[]
      it_fieldcatalog               = gt_fieldcat[]
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4.
  CALL METHOD go_grid->set_ready_for_input "处于编辑状态
    EXPORTING
      i_ready_for_input = 1.
  CALL METHOD cl_gui_control=>set_focus    "设置焦点在go_grid 上
    EXPORTING
      control = go_grid .
ENDFORM.                    " load_data_into_grid

*&--------------------------------------------------------------------*
*&      Form  fieldcat_init
*&--------------------------------------------------------------------*
FORM. fieldcat_init USING rt_fieldcat TYPE lvc_t_fcat.
  DATA: ls_fieldcat TYPE lvc_s_fcat.
  PERFORM. frm_catlg_set USING:
  'MBLNR'  'X' '凭证'       '' 'MBLNR' 'MSEG' rt_fieldcat,
  'KOSTL'  '' '成本中心'   'X'  ''      ''     rt_fieldcat,
  'BWART'  '' '移动类型'   'X'  ''      ''     rt_fieldcat.
  gs_f4-fieldname = 'KOSTL'.
  gs_f4-register = 'X'.
  gs_f4-getbefore = 'X'.
  gs_f4-chngeafter = 'X'.
  INSERT gs_f4 INTO TABLE gt_f4.
ENDFORM.   "fieldcat_init

*---------------------------------------------------------------------*
*       FORM. frm_catlg_set                                            *
*---------------------------------------------------------------------*
FORM. frm_catlg_set USING p_field p_key p_text p_edit ref_f ref_t
                          rt_fieldcat  TYPE lvc_t_fcat .
  DATA:  tmp_fieldcat TYPE lvc_s_fcat.
  tmp_fieldcat-fieldname     =  p_field.
  tmp_fieldcat-key           =  p_key .
  tmp_fieldcat-scrtext_l     =  p_text.
  tmp_fieldcat-edit          =  p_edit.
  tmp_fieldcat-f4availabl    = 'X'.
  tmp_fieldcat-ref_field     = ref_f.
  tmp_fieldcat-ref_table     = ref_t.
  APPEND tmp_fieldcat TO rt_fieldcat .
  CLEAR tmp_fieldcat .
ENDFORM.                    " FRM_CATLG_SET
*&---------------------------------------------------------------------*
*&      Form  change
*&---------------------------------------------------------------------*
FORM. change .
  IF go_grid->is_ready_for_input( ) = 0.
    CALL METHOD go_grid->set_ready_for_input
      EXPORTING
        i_ready_for_input = 1.
  ELSE.
    CALL METHOD go_grid->check_changed_data  "把修改的内容更改到内表里
      IMPORTING
        e_valid = l_valid.
    CALL METHOD go_grid->set_ready_for_input
      EXPORTING
        i_ready_for_input = 0.
    CALL METHOD go_grid->refresh_table_display.
  ENDIF.
ENDFORM.                    " change

*&--------------------------------------------------------------------*
*&      Form  f4
*&--------------------------------------------------------------------*
FORM. f4 USING r_fieldname TYPE lvc_fname
              rs_row_no TYPE lvc_s_roid
              rr_event_data TYPE REF TO cl_alv_event_data
              rt_bad_cells TYPE lvc_t_modi.
  FIELD-SYMBOLS: TYPE lvc_t_modi.
  DATA: ls_f4 TYPE lvc_s_modi ,
        t_index LIKE sy-tabix .
  DATA: BEGIN OF return_tab OCCURS 0 .
          INCLUDE STRUCTURE ddshretval .
  DATA: END OF return_tab .
  DATA: BEGIN OF it_csks OCCURS 0 ,
          kokrs LIKE csks-kokrs ,
          kostl LIKE csks-kostl ,
          datbi LIKE csks-datbi ,
        END OF it_csks.
  IF go_grid->is_ready_for_input( ) = 0 .
    rr_event_data->m_event_handled = 'X'.
    EXIT.
  ENDIF .
  IF r_fieldname = 'KOSTL'.
    SELECT kokrs kostl datbi FROM csks INTO TABLE it_csks
    UP TO 20 ROWS .
    IF it_csks[] IS INITIAL .
*      MESSAGE '没有可以选择的项' type 'I'.
      EXIT.
    ENDIF.
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
         EXPORTING
              retfield        = 'KOSTL'  "起作用的字段
              value_org       = 'S'
         TABLES
              value_tab       = it_csks[]
              return_tab      = return_tab
         EXCEPTIONS
              parameter_error = 1
              no_values_found = 2
              OTHERS          = 3.
    ASSIGN rr_event_data->m_data->* TO .
    ls_f4-fieldname = r_fieldname.
    ls_f4-row_id = rs_row_no-row_id.
    IF NOT return_tab IS INITIAL .
      ls_f4-value = return_tab-fieldval .
      APPEND ls_f4 TO .
    ENDIF .
  ENDIF.
  rr_event_data->m_event_handled = 'X'. " 抑制标准的Search Help
ENDFORM.                                                    " F4
*---------------------------------------------------------------------*
*       FORM. set_grid_drdn                                            *
*---------------------------------------------------------------------*
FORM. set_grid_drdn CHANGING ct_fcat TYPE lvc_t_fcat.
  FIELD-SYMBOLS:    TYPE lvc_s_fcat.
  DATA: lt_drdn TYPE lvc_t_drop,
        ls_drdn TYPE lvc_s_drop .
  DATA: BEGIN OF itab_bwart OCCURS 0 ,
          bwart LIKE t156-bwart,
        END OF itab_bwart.
  DEFINE mac_get_drdn.
    ls_drdn-handle  = 4.
    ls_drdn-value   = &1.
    append ls_drdn to lt_drdn.
  END-OF-DEFINITION.
  SELECT bwart INTO TABLE itab_bwart FROM t156.
  LOOP AT itab_bwart.
    mac_get_drdn itab_bwart-bwart.
  ENDLOOP.
  CALL METHOD go_grid->set_drop_down_table
    EXPORTING
      it_drop_down = lt_drdn.
  READ TABLE ct_fcat ASSIGNING
             WITH KEY fieldname = 'BWART'.
  IF sy-subrc EQ 0.
    -drdn_field = 'HANDLE_DRDN'.
    -f4availabl = ''.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'MAIN100'.
  gs_variant-report = sy-repid.
  IF go_grid IS INITIAL.
    CREATE OBJECT go_grid
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    CREATE OBJECT event_receiver.
    SET HANDLER event_receiver->handle_f4 FOR go_grid.
    CALL METHOD go_grid->register_f4_for_fields
      EXPORTING
        it_f4 = gt_f4.
    IF sy-batch IS INITIAL.
      CALL METHOD go_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter.
    ENDIF.
    PERFORM. load_data_into_grid.
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23495244/viewspace-694731/,如需转载,请注明出处,否则将追究法律责任。

下一篇: ALV颜色&按钮
请登录后发表评论 登录
全部评论

注册时间:2010-03-11

  • 博文量
    196
  • 访问量
    168015