1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
FORM frm_create_ab. *目的:财务分别做预收款和开billing,需要后续做清账对冲DZ和RV. *逻辑:由于只需要模拟人工F-32做清账,只需要根据XBLNR找到借贷方进行对冲即可,因此程序非常简单,核心传递的值为it_ftclear-selfd. *由于VF01开票中已经做了拆分增强,所以billing的金额和DZ的金额是无法对应上的,因此无法采用标准自动清账配置,必须开发实现。 *函数:POSTING_INTERFACE_CLEARING. *POSTING_INTERFACE_CLEARING并非纯函数,本质上是call bdc. *examples: http://www.se80.co.uk/sapfms/p/post/posting_interface_clearing.htm * https://blogs.sap.com/2013/06/11/fb05-through-fm-postinginterfaceclearing/ * https://archive.sap.com/discussions/thread/1873193 * https://archive.sap.com/discussions/thread/2005974 * http://blog.csdn.net/chfeijj/article/details/51443437 * http://blog.csdn.net/zhongguomao/article/details/50214341 *清账逻辑:取出RV、DZ、DG,将XBLNR字段相同的行组合在一起,清账. *处理异常,事务代码:F-32. *重点需要解决的两个问题:1. 清账函数的使用; * 2. 清账数据的准备(按照公司业务逻辑). DATA: it_blntab TYPE TABLE OF blntab WITH HEADER LINE, it_ftclear TYPE TABLE OF ftclear WITH HEADER LINE, it_ftpost TYPE TABLE OF ftpost WITH HEADER LINE, it_fttax TYPE TABLE OF fttax WITH HEADER LINE. DATA: lt_bsad_clearing TYPE TABLE OF bsad WITH HEADER LINE. "客户未清项表. DATA: lt_kunnr TYPE TABLE OF zthy_ecc_kunnr WITH HEADER LINE. DATA: lv_ftclear_agbuk TYPE bukrs. "清账公司代码. "仅电商平台用自动清账程序,其他平台人工处理. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_kunnr FROM zthy_ecc_kunnr. "每次处理一个客户的清账业务. *宏. *SELFD = Field Name from the Document Index *SELVON = Input Field for Search Criterion for Selecting Open Items. DEFINE populate_ftclear. it_ftclear-agkoa = &1. "科目类型,based on account type, Vendor or Customer for Out Going / Incoming Payments. it_ftclear-agbuk = &2. "公司代码. it_ftclear-xnops = 'X'. "标准未清项目. it_ftclear-AGUMS = 'A'. "特别总账未清项目. it_ftclear-selfd = 'XBLNR'. "凭证索引中的字段名(使用该字段搜索用来做对冲的借贷方). it_ftclear-selvon = &3. "Input Field for Search Criterion for Selecting Open Items. append it_ftclear. END-OF-DEFINITION. DEFINE populate_ftpost. it_ftpost-stype = &1. "K为header,P为item. it_ftpost-count = &2. "凭证抬头或行项目的计数器(记帐界面). it_ftpost-fnam = &3. "BDC 字段名. it_ftpost-fval = &4. "BDC 字段值. append it_ftpost. END-OF-DEFINITION. *1.Start of call transaction: SHDB. CALL FUNCTION 'POSTING_INTERFACE_START' EXPORTING i_client = sy-mandt i_function = 'C' "B= BDC, C= Call Trans. i_mode = 'N' "N – no screen, A – all screen, E – Error –> Mode we use in Call transaction i_update = 'S' "S: 数据更新完成后执行下一个操作 i_keep = 'X' "用于已处理会话的队列删除标志. i_user = sy-uname EXCEPTIONS client_incorrect = 1 function_invalid = 2 group_name_missing = 3 mode_invalid = 4 update_invalid = 5 OTHERS = 6. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. *2.Fill data for SHDB. "调用两次,一次借方,一次贷方. populate_ftclear 'D' '1000' 'SA00012090'. *每执行一次添加一条清账行项目. *如果借贷方分录不是正好等于两条,则应使用loop追加清账条目. populate_ftpost: 'K' 1 'BKPF-BUKRS' '1000', 'K' 1 'BKPF-BLART' 'AB', 'K' 1 'BKPF-BLDAT' sy-datum, 'K' 1 'BKPF-BUDAT' sy-datum, 'K' 1 'BKPF-XBLNR' 'SA00012090', "清账参考号. 'K' 1 'BKPF-WAERS' 'CNY'. **由于根据参考号(XBLNR)自动搜索清账的方式进行清账,因此行项目级别均不需要传值. ** 'P' 1 'RF05A-NEWBS' '17', * 'P' 1 'RF05A-NEWBS' '18', "通过FB05进行预收和应收对冲清账时,记账码为18(手工做F-32为17) * 'P' 1 'RF05A-NEWUM' '', "Special G/L indicator. ** 'P' 1 'BSEG-HKONT' '0011220001', * 'P' 1 'BSEG-KUNNR' '0011000000', "统驭科目. ** 'P' 1 'BSEG-WRBTR' '347.09', "程序根据搜索条件自动搜出金额,无需指定. * 'P' 1 'BSEG-ZFBDT' sy-datum, * 'P' 1 'BSEG-SGTXT' '清账测试'. * populate_ftpost: 'K' 2 'BKPF-BUKRS' '1000', 'K' 2 'BKPF-BLART' 'AB', 'K' 2 'BKPF-BLDAT' sy-datum, 'K' 2 'BKPF-BUDAT' sy-datum, 'K' 2 'BKPF-XBLNR' 'SA00012090', "清账参考号. 'K' 2 'BKPF-WAERS' 'CNY'. **由于根据参考号(XBLNR)自动搜索清账的方式进行清账,因此行项目级别均不需要传值. * 'P' 2 'RF05A-NEWBS' '09', * 'P' 2 'RF05A-NEWUM' 'A', "Special G/L indicator. ** 'P' 2 'BSEG-HKONT' '0022030001', * 'P' 2 'BSEG-KUNNR' '0011000000', "统驭科目. ** 'P' 2 'BSEG-WRBTR' '347.09', "程序根据搜索条件自动搜出金额,无需指定. * 'P' 2 'BSEG-ZFBDT' sy-datum, * 'P' 2 'BSEG-SGTXT' '清账测试'. *SE16查询表BSAD按BUKRS、AUGBL、GJAHR查询,可查询到清账凭证行及原始行信息. *3.Process BDC. *每次只能传入一个清账分录. *AUGLV Purpose *AUSGZAHL Outgoing payment *EINGZAHL Incoming payment *GUTSCHRI Credit memo(W为承兑汇票,可能比较特殊) *UMBUCHNG Transfer posting with clearing *Note the following : *--------------------------------------- *The data is marked with a record type (header, code = K; item, code = P) and counter. – LCF_STYPE_K and LCF_STYPE_S *Up to 950 line items can be transferred. *The data is transferred with the field name and field value. *The data must be transferred in the following sequence: *Document header data ( K 1) *Document item 1 ( P 1) *Document item 2 ( P 2) etc. *The field names are the same as those used on the entry screen (e.g. ‘BKPF-WAERS’, ‘BSEG-WRBTR’, ‘COBL-GSBER’…). *Suppose if it Cost Center / Profit Center – its COBL-KOSTL and COBL-PRCTR *The footer data can be transferred using the following fields: *Posting key: RF05A-NEWBS or BSEG-BSCHL *Account number: RF05A-NEWKO or BSEG-KONTO * or BSEG-KUNNR (for customer accounts) * or BSEG-LIFNR (for vendor accounts) * or BSEG-HKONT (for G/L accounts) *Special G/L indicator: RF05A-NEWUM or BSEG-UMSKZ *Company code (for intercompany posting): * RF05A-NEWBK or BSEG-BUKRS. *The field names are analyzed by the function module so that the data can be assigned to the right screens. *Field names for one-time data or data for an alternative payer must start with ‘BSEC-‘, for example (see screen SAPLFCPD 0100). *Processing with ‘Call Transaction … Using ‘ * *If processing takes place with ‘Call Transaction .. Using’, the initiator can see whether processing was successful by looking at the export parameter’SUBRC’. * *SUBRC = 0 means that the document was posted. The document number is stored in table T_BLNTAB. For intercompany documents, several document numbers are stored here. * *SUBRC <> 0 means that the document could not be posted. Information concerning the error which has arisen is returned via the message fields MSGID, MSGNO, etc. * *Support of transaction ‘FBB1’ * *If you want to access transaction FBB1, you should note the following: * *Enter the foreign currency key in field BKPF-WAERS. *In this transaction you should enter the local currency amount in field BSEG-WRBTR for each document item. CALL FUNCTION 'POSTING_INTERFACE_CLEARING' "Post with clearing (FB05) using internal posting interface EXPORTING i_auglv = 'AUSGZAHL' " t041a-auglv Clearing Transaction i_tcode = 'FB05' " sy-tcode Transaction code i_sgfunct = space " rfipi-sgfunct Different FUNCT function IMPORTING e_msgid = sy-msgid " sy-msgid Message ID (only for Call Trans. ..Using) e_msgno = sy-msgno " sy-msgno Message number (only for Call Trans. ..Using) e_msgty = sy-msgty " sy-msgty Message category (only for Call Trans. ..Using) e_msgv1 = sy-msgv1 " sy-msgv1 Message variable 1 (only for Call Trans. ..Using) e_msgv2 = sy-msgv2 " sy-msgv2 Message variable 2 (only for Call Trans. ..Using) e_msgv3 = sy-msgv3 " sy-msgv3 Message variable 3 (only for Call Trans. ..Using) e_msgv4 = sy-msgv4 " sy-msgv4 Message variable 4 (only for Call Trans. ..Using) TABLES t_blntab = it_blntab " blntab Table of the document numbers (only for Call Trans ..) t_ftclear = it_ftclear " ftclear Clearing data t_ftpost = it_ftpost " ftpost Document header and item data t_fttax = it_fttax " fttax Taxes EXCEPTIONS clearing_procedure_invalid = 1 clearing_procedure_missing = 2 table_t041a_empty = 3 transaction_code_invalid = 4 amount_format_error = 5 too_many_line_items = 6 company_code_invalid = 7 screen_not_found = 8 no_authorization = 9 OTHERS = 10. IF sy-subrc EQ 0. "清账成功,清账凭证信息存储在it_blntab中. ELSE. "清账失败,查看importing中的消息. ENDIF. *4.After bdc processing. CALL FUNCTION 'POSTING_INTERFACE_END' EXPORTING i_bdcimmed = 'X' EXCEPTIONS session_not_processable = 1 OTHERS = 2. *5.log record. ENDFORM. |
本文作者: GavinDong
版权属于: GavinDong博客
文章链接: https://gavindong.com/1770.html
如果使用过程中遇到问题,可 **点击此处** 交流沟通。
版权所有,转载时必须以链接形式注明作者和原始出处及本声明。
评论列表(1条)
程序自动清账的过账日期需要注意(与财务确定):
按当前系统时间记账?
还是按客户确认签收的时间记账?
还是按签收状态传回ERP的时间记账?
由于外围系统的不可靠性,经常发生数据传回不及时、漏传的情况,情况比较多,最简单的做法是按当前日期进行清账,这样即便有历史数据也不需要打开已经关闭的账期。