ABAP 自定义搜索功能 demo1
效果:
双击选中行则为选中对应发票
实现
1定义
定义屏幕筛选参数
SELECTION-SCREEN BEGIN OF SCREEN 9020.
SELECT-OPTIONS:s1_belnr FOR rbkp-belnr,
s1_gjahr FOR rbkp-gjahr,
s1_lifnr FOR rbkp-lifnr,
s1_erfna FOR rbkp-erfnam,
s1_bldat FOR rbkp-bldat,
s1_bukrs FOR rbkp-bukrs.
PARAMETERS:c_wqr TYPE xfeld.
SELECTION-SCREEN END OF SCREEN 9020.
定义alv显示内表
DATA:BEGIN OF gs_data1,
belnr TYPE rbkp-belnr,
gjahr TYPE rbkp-gjahr,
bldat TYPE rbkp-bldat,
bukrs TYPE rbkp-bukrs,
lifnr TYPE rbkp-lifnr,
name1 TYPE lfa1-name1,
waers TYPE rbkp-waers,
rmwwr TYPE rbkp-rmwwr,
wmwst1 TYPE rbkp-wmwst1,
rbstat TYPE rbkp-rbstat,
trbstat(6),
erfnam TYPE rbkp-erfnam,
sgtxt TYPE rbkp-sgtxt,
zstat TYPE ztmm015h-zstat,
tzstat(6),
zdate TYPE ztmm015h-zdate,
zuser TYPE ztmm015h-zuser,
zdate2 TYPE ztmm015h-zdate2,
zoaid TYPE ztmm015h-zoaid,
END OF gs_data1.
DATA:gt_data1 LIKE TABLE OF gs_data1.
2设置选择帮助触发按钮
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_belnr.
3.设置触发后功能
PERFORM frm_f4_help CHANGING p_belnr p_gjahr.
FORM frm_f4_help CHANGING c_belnr
c_gjahr.
CALL SELECTION-SCREEN 9020 STARTING AT 10 1 ENDING AT 100 10.
IF sy-subrc NE 0.
MESSAGE ‘用户取消选择’ TYPE ‘S’.
EXIT.
ENDIF.
REFRESH:gt_data1.
SELECT
rbkp~belnr
rbkp~gjahr
rbkp~bldat
rbkp~bukrs
rbkp~lifnr
rbkp~waers
rbkp~rmwwr
rbkp~wmwst1
rbkp~rbstat
rbkp~erfnam
rbkp~sgtxt
lfa1~name1
INTO CORRESPONDING FIELDS OF TABLE gt_data1
FROM rbkp
JOIN lfa1 ON rbkp~lifnr EQ lfa1~lifnr
WHERE belnr IN s1_belnr
AND gjahr IN s1_gjahr
AND rbkp~lifnr IN s1_lifnr
AND erfnam IN s1_erfna
AND bldat IN s1_bldat
AND bukrs IN s1_bukrs
AND rbstat IN ( ‘A’,‘5’ ).
IF gt_data1 IS INITIAL.
MESSAGE ‘查询无数据’ TYPE ‘S’ DISPLAY LIKE ‘E’.
EXIT.
ENDIF.
SELECT * INTO TABLE @DATA(lt_ztmm015h)
FROM ztmm015h
FOR ALL ENTRIES IN @gt_data1
WHERE belnr EQ @gt_data1-belnr
AND gjahr EQ @gt_data1-gjahr
AND zstat IN ( ‘2’,‘3’,‘5’ ).
SORT lt_ztmm015h BY belnr gjahr.
LOOP AT gt_data1 INTO gs_data1.
CASE gs_data1-rbstat.
WHEN ‘A’.
gs_data1-trbstat = ‘预制’.
WHEN ‘5’.
gs_data1-trbstat = ‘已过帐’.
WHEN OTHERS.
ENDCASE.
READ TABLE lt_ztmm015h INTO DATA(lw_ztmm015h) WITH KEY belnr = gs_data1-belnr
gjahr = gs_data1-gjahr BINARY SEARCH.
IF sy-subrc = 0.
gs_data1-zstat = lw_ztmm015h-zstat.
CASE gs_data1-zstat.
WHEN '2'.
gs_data1-tzstat = '已确认'.
WHEN '3'.
gs_data1-tzstat = '已发送OA'.
WHEN '5'.
gs_data1-tzstat = 'OA流程已归档'.
WHEN OTHERS.
ENDCASE.
gs_data1-zstat = lw_ztmm015h-zstat.
gs_data1-zdate = lw_ztmm015h-zdate.
gs_data1-zuser = lw_ztmm015h-zuser.
gs_data1-zdate2 = lw_ztmm015h-zdate2.
gs_data1-zoaid = lw_ztmm015h-zoaid.
ENDIF.
MODIFY gt_data1 FROM gs_data1.
ENDLOOP.
IF c_wqr = ‘X’. "只查未确认预制发票
DELETE gt_data1 WHERE zuser <> ‘’.
ENDIF.
************alv
REFRESH gt_fieldcat5.
CLEAR: gw_layout.
gw_layout-cwidth_opt = ‘X’.
gw_layout-zebra = ‘X’.
gw_layout-sel_mode = ‘B’.
DEFINE def_fcat5.
CLEAR: wa_fieldcat.
wa_fieldcat-fieldname = &1.
wa_fieldcat-coltext = &2.
wa_fieldcat-ref_field = &3.
wa_fieldcat-ref_table = &4.
wa_fieldcat-key = &5.
wa_fieldcat-do_sum = &6.
wa_fieldcat-cfieldname = &7.
APPEND wa_fieldcat TO gt_fieldcat5.
END-OF-DEFINITION.
def_fcat5 ‘BUKRS’ ‘公司代码’ ‘BUKRS’ ‘T001’ ‘’ ‘’ ‘’.
def_fcat5 ‘LIFNR’ ‘供应商代码’ ‘LIFNR’ ‘EKKO’ ‘’ ‘’ ‘’.
def_fcat5 ‘NAME1’ ‘供应商名称’ ‘NAME_ORG1’ ‘BUT000’ ‘’ ‘’ ‘’.
def_fcat5 ‘BELNR’ ‘发票’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘GJAHR’ ‘发票年份’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘BLDAT’ ‘凭证日期’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘WAERS’ ‘币种’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘RMWWR’ ‘含税金额’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘WMWST1’ ‘税额’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘TRBSTAT’ ‘发票状态’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘ERFNAM’ ‘发票创建者’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘SGTXT’ ‘发票文本’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘TZSTAT’ ‘付款申请状态’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘ZDATE’ ‘确认日期’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘ZUSER’ ‘确认者’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘ZDATE2’ ‘发送OA日期’ ‘’ ‘’ ‘’ ‘’ ‘’.
def_fcat5 ‘ZOAID’ ‘OA流程单号’ ‘’ ‘’ ‘’ ‘’ ‘’.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
-
I_INTERFACE_CHECK = ' '
-
I_BYPASSING_BUFFER =
-
I_BUFFER_ACTIVE = i_callback_program = sy-repid
-
i_callback_pf_status_set = 'SET_PF_STATUS' i_callback_user_command = 'USER_COMMAND01'
-
I_CALLBACK_TOP_OF_PAGE = ' '
-
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
-
I_CALLBACK_HTML_END_OF_LIST = ' '
-
I_STRUCTURE_NAME =
-
I_BACKGROUND_ID = ' '
-
i_grid_title = gv_title
-
i_grid_settings = gw_settings is_layout_lvc = gw_layout it_fieldcat_lvc = gt_fieldcat5
-
it_excluding = gt_excluding
-
IT_SPECIAL_GROUPS_LVC =
-
TABLESit_sort_lvc = gt_sort i_default = 'X' i_save = 'A'
t_outtab = gt_data1
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
FORM user_command01 USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA g_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = g_grid.
CALL METHOD g_grid->check_changed_data.
READ TABLE gt_data1 INTO gs_data1 INDEX rs_selfield-tabindex.
IF sy-subrc = 0.
p_belnr = gs_data1-belnr.
p_gjahr = gs_data1-gjahr.
LEAVE TO SCREEN 0.
ENDIF.
rs_selfield-refresh = ‘X’.
rs_selfield-col_stable = ‘X’.
rs_selfield-row_stable = ‘X’.
ENDFORM.