Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7203150
  • 博文数量: 655
  • 博客积分: 10264
  • 博客等级: 上将
  • 技术积分: 8278
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-04 17:47
个人简介

ABAP顾问

文章分类

全部博文(655)

文章存档

2017年(2)

2014年(8)

2013年(3)

2012年(2)

2011年(18)

2010年(102)

2009年(137)

2008年(274)

2007年(134)

分类:

2007-07-19 11:24:34

 
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
阅读(7966) | 评论(5) | 转发(1) |
给主人留下些什么吧!~~

chinaunix网友2011-01-11 13:11:06

肯定是自己創建的噻

chinaunix网友2011-01-11 12:38:22

CALL SCREEN '100' 这段代码的100屏幕是哪里来的?是事先创建好的吗?我把上面代码拷贝运行出现错误哦。

chinaunix网友2008-04-02 21:46:36

好资料 顶

qdbarry2008-01-10 15:41:11

不记得是不是这样做过,但是不建议使用FM的ALV进行交互式的Report开发,换CLASS方式的吧!也不麻烦

yangzhi5202008-01-10 10:39:37

在FM中如何用F4和LIST呢?!!!