【SAP】ABAP——ALV显示字段增加下拉框

背景:报表ALV显示后,需要对某些字段增加下拉框进行修改。

本文为Function ALV的设置,OOALV同理可进行设置。

REPORT  y_test_1030.

TABLES: t001,lfa1,ska1.
TYPE-POOLS:slis.

"付款操作与查询
DATA: BEGIN OF ls_data,
  choose(1),
  belnr LIKE bsik-belnr,"凭证编号
  zuonr LIKE bsik-zuonr,"OA申请单
  ifcas(2),             "是否到达出纳
  ctime(20),            "到达出纳日期
  bukrs LIKE bsik-bukrs,"费用付款公司
  bwart(4),             "费用类别
  lifnr LIKE lfa1-lifnr,"供应商代码
  name1 LIKE lfa1-name1,"供应商名称/收款人
  bankn LIKE lfbk-bankn,"银行代码
  banka LIKE bnka-banka,"支行名称
  banww(20),            "支行联行号
  brnch LIKE bnka-brnch,"收款人银行账号
  waers LIKE bsik-waers,"币种
  wrbtr LIKE bsik-wrbtr,"金额
  purps(50),            "用途
  payst(4),             "付款状态
  ptime(20),  "付款状态更新时间


END OF ls_data.
DATA: lt_data LIKE TABLE OF ls_data.

"LAV显示参数
DATA:
  ls_layout   TYPE lvc_s_layo,
  ls_fieldcat TYPE lvc_s_fcat,
  lt_fieldcat TYPE lvc_t_fcat,
  ls_event    TYPE slis_alv_event,
  lt_event    TYPE slis_t_event.

DATA: ls_ddval TYPE lvc_s_drop,
      lt_ddval TYPE lvc_t_drop.

SELECT-OPTIONS:
  s_bukrs FOR t001-bukrs ,
  s_lifnr FOR lfa1-lifnr ,
  s_aedat FOR sy-datum OBLIGATORY.

DEFINE fieldcat.
  ls_fieldcat-fieldname = &1.
  ls_fieldcat-scrtext_l = &2.
  ls_fieldcat-no_zero   = &3.
  ls_fieldcat-edit      = &4.
  ls_fieldcat-drdn_hndl = &5.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM build_alv.
  PERFORM create_dropdown_values."获取下拉菜单的值
  PERFORM create_event.
  PERFORM diaplay_alv.

FORM get_data .
  SELECT  bsik~belnr
          bsik~zuonr
          bsik~bukrs
          bsik~waers
          bsik~wrbtr
          lfa1~lifnr
          lfa1~name1
          lfbk~bankn
          bnka~banka
          bnka~brnch
    INTO CORRESPONDING FIELDS OF TABLE lt_data
    FROM bsik
    INNER JOIN lfa1 ON bsik~lifnr = lfa1~lifnr
    INNER JOIN lfbk ON lfa1~lifnr = lfbk~lifnr
    INNER JOIN bnka ON lfbk~bankn = bnka~bankl
    WHERE bsik~lifnr IN s_lifnr
      AND bsik~bukrs IN s_bukrs.
ENDFORM.  

FORM build_alv .
  ls_layout-zebra = 'X'.
  ls_layout-box_fname = 'CHOOSE'.

  fieldcat 'BELNR' '凭证编号' 'X' '' ''.
  fieldcat 'ZUONR' 'OA申请单号' '' '' ''.
  fieldcat 'IFCAS' '是否到达出纳' '' '' ''.
  fieldcat 'CTIME' '到达出纳时间' '' '' ''.
  fieldcat 'BWART' '费用类别' '' '' ''.
  fieldcat 'BUKRS' '费用付款公司' '' '' ''.
  fieldcat 'LIFNR' '供应商代码' 'X' '' ''.
  fieldcat 'NAME1' '供应商名称' '' '' ''.
  fieldcat 'BANKN' '银行代码' '' '' ''.
  fieldcat 'BANKA' '支行名称' '' '' ''.
  fieldcat 'BANWW' '支行联行号' '' '' ''.
  fieldcat 'BRNCH' '收款人银行账号' '' '' ''.
  fieldcat 'WAERS' '币种' '' '' ''.
  fieldcat 'WRBTR' '金额' '' '' ''.
  fieldcat 'PURPS' '用途' '' '' ''.
  fieldcat 'PAYST' '付款状态' '' 'X' '1'.
  fieldcat 'PTIME' '付款状态更新时间' '' '' ''.

ENDFORM. 
 
FORM create_dropdown_values.
  LS_DDVAL-HANDLE = '1'.
  ls_ddval-VALUE  = '待提交'.
  APPEND LS_DDVAL TO LT_DDVAL.

  LS_DDVAL-HANDLE = '1'.
  ls_ddval-VALUE  = '提交成功'.
  APPEND LS_DDVAL TO LT_DDVAL.
ENDFORM.     

FORM create_event.
  ls_event-name = 'CALLER_EXIT'.
  ls_event-form = 'CALLER_EXIT'.
  APPEND ls_event TO lt_event.
ENDFORM. 

FORM caller_exit USING r_grid TYPE slis_data_caller_exit.
  DATA:l_ref_alv TYPE REF TO cl_gui_alv_grid.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = l_ref_alv.

  CALL METHOD l_ref_alv->set_drop_down_table
    EXPORTING
      it_drop_down = lt_ddval.
ENDFORM. 
 
FORM diaplay_alv .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
   EXPORTING
     i_callback_program                = sy-repid
     i_callback_pf_status_set          = 'SET_PF_STATUS'
     i_callback_user_command           = 'USER_COMMAND'
     is_layout_lvc                     = ls_layout
     it_fieldcat_lvc                   = lt_fieldcat
     it_events                         = lt_event
    TABLES
      t_outtab                          = lt_data  .

ENDFORM. 

FORM set_pf_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'PF_1' EXCLUDING rt_extab.
ENDFORM.

FORM user_command  USING r_ucomm LIKE sy-ucomm
                         rs_selfield TYPE slis_selfield.
  CASE sy-ucomm.
    WHEN '&DATA_SAVE'.

    WHEN OTHERS.
  ENDCASE.

ENDFORM.  

 

你可能感兴趣的:(【SAP】ABAP——ALV显示字段增加下拉框)