(1) 复制函数SAMPLE_INTERFACE_RWBAPI01为Z SAMPLE_INTERFACE_RWBAPI01
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" IT_ACCIT STRUCTURE ACCIT
*" IT_ACCCR STRUCTURE ACCCR
*" RETURN STRUCTURE BAPIRET2
*" EXTENSION STRUCTURE BAPIACEXTC
*" IT_ACCWT STRUCTURE ACCIT_WT
*" CHANGING
*" VALUE(DOCUMENT_HEADER) LIKE ACCHD STRUCTURE ACCHD
*"----------------------------------------------------------------------
if sy-uname = 'ZHANGDQ'.
LOOP AT EXTENSION.
loop at IT_ACCIT .
IT_ACCIT-RSTGR = EXTENSION-FIELD1.
MODIFY IT_ACCIT .
endloop.
ENDLOOP.
endif.
ENDFUNCTION.
只是测试,所以我只针对我的用户有效。
(2) FIBF业务交易事件设置
菜单栏
设置-》处理函数模块-》SAP的一个应用程序
修改视图 每处理界面的应用函数模块:总览
处理 Ctr 应用 函数模块
CACS3003 IS-CS CACS_HR_FIND_EMPLOYEE
CACS8001 EA-ICM CACS_SAP00_PRC_8001
RWBABI01 ZSAMPLE_INTERFACE_RWBAPI01
(3) 程序调用BAPI: BAPI_ACC_DOCUMENT_POST
*&---------------------------------------------------------------------*
*& Report ZFR_GL_DOCUMENT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------* REPORT zfr_gl_document. DATA: gt_docheader LIKE TABLE OF bapiache09 WITH HEADER LINE,
gt_accountgl LIKE TABLE OF bapiacgl09 WITH HEADER LINE,
gt_acccust LIKE TABLE OF bapiacar09 WITH HEADER LINE,
gt_amount LIKE TABLE OF bapiaccr09 WITH HEADER LINE,
gt_extension LIKE TABLE OF bapiacextc WITH HEADER LINE,
gt_return LIKE TABLE OF bapiret2 WITH HEADER LINE. DATA: gv_post_doc LIKE bapiache09-obj_key. PERFORM fill_header. * Fill in gl
PERFORM fill_gl.
PERFORM fill_amount. gt_EXTENSION-FIELD1 = 'A01'.
APPEND gt_EXTENSION.
CLEAR gt_EXTENSION. CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = gt_docheader
TABLES
accountgl = gt_accountgl
currencyamount = gt_amount
extension1 = gt_extension
return = gt_return. READ TABLE gt_return WITH KEY type = 'E'. IF sy-subrc <> .
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = gt_docheader
IMPORTING
obj_key = gv_post_doc
TABLES
accountgl = gt_accountgl
currencyamount = gt_amount" accountpayable = gt_accpay
EXTENSION1 = gt_EXTENSION
return = gt_return.
COMMIT WORK AND WAIT. WRITE: 'Posting Document: ', gv_post_doc.
ELSE.
WRITE: 'Error!'.
ENDIF. *&---------------------------------------------------------------------*
*& Form fill_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_header .
CLEAR gt_docheader.
gt_docheader-doc_date = sy-datum.
gt_docheader-pstng_date = sy-datum.
* gt_docheader-obj_type = 'IDOC'.
* gt_docheader-obj_key = '$'.
* gt_docheader-obj_sys = 'BGS1'.
gt_docheader-bus_act = 'RFBU'.
gt_docheader-username = sy-uname.
gt_docheader-header_txt = 'Header Text'.
gt_docheader-ref_doc_no = 'Reference Doc No'.
gt_docheader-comp_code = ''.
gt_docheader-doc_type = 'SA'.
APPEND gt_docheader.
ENDFORM. " fill_header *&---------------------------------------------------------------------*
*& Form fill_amount
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_amount .
gt_amount-itemno_acc = ''.
gt_amount-currency = 'RMB'.
gt_amount-amt_doccur = .
APPEND gt_amount. gt_amount-itemno_acc = ''.
gt_amount-currency = 'RMB'.
gt_amount-amt_doccur = -.
APPEND gt_amount.
ENDFORM. " fill_amount *&---------------------------------------------------------------------*
*& Form fill_gl
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_gl .
CLEAR gt_accountgl.
gt_accountgl-gl_account = ''.
gt_accountgl-itemno_acc = ''.
gt_accountgl-item_text = 'Item Text'.
gt_accountgl-bus_area = ''.
gt_accountgl-profit_ctr = ''.
gt_accountgl-costcenter = ''.
gt_accountgl-comp_code = ''.
gt_accountgl-alloc_nmbr = ''.
gt_accountgl-COSTCENTER = ''.
APPEND gt_accountgl.
CLEAR gt_accountgl. gt_accountgl-gl_account = ''.
gt_accountgl-itemno_acc = ''.
gt_accountgl-item_text = 'Item Text'.
gt_accountgl-bus_area = ''.
gt_accountgl-profit_ctr = ''.
gt_accountgl-costcenter = ''.
gt_accountgl-comp_code = ''.
gt_accountgl-alloc_nmbr = ''.
gt_accountgl-COSTCENTER = ''.
APPEND gt_accountgl.
CLEAR gt_accountgl. ENDFORM. " fill_gl
(4) 查看运行结果
(5) 1