如何在cl gui alv grid设置list列表

               

在进行OO Grid编程时,用户常需要使用下拉列表来选择输入,其方法步骤如下:

1、创建内表,在内表增加一下字段
         handle_drdn          type lvc_s_drop-handle,

2、创建GRID
    if cl_gui_alv_grid=>offline( ) is initial.
      create object gr_container_d0100
                    exporting container_name = 'D0100_CONTAINER'.
    endif.

    create object gr_grid_d0100
                  exporting i_parent = gr_container_d0100.

3、设置字段显示格式
 ct_fcat type lvc_t_fcat.
 data: ls_fcat type lvc_s_fcat,
 l_lin   type i.
 clear ls_fcat.
  ls_fcat-tabname   = '1'.
  ls_fcat-fieldname = 'DROPDOWN_F4'.
  ls_fcat-inttype   = 'I'.
  ls_fcat-intlen    = 10.
  ls_fcat-col_pos   = l_lin.
  ls_fcat-scrtext_s = ls_fcat-fieldname.
  ls_fcat-scrtext_m = ls_fcat-fieldname.
  ls_fcat-scrtext_l = ls_fcat-fieldname.
  append ls_fcat to ct_fcat.

4、设置下拉列表数据(本代码是设置'DROPDOWN_F4'为下拉列表)
form d0100_set_grid_drdn changing ct_fcat type lvc_t_fcat.

  field-symbols: <ls_outtab> type g_ty_s_outtab,
                 <ls_fcat>   type lvc_s_fcat.

  data: lt_drdn type lvc_t_drop,                            "#EC NEEDED
        ls_drdn type lvc_s_drop,                            "#EC NEEDED
        lt_dral type lvc_t_dral,                            "#EC NEEDED
        ls_dral type lvc_s_dral,                            "#EC NEEDED
        l_count type i.

  define mac_get_drdn.
    ls_drdn-handle  = 1.  "列表对象句柄
    ls_drdn-value   = &1. "列表显示的值
    append ls_drdn to lt_drdn.

    add 1 to l_count.
    ls_dral-handle    = 1."列表对象句柄
    ls_dral-value     = &1. "列表显示的值
    write l_count to ls_dral-int_value left-justified. " "选择输入的显示的值
    append ls_dral to lt_dral.
  end-of-definition.

  mac_get_drdn 'http://www.aa.com'.
  mac_get_drdn 'http://www.airberlin.com'.
  mac_get_drdn 'http://www.aircanda.ca'.
  mac_get_drdn 'http://www.airfrance.ca'.
  mac_get_drdn 'http://www.alitalia.it'.
  mac_get_drdn 'http://www.british-airways.com'.
  mac_get_drdn 'http://www.continental.com'.
  mac_get_drdn 'http://www.delta-air.com'.
  mac_get_drdn 'http://www.airpacific.com'.
  mac_get_drdn 'http://www.jal.co.jp'.
  mac_get_drdn 'http://www.lufthansa.com'.
  mac_get_drdn 'http://www.laudaair.com'.
  mac_get_drdn 'http://www.nwa.com'.
  mac_get_drdn 'http://www.gantas.com.au'.
  mac_get_drdn 'http://www.saa.co.za.de'.
  mac_get_drdn 'http://www.singaporeair.com'.
  mac_get_drdn 'http://www.swissair.com'.
  mac_get_drdn 'http://www.ual.com'.

  call method gr_grid_d0100->set_drop_down_table
    exporting
      it_drop_down_alias = lt_dral.   "该调用将列出描叙,自动转换为输入ID值

*  call method gr_grid_d0100->set_drop_down_table
*    exporting
*      it_drop_down = lt_drdn.   "该列表选择

    read table ct_fcat assigning <ls_fcat>
               with key fieldname = 'DROPDOWN_F4'.
    if sy-subrc eq 0.
      <ls_fcat>-drdn_field = 'HANDLE_DRDN'.
      <ls_fcat>-edit = 'X'.
      <ls_fcat>-drdn_alias = con_true.
    endif.

    loop at gt_outtab assigning <ls_outtab>.
      <ls_outtab>-handle_drdn = 1."设置字段列表控制句柄,和上面list表对应上
    endloop.

endform.                    " d0100_set_grid_drdn 

5、输出数据
    call method gr_grid_d0100->set_table_for_first_display
      exporting
        i_buffer_active     = gs_test-buffer_active
        i_bypassing_buffer  = gs_test-bypassing_buffer
        i_consistency_check = l_consistency_check
        is_variant          = ls_vari
        i_save              = 'A'
        i_default           = con_true
        is_layout           = ls_layo
        is_print            = ls_prnt
        it_hyperlink        = lt_hype
      changing
        it_outtab           = gt_outtab[]
        it_fieldcatalog     = lt_fcat.

参考sap代码:BCALV_TEST_GRID_EDITABLE

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

*&---------------------------------------------------------------------* *& Report YTEST31 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT YTEST31. DATA: OK_CODE TYPE SY-UCOMM, SAVE_OK TYPE SY-UCOMM. TABLES SPFLI. DATA LS_SPFLI TYPE SPFLI. DATA WA_SPFLI TYPE TABLE OF SPFLI. DATA WADEL_SPFLI TYPE TABLE OF SPFLI. SELECT * INTO TABLE WA_SPFLI FROM SPFLI. DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA', ALV_GRID TYPE REF TO CL_GUI_ALV_GRID, WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. DATA WA_LAYOUT TYPE LVC_S_LAYO. WA_LAYOUT-EDIT = 'X'. CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED. DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER. ************************************************************************ * CLASS LCL_EVENT_RECEIVER DEFINITION * * * ************************************************************************ CLASS LCL_EVENT_RECEIVER DEFINITION. PUBLIC SECTION. TYPES: DEL_ROWS TYPE STANDARD TABLE OF SPFLI. DATA: DDEL_ROWS TYPE STANDARD TABLE OF SPFLI. METHODS: HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID IMPORTING ER_DATA_CHANGED. METHODS: UPDATE_DELTA_TABLES IMPORTING PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL. METHODS: GET_DELETED_ROWS EXPORTING DELETED_ROWS TYPE DEL_ROWS. ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION *&-------------------------------------------------------------------------- *& CLASS LCL_EVENT_RECEIVER IMPLENTMENTATION *& *&-------------------------------------------------------------------------- CLASS LCL_EVENT_RECEIVER IMPLEMENTATION. METHOD HANDLE_DATA_CHANGED. CALL METHOD UPDATE_DELTA_TABLES( ER_DATA_CHANGED ). ENDMETHOD. "HANDLE_DATA_CHANGED METHOD UPDATE_DELTA_TABLES. "HANDLE_DATA_CHANGED DATA: L_DEL_ROW TYPE LVC_S_MOCE. LOOP AT PR_DATA_CHANGED->MT_DELETED_ROWS INTO L_DEL_ROW. READ TABLE WA_SPFLI INTO LS_SPFLI INDEX L_DEL_ROW-ROW_ID. IF SY-SUBRC NE 0. MESSAGE E208(00) WITH '?理??'. ELSE. APPEND LS_SPFLI TO DDEL_ROWS. ENDIF. ENDLOOP. ENDMETHOD. "UPDATE_DELTA_TABLES METHOD GET_DELETED_ROWS. "update_delta_tables DELETED_ROWS = ME->DDEL_ROWS. ENDMETHOD. "GET_DELETED_ROWS ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION START-OF-SELECTION. CALL SCREEN 100. WRITE / '?除的内表??'. "get_deleted_rows WRITE / '______________'. "LCL_EVENT_RECEIVER DEFINITION CALL METHOD EVENT_RECEIVER->GET_DELETED_ROWS IMPORTING DELETED_ROWS = WADEL_SPFLI. LOOP AT WADEL_SPFLI INTO SPFLI. WRITE: / SPFLI-CARRID,SPFLI-CONNID,SPFLI-CITYFROM. ENDLOOP. WRITE: / '更新后的内表??:'. WRITE: / '__________________'. LOOP AT WA_SPFLI INTO SPFLI. WRITE : / SPFLI-CARRID,SPFLI-CONNID,SPFLI-CITYFROM. ENDLOOP. *此?是更新到数据?的操作 *WHEN 'SAVE'. * MODIFY SPFLI FORM TABLE WA_SPFLI. * IF SY-SUBRC NE 0. *MESSAGE I005(YMESS) WITH '更新数据??!'. EXIT. * ELSE. * MESSAGE I005(YMESS) WITH '更新数据OK!'. * ENDIF. * DELETE SPFLI FROM TABLE DELA_SPFLI. * IF SY-SUBRC NE 0. * MESSAGE I005(YMESS) WITH '更新数据??!'. * ELSE. * MESSAGE I005(YMESS) WITH '更新数据OK!'. * ENDIF. END-OF-SELECTION. INCLUDE YTEST31_STATUS_100. INCLUDE YTEST31_USER_COMMAND_100.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值