VF01/VF02/VF03 屏幕加页签增强 & BAPI增强字段赋值
BAPI增强字段赋值
(需求:对销售发票(VBRK/VBRP)做字段增强)
该功能的主要需求点是通过BAPI:BAPI_BILLINGDOC_CREATEMULTIPLE对增强附加字段赋值,该BAPI表参数内有EXTENSIONIN参数用于存放扩展字段,可参考文档
参考文档可得增强字段需在BAPE_SDBILLINGDOC/BAPE_SDBILLINGDOCITEM两个结构中附加,分别对应VBRK/VBRP,传入数据通过参考字段(交货单/交货单行)拼接KEY字段值与原数据关联,EXTENSIONIN赋值时需用lo_bapi_mapping->map_to_bapiparex_single类方法转换为XML格式
给增强字段传值,其它字段传值可参考链接:VF01创建应收单BAPI->BAPI_BILLINGDOC_CREATEMULTIPLE VF02过账BAPI->SD_INVOICE_RELEASE_TO_ACCOUNT - 阿多的阿胖 - 博客园 (cnblogs.com)
FUNCTION zbapi_billingdoc_create. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(CREATORDATAIN) LIKE BAPICREATORDATA STRUCTURE *" BAPICREATORDATA OPTIONAL *" VALUE(TESTRUN) LIKE BAPIVBRKTESTRUN-TESTRUN OPTIONAL *" VALUE(POSTING) TYPE POSTING_TYPE_CT OPTIONAL *" VALUE(IV_KURRF) TYPE KURRF OPTIONAL *" VALUE(IV_ZZYGGH) TYPE ZE_YGGH OPTIONAL *" VALUE(IV_ZZYGXM) TYPE ZE_YGXM OPTIONAL *" TABLES *" BILLINGDATAIN STRUCTURE BAPIVBRK *" CONDITIONDATAIN STRUCTURE BAPIKOMV OPTIONAL *" CCARDDATAIN STRUCTURE BAPICCARD_VF OPTIONAL *" TEXTDATAIN STRUCTURE BAPIKOMFKTX OPTIONAL *" ERRORS STRUCTURE BAPIVBRKERRORS OPTIONAL *" RETURN STRUCTURE BAPIRET1 *" SUCCESS STRUCTURE BAPIVBRKSUCCESS *" EXTENSIONIN STRUCTURE BAPIPAREX OPTIONAL *" PARTNERDATAIN STRUCTURE BAPIVBRKPARNR OPTIONAL *" NFMETALLITMS STRUCTURE /NFM/BAPIDOCITM OPTIONAL *"---------------------------------------------------------------------- DATA: lo_bapi_mapping TYPE REF TO if_cfd_bapi_mapping, lr_header_bapi_ext TYPE REF TO bape_sdbillingdoc, extensionin1 TYPE bapiparextab, lv_key TYPE sdbillingdoc_key, lv_vgbel TYPE vgbel, lv_vgpos TYPE vgpos. EXPORT iv_kurrf = iv_kurrf TO MEMORY ID 'ZBAPI_BILLINGDOC_CREATE'."RV60AFZC "声明对象 CREATE DATA lr_header_bapi_ext. lo_bapi_mapping = cl_cfd_bapi_mapping=>get_instance( ). "赋值 LOOP AT billingdatain. lv_vgbel = billingdatain-ref_doc. lv_vgpos = billingdatain-ref_item. lv_key = lv_vgbel && lv_vgpos. lr_header_bapi_ext->key = lv_key. lr_header_bapi_ext->data-zzyggh = iv_zzyggh. lr_header_bapi_ext->data-zzygxm = iv_zzygxm. "传入增强字段 CALL METHOD lo_bapi_mapping->map_to_bapiparex_single EXPORTING ir_source_structure = lr_header_bapi_ext CHANGING ct_bapiparex = extensionin1. ENDLOOP. CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE' EXPORTING creatordatain = creatordatain testrun = testrun posting = posting TABLES billingdatain = billingdatain conditiondatain = conditiondatain ccarddatain = ccarddatain textdatain = textdatain errors = errors return = return success = success extensionin = extensionin1 partnerdatain = partnerdatain nfmetallitms = nfmetallitms. FREE MEMORY ID 'ZBAPI_BILLINGDOC_CREATE'. ENDFUNCTION.
按照上述方法传入值后,执行BAPI发现并不能写入值,跟踪BAPI程序,发现附加字段值可以带入内表XKOMFKGN但是不能赋值进内表VBRK
用增强赋值的方法手动从XKOMFKGN赋值给VBRK了,通过增强可以实现赋值(VBRP同方法)
详细可参考此链接:[ABAP] VF01/VF02/VF03 发票字段增强总结(BAPI&赋值&屏幕增强)_abap vf02 抬头增强-CSDN博客
屏幕增强
1.附加结构
如果没有上边BAPI赋值的时候给底表加上增强字段,则需要重新从VBRK表->附加结构去加所需增强字段
抬头字段F1->程序名SAPMV60A->6001屏幕->导航
2.创建处理程序
主程序SAPMV60A中的所有包含文件都是以MV60AF打头的,所以我们创建一个独立的程序 SE38(ZSDU0001) 来存放所有的处理代码
创建屏幕9001,确保屏幕类型为子屏幕
屏幕字段可从VBRK表中获取
*&---------------------------------------------------------------------* *& Module PBO_9001 OUTPUT *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* MODULE pbo_9001 OUTPUT. CASE sy-ucomm. WHEN 'VF03'. LOOP AT SCREEN. screen-input = '0'. MODIFY SCREEN. ENDLOOP. ENDCASE. ENDMODULE.
ZSDU0001报表程序代码参考
*&---------------------------------------------------------------------* *& Report ZSDU0001 *&---------------------------------------------------------------------* *&作者:HW *&日期:20240329 *&描述:销售发票屏幕增强程序 *&---------------------------------------------------------------------* REPORT zsdu0001. DATA:badi_active TYPE sap_bool. FORM cust_head_activate USING fvbrk TYPE vbrk fvbuk TYPE vbuk fxvbpa TYPE va_vbpavb_t CHANGING fcaption TYPE char40 fprogram TYPE sy-repid fdynpro TYPE sy-dynnr ftab TYPE char40. PERFORM frm_check_badi_active. CHECK:badi_active EQ abap_false. fcaption = '抬头增强字段'. "页签名称 fprogram = 'ZSDU0001'. fdynpro = '9001'. ftab = fcaption. LOOP AT SCREEN. IF screen-name EQ 'TABSTRIP_TAB06'. screen-active = 1. screen-invisible = 0. MODIFY SCREEN. ENDIF. ENDLOOP. ENDFORM. FORM cust_head_set_data USING f_vbrk TYPE vbrk ft180 TYPE t180 CHANGING fxvbpa TYPE va_vbpavb_t fxyvbrk TYPE vbrkvb_t fxvbrk TYPE vbrkvb_t frv60a TYPE rv60a fxyvbadr TYPE shp_sadrvb_t fxvbadr TYPE shp_sadrvb_t fxyvbpa TYPE va_vbpavb_t fxvbrp TYPE vbrpvb_t fxyvbrp TYPE vbrpvb_t fvbrk TYPE vbrk. PERFORM frm_check_badi_active. CHECK:badi_active EQ abap_false. ENDFORM. FORM cust_head_pass_fcode USING ffcode_same_page TYPE fcode ffcode TYPE fcode. PERFORM frm_check_badi_active. CHECK:badi_active EQ abap_false. ENDFORM. FORM cust_head_get_data USING ft180 TYPE t180 CHANGING fvbrk TYPE vbrk fxvbpa TYPE va_vbpavb_t fxyvbrk TYPE vbrkvb_t fxvbrk TYPE vbrkvb_t frv60a TYPE rv60a fxyvbadr TYPE shp_sadrvb_t fxvbadr TYPE shp_sadrvb_t fxyvbpa TYPE va_vbpavb_t fxvbrp TYPE vbrpvb_t fxyvbrp TYPE vbrpvb_t ffcode TYPE fcode. PERFORM frm_check_badi_active. CHECK:badi_active EQ abap_false. ENDFORM. *&---------------------------------------------------------------------* *& Module PBO_9001 OUTPUT *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* MODULE pbo_9001 OUTPUT. CASE sy-ucomm. WHEN 'VF03'. LOOP AT SCREEN. screen-input = '0'. MODIFY SCREEN. ENDLOOP. ENDCASE. ENDMODULE. *&---------------------------------------------------------------------* *& Form frm_check_badi_active *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_check_badi_active. INCLUDE wb2_param_control_global. DATA:lr_badi TYPE REF TO if_ex_badi_sd_cust_head. CALL FUNCTION 'GET_HANDLE_SD_CUST_HEAD' IMPORTING handle = lr_badi active = badi_active. IF badi_active EQ abap_true. IF cl_wb2_check_add_on_active=>a_gtm_active EQ abap_false. badi_active = abap_false. ENDIF. IF cl_wb2_check_add_on_active=>a_enhance NE addon_all_active. badi_active = abap_false. ENDIF. ENDIF. ENDFORM.
3.屏幕增强
在主程序SAPMV60A 的 屏幕6001中 双击 CUST_HEAD_ACTIVATE 直到对应的FORM
显示隐式增强->创建实施->使用 PERFORM … IN PROGRAM … IF FOUND 创建增强
FORM涉及详细的逻辑代码,在ZSDU0001程序中编写,在上边
ENHANCEMENT 1 ZE_SAPMV60A. "active version PERFORM cust_head_activate IN PROGRAM zsdu0001 IF FOUND USING vbrk vbuk xvbpa[] CHANGING gs_cust_tab-head_caption gs_cust_tab-head_program gs_cust_tab-head_dynpro tabstrip_tab06. ENDENHANCEMENT.
业务加载项BADI_SD_CUST_HEAD的另外三个方法是用在屏幕6101中,建议不管当前是否有使用到,都应当进行增强到程序ZMV60AFZCUST_HEAD中以预留将来可以方便的修改,所有的增强实施都应当使用同一个名称ZE_SAPMV60A,这样我们可以方便地使用SE20查看所有的增强
perform cust_head_set_data->(FORM涉及详细的逻辑代码,在ZSDU0001程序中编写,在上边)ENHANCEMENT 2 ZE_SAPMV60A. "active version PERFORM cust_head_set_data IN PROGRAM zsdu0001 IF FOUND USING vbrk t180 CHANGING xvbpa[] yvbrk[] xvbrk[] rv60a yvbadr[] xvbadr[] yvbpa[] xvbrp[] yvbrp[] vbrk. ENDENHANCEMENT.
perform cust_head_pass_fcode
ENHANCEMENT 3 ZE_SAPMV60A. "active version PERFORM cust_head_pass_fcode IN PROGRAM ZSDU0001 IF FOUND USING fcode_gleiche_seite fcode. ENDENHANCEMENT.
perform cust_head_get_data
ENHANCEMENT 4 ZE_SAPMV60A. "active version PERFORM cust_head_get_data IN PROGRAM zsdu0001 IF FOUND USING t180 CHANGING vbrk xvbpa[] yvbrk[] xvbrk[] rv60a yvbadr[] xvbadr[] yvbpa[] xvbrp[] yvbrp[] fcode. ENDENHANCEMENT.
用VF02修改发票凭证,转到抬头–>抬头增强字段,填写相关的数据并保存,然后检查表VBRK发现增强字段已经保存成功
用VF03查看发票凭证,发现页签是只读格式,创建增强字段成功
以上为抬头屏幕增强,行项目增强在6002屏幕上
可参考链接:屏幕增强 - 3.为发票凭证VF01/2/3增加自定义选项卡 - 《ABAP 开发笔记》 - 极客文档 (geekdaxue.co)
行项目屏幕增强同以上方法,可参考链接:VF01/VF02/VF03销售发票屏幕增强实例_vf01屏幕增强-CSDN博客