清帐函数的使用
最近需要做一个清帐程序,SAP没有清帐的BAPI,但是提供了清帐的一组函数:
POSTING_INTERFACE_START;
POSTING_INTERFACE_CLEARING;
POSTING_INTERFACE_END ;
这边着重说明一下函数POSTING_INTERFACE_CLEARING的传值
栗子:
发票校验产生的应收凭证需要转成预收,然后清掉应付。
A凭证 借:费用
贷:应付暂估
B凭证 借:应付暂估
借:应缴增值税
贷:应付
C凭证 借: 预收
贷:费用
A和B 可以清掉应付暂估
C凭证的产生可以直接同时把应付清掉
这边主要说明C凭证的产生。
FB05是清帐事物代码:
T_FTPOST的值是产生清帐 并生成预收凭证C的 抬头字段和项目字段值:
输入的值如同
FB05的
T_FTCLEAR的值是需要清的凭证,展开如下,是要清掉会计凭证9511007857,如果需要清多个凭证需要填多个
相当于FB05的
点击FB05模拟
SE37里面执行 POSTING_INTERFACE_CLEARING 可以debug看到FB05的界面
注意:给T_FTPOST传值的时候金额需要去前面的空格,千万不要对每一个字段都去空格,不然会带不到FB05的行项目上,这几天由于对每个字段都去空格,测了老半天的错误才查出来,折腾死。
如果生成的清帐凭证是一个没有行项目的凭证:
参数:T_FTCLEAR: 传入的是所要清帐的内容比如清供应商的应付行项目
参数:T_FTPOST 是要生成的SH清帐凭证的抬头
参数:I_AUGLV : UMBUCHNG
I_TCODE: FB05
I_SGFUNCT:C 这边不知道除了传C还可以传什么
这边贴一段代码:清帐产生没有行项目的凭证:
1 FORM frm_create_sh USING p_haeder TYPE zfis011 2 pt_list TYPE zfit009 3 CHANGING pt_return TYPE zfit010. 4 5 DATA: lt_list TYPE zfit009, 6 ls_list TYPE zfis009, 7 wa_list TYPE zfis009, 8 lt_return TYPE zfit010, 9 ls_return TYPE zfis010, 10 lv_itemno TYPE posnr_acc. 11 12 DATA lv_message TYPE bapiret2-message. 13 DATA: lv_msgid LIKE sy-msgid, 14 lv_msgno LIKE sy-msgno, 15 lv_msgty LIKE sy-msgty, 16 lv_msgv1 LIKE sy-msgv1, 17 lv_msgv2 LIKE sy-msgv2, 18 lv_msgv3 LIKE sy-msgv3, 19 lv_msgv4 LIKE sy-msgv4, 20 lv_subrc LIKE sy-subrc. 21 22 DATA: lt_blntab LIKE TABLE OF blntab WITH HEADER LINE, 23 lt_ftclear LIKE TABLE OF ftclear WITH HEADER LINE, 24 lt_ftpost LIKE TABLE OF ftpost WITH HEADER LINE, 25 lt_fttax LIKE TABLE OF fttax WITH HEADER LINE. 26 27 28 lt_list = pt_list. 29 lt_return = pt_return. 30 SORT lt_return BY group blart. 31 DELETE lt_list WHERE flag = ' '. 32 REFRESH:lt_ftclear,lt_ftpost. 33 LOOP AT lt_list INTO ls_list. 34 35 *--需要清帐的凭证和供应商 36 READ TABLE lt_return INTO ls_return WITH KEY group = ls_list-group 37 blart = 'KR' BINARY SEARCH. 38 IF sy-subrc = 0. 39 CLEAR lt_ftclear. 40 lt_ftclear-agkoa = 'K'. 41 lt_ftclear-agkon = ls_list-kunnr. 42 lt_ftclear-agbuk = p_haeder-bukrs. 43 lt_ftclear-xnops = 'X'. 44 lt_ftclear-selfd = 'BELNR'. 45 lt_ftclear-selvon = ls_return-belnr. 46 APPEND lt_ftclear. 47 ENDIF. 48 49 READ TABLE lt_return INTO ls_return WITH KEY group = ls_list-group 50 blart = 'DY' BINARY SEARCH. 51 IF sy-subrc = 0. 52 CLEAR lt_ftclear. 53 lt_ftclear-agkoa = 'K'. 54 lt_ftclear-agkon = ls_list-kunnr. 55 lt_ftclear-agbuk = p_haeder-bukrs. 56 lt_ftclear-xnops = 'X'. 57 lt_ftclear-selfd = 'BELNR'. 58 lt_ftclear-selvon = ls_return-belnr. 59 APPEND lt_ftclear. 60 ENDIF. 61 62 *--清帐凭证抬头 63 CLEAR lt_ftpost. 64 lt_ftpost-stype = 'K'. 65 lt_ftpost-fnam = 'BKPF-BLDAT'. 66 lt_ftpost-fval = sy-datum. 67 APPEND lt_ftpost. 68 69 CLEAR lt_ftpost. 70 lt_ftpost-stype = 'K'. 71 lt_ftpost-fnam = 'BKPF-BLART'. 72 lt_ftpost-fval = 'SH'. 73 APPEND lt_ftpost. 74 75 CLEAR lt_ftpost. 76 lt_ftpost-stype = 'K'. 77 lt_ftpost-fnam = 'BKPF-BUKRS'. 78 lt_ftpost-fval = p_haeder-bukrs. 79 APPEND lt_ftpost. 80 81 CLEAR lt_ftpost. 82 lt_ftpost-stype = 'K'. 83 lt_ftpost-fnam = 'BKPF-BUDAT'. 84 lt_ftpost-fval = sy-datum. 85 APPEND lt_ftpost. 86 87 CLEAR lt_ftpost. 88 lt_ftpost-stype = 'K'. 89 lt_ftpost-fnam = 'BKPF-WAERS'. 90 lt_ftpost-fval = 'RMB'. 91 APPEND lt_ftpost. 92 ENDLOOP. 93 94 *--开始清帐 95 CALL FUNCTION 'POSTING_INTERFACE_START' 96 EXPORTING 97 i_client = sy-mandt 98 i_function = 'C' 99 i_mode = 'N' "不显示调用屏幕 100 i_update = 'S' "同步 101 i_user = sy-uname. 102 103 104 CLEAR:lv_msgid,lv_msgno,lv_msgty,lv_msgv1, 105 lv_msgv2,lv_msgv3,lv_msgv4,lv_subrc,lv_message. 106 CALL FUNCTION 'POSTING_INTERFACE_CLEARING' 107 EXPORTING 108 i_auglv = 'UMBUCHNG' 109 i_tcode = 'FB05' 110 i_sgfunct = 'C' 111 IMPORTING 112 e_msgid = lv_msgid 113 e_msgno = lv_msgno 114 e_msgty = lv_msgty 115 e_msgv1 = lv_msgv1 116 e_msgv2 = lv_msgv2 117 e_msgv3 = lv_msgv3 118 e_msgv4 = lv_msgv4 119 e_subrc = lv_subrc 120 TABLES 121 t_blntab = lt_blntab 122 t_ftclear = lt_ftclear 123 t_ftpost = lt_ftpost 124 t_fttax = lt_fttax. 125 CLEAR lv_message. 126 MESSAGE ID lv_msgid 127 TYPE lv_msgty 128 NUMBER lv_msgno 129 WITH lv_msgv1 lv_msgv2 lv_msgv3 lv_msgv4 130 INTO lv_message. 131 CLEAR ls_return. 132 133 *---记录清帐产生的凭证号 134 READ TABLE lt_blntab INDEX 1. 135 ls_return-blart = 'SH'. 136 ls_return-bukrs = lt_blntab-bukrs. 137 ls_return-belnr = lt_blntab-belnr. 138 ls_return-gjahr = lt_blntab-gjahr. 139 IF lv_subrc = 0. 140 ls_return-flag = 'S'. 141 ELSE. 142 ls_return-flag = 'E'. 143 ENDIF. 144 ls_return-message = lv_message. 145 APPEND ls_return TO pt_return. 146 CALL FUNCTION 'POSTING_INTERFACE_END' 147 EXCEPTIONS 148 session_not_processable = 1 149 OTHERS = 2. 150 151 152 ENDFORM. " FRM_CREATE_SH