1、F-65 生成预制凭证
使用的bapi :
** Check the Document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
**Create the Document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
在使用这个BAPI的时候需要注意原因代码等字段需要通过扩展去传输,这里就需要去使用SE19增强
参考实施是 ACC_DOCUMENT,我这里定义了一个 ZACC_DOCUMENT在他的CHANGE方法里面我们需要去写入如下代码:
DATA:ls_exte TYPE bapiparex. "用于生成预制凭证bapi设定 DATA: wa_extension TYPE bapiparex, ext_value(960) TYPE c, wa_accit TYPE accit, l_ref TYPE REF TO data. FIELD-SYMBOLS: <l_struc> TYPE any, <l_field> TYPE any. SORT c_extension2 BY structure. LOOP AT c_extension2 INTO wa_extension. AT NEW structure. CREATE DATA l_ref TYPE (wa_extension-structure). ASSIGN l_ref->* TO <l_struc>. ENDAT. CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2 wa_extension-valuepart3 wa_extension-valuepart4 INTO ext_value. MOVE ext_value TO <l_struc>. ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO <l_field>. READ TABLE c_accit WITH KEY posnr = <l_field> INTO wa_accit. IF sy-subrc IS INITIAL. MOVE-CORRESPONDING <l_struc> TO wa_accit. MODIFY c_accit FROM wa_accit INDEX sy-tabix. ENDIF. ENDLOOP. "如下计算税额字段也需要在扩展里面去定义才能传输 LOOP AT c_extension2 INTO wa_extension WHERE structure = 'ZSEXTEN'. IF wa_extension-valuepart2 = 'XMWST'. LOOP AT c_accit INTO wa_accit . wa_accit-xmwst = 'X'. MODIFY c_accit FROM wa_accit INDEX sy-tabix TRANSPORTING xmwst. ENDLOOP. ENDIF. ENDLOOP. ”需要注意SET status为2才能生成预制凭证 READ TABLE c_extension2 INTO ls_exte WITH KEY structure = 'ZSEXTEN'. IF sy-subrc = 0. MOVE '2' TO c_acchd-status_new. DELETE c_extension2 INDEX sy-tabix. ENDIF.
遇到问题2是header_txt文本传输不进去,解决方法如下
使用SE24:IF_EX_AC_DOCUMENT,去调整他的方法 CHANGE_INITIAL ,CHANGE_AFTER_CHECK
在上面两个方法里面添加如下代码:
*----------------------------------------------------------------------------------------------------- *about field "HEADER_TXT" in structure "BAPIACHE09" not transferred to field "BKTXT" in table "BKPF" *Add by Torrance 20200330 *--------------------------------------------------------------------------------------------------- DATA: wa_header TYPE acchd. IF sy-xprog NE 'SAPMSSY1'. *---<SAPLBPFC> is for Posting with BAPI: BAPI_ACC_DOCUMENT_POST *---<SAPCNVE > is for Posting(Tax) with BAPI: BAPI_ACC_DOCUMENT_POST *---<SAPMSSY1> is for Test(Check) with BAPI: BAPI_ACC_DOCUMENT_CHECK CLEAR wa_header. wa_header = im_document-header. ex_document-header-bktxt = wa_header-bktxt. CLEAR wa_header. ENDIF.
2、FBV0过账
*check document data
CALL FUNCTION 'ZPRELIMINARY_POSTING_CHECK_ALL'
*post document data
CALL FUNCTION 'ZPRELIMINARY_POSTING_POST_ALL'
原本应该使用PRELIMINARY_POSTING_CHECK_ALL和PRELIMINARY_POSTING_POST_ALL,但是这两个方法在显示界面的时候会去display log,如果在循环里面展现给用户的结果就不友好,所以我复制了这两个标准的function,然后在里面做变更,当我的程序call的时候就不display log
3、删除预制凭证
这里使用了录制BDC的方式
PERFORM bdc_dynpro USING 'SAPMF05V' '0100'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'BDC_CURSOR' 'RF05V-GJAHR'. PERFORM bdc_field USING 'RF05V-BUKRS' 'SR00'. PERFORM bdc_field USING 'RF05V-BELNR' p_belnr. PERFORM bdc_field USING 'RF05V-GJAHR' p_gjahr. PERFORM bdc_dynpro USING 'SAPLF040' '0700'. PERFORM bdc_field USING 'BDC_CURSOR' 'BKPF-XBLNR'. PERFORM bdc_field USING 'BDC_OKCODE' 'BL'. PERFORM bdc_dynpro USING 'SAPLSPO1' '0200'. PERFORM bdc_field USING 'BDC_CURSOR' 'SPOP-OPTION1'. "Button YES PERFORM bdc_field USING 'BDC_OKCODE' 'YES'. PERFORM bdc_field USING 'BDC_OKCODE' 'ENTER'. CALL TRANSACTION 'FBV0' USING bdcdata MODE mode UPDATE 'S'. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = sy-msgid msgnr = sy-msgno msgv1 = sy-msgv1 msgv2 = sy-msgv2 msgv3 = sy-msgv3 msgv4 = sy-msgv4 IMPORTING message_text_output = messtab EXCEPTIONS OTHERS = 4. APPEND messtab.
4、取消过账
*会计凭证冲销前检查
CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_CHECK'
CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'