Goal
Sometimes you may need create FI documents in your customer ABAP‑programs. Several techniques are useful for this, e.g. batch-input execution, direct accounting document input and so on and also BAPI.
And sometimes you may need to post FI-document with clearing including partial one. In this case it is not so obvious to use standard programming interface without batch‑input simulation of t-code ‘FB05’, such as function ‘AC_DOCUMENT_DIRECT_INPUT’ or BAPI function ‘BAPI_ACC_DOCUMENT_POST’. The text below explains as to make it for both cases.
Solution for AC_DOCUMENT_DIRECT_INPUT
The first obstacle for clearing with direct document input is a lack of input parameters with clearing‑info: AUSZ2_TAB and AUSZ_CLR_TAB types. In other words you want to tell FI‑interface that some item should be cleared by your document, but you can’t. You may ask why standard programs as ‘SAPMF05A’ processes a clearing with no problem, well answer is ‘BELEG’ RWIN-process used in that case, not ‘DOCUMENT’.
Key points to receive and handle clearing information with a non‑dialog posting procedure are:
- function ‘FI_DOCUMENT_PROJECT’: saves clearing info from input parameters for further posting
- function ‘FI_DOCUMENT_POST’: sends clearing info last saved to the real update module ‘POST_DOCUMENT’
The first function triggered at DOCUMENT/SPLIT RWIN‑event. So the only you need is to fill clearing info before the one has called. You might use one of 2 techniques to do this, depending on development rules for you project team:
- make implicit enhancement directly at the beginning of ‘FI_DOCUMENT_PROJECT’
- or register you own RWIN handler for DOCUMENT/CLOSE event: t-code SM30, view TRWPR;
take the rule 'SUBNO > 900' into account
In any case you might use unified ABAP logic (see attached example for RWIN) according to the following restrictions:
- one item in document you create may clear only one item in other document
- each item in your document has non-zero amounts
- full clearing is possible if you explicilty mark it, partial clearing is performed by default
Short description of ABAP logic attached:
- Take BUKRS, REBZG, REBZJ, REBZZ from T_ACCIT[p] that should be set there by caller program;
- Read amounts T_AUSZ_CLR[p]‑WRBTR, -DMBTR from BSEG (or some non‑cleared index table) found by the reference and add new records to itab T_AUSZ_CLR with corresponding BSEG values.
- Calculate reminder T_AUSZ_CLR[p]‑DIFFW, ‑DIFHW as difference between clearing and cleared amounts
- Mark T_AUSZ_CLR[p] for partial clearing: CLRIN = ‘2’. But if DIFFW and DIFHW are both zero it is possible to make full clearing by marking T_AUSZ_CLR[p]-CLRIN = SPACE; to control this logic the T_ACCIT[p]-AUGBL value is used: = ‘*’ (full clearing) or = ‘ ’ (partial).
- For the whole document create single row in T_AUSZ2: fill BUKRS = T_ACCIT[p]-BUKRS. And when full clearing needed you must fill T_AUSZ2‑AUGBL = ‘*’ also.
Solution for BAPI_ACC_DOCUMENT_POST
Well first the most of solution told above is applicable to BAPI also. Because the same function AC_DOCUMENT_CREATE called from AC_DOCUMENT_DIRECT_INPUT as well as from BAPI function.
The specific obstacle for BAPI is a lack of fields where you can pass clearing item reference: REBZG, REBZJ, REBZZ, and also helpful fields REBZG_CHECK and AUGBL. The solution contains 2 steps:
- At BAPI call point write your clearing reference(s) in you custom structure, or you may find and use some standard one, and serialize it to EXTENSION2 parameter of type BAPIPAREX_TAB. Don’t forget that POSNR field has to be present in the structure along with REBZG, REBZJ and REBZZ fields.
- Implement BADI ACC_DOCUMENT, or – for new ERP versions – the enhancement spot BADI_ACC_DOCUMENT and create BADI implementation inside it with filter AWTYP = BKPFF:
- Use ABAP logic from sample method CL_EXM_IM_ACC_DOCUMENT->CHANGE to move you reference into corresponding T_ACCIT[p]-REBZG, -REBZJ and –REBZZ
- Ensure that document you clear is compatible with FUNCTION ‘FI_DOCUMENT_CHECK’ standard checks. Elsewhere you might set T_ACCIT[p]‑REBZG_CHECK = ‘N’ and skip invoice reference checks