Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to post clearing with direct input

alexander_zelentsov
Product and Topic Expert
Product and Topic Expert
0 Likes
9,042

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
9 REPLIES 9
Read only

Clemenss
Active Contributor
0 Likes
5,552

Hi Alexander,

thank you for the excellent post.

I'm very eager to substitute clearing transaction F-32 by  BAPI_ACC_DOCUMENT_POST.

In F-32, the clearing information is provided by passing  T_AUSZ3 to function FI_DOCUMENT_PROCESS with I_EVENT = 'PROJECT'.

Even in the 'POST' event I have only one line in T_BKPF and for the RW interface just onle line T_ACCIT is created.

Now I have no idea how the clearing items T_AUSZ3 may be supplied in BADI_ACC_DOCUMENT. Will I create additional

C_ACCIT

C_ACCCR

C_ACCWT

C_ACCTX

lines from my extension data here?

Can you give me a hint?

The code in z_rwin_clearing_sample does not really explain it  or I do not fully understand

Thank You.

Best regards Clemens

Read only

alexander_zelentsov
Product and Topic Expert
Product and Topic Expert
0 Likes
5,552

Hi Clemens.

I think you should create as much items as required for zero-balancing your document.

But I wouldn't recommend you to add items within BADI implementation only to simulate 'F-32' visual behavior in your program internals. It will be much better if you construct all items of your clearing document before you call BAPI_ACC_DOCUMENT_POST. How they looks you might see in  clearings that are really made by F-32.

Read only

Clemenss
Active Contributor
0 Likes
5,552

Hi Alexander,

I'll try to do that:

Because the document created by clearing with F-32 has no items at all but will fill in the clearing data into the cleared items as AUGBL AUGT etc. I'm still in doubt how to convince the BAPI to behave like this.

Where will I supply the document and/or reference number of the items to be cleared?

I'm still in doubt as I do not want to create any new items but clear existing items.

My idea was to fill the T_AUSZ3 for further processing, but how?

Can you give any hints?

Best regards

Clemens

Read only

alexander_zelentsov
Product and Topic Expert
Product and Topic Expert
0 Likes
5,552

Hi, Clemens.

If you just about full clearing by itemless document then ... to use BAPI_ACC_DOCUMENT_POST whould be excessive I think. And besides, sample code above whouldn't work, it has to be improved for the case of itemless clearing.

To cover your goal you may try:

Read only

alexander_zelentsov
Product and Topic Expert
Product and Topic Expert
0 Likes
5,552

Hi, Clemens.

I've achieved a kind of clearing you told with BAPI_ACC_DOCUMENT_POST purely just for fun.

It was to create enough the document with mirror items to cleared. And use improved RW-handler, see post below.

Read only

alexander_zelentsov
Product and Topic Expert
Product and Topic Expert
0 Likes
5,552

Some corrections to the sample ...

1. Now ACCIT-REBZG_CHECK='A' used as a full-clearing indicator, instead of ACCIT-AUGBL='*'. AUGBL only used internally since RWIN-handler has finished.

2. Account types D, K, S are supported

3. Itemless clearing is supported

Read only

0 Likes
5,552

Hi Alexander.

I was trying to clear open items using bapi BAPI_ACC_DOCUMENT_POST ( and badi BADI_ACC_DOCUMENT enhancement ) but is not working.

In badi implementation i was passing:

REBZG -> invoice reference

REBZJ -> pos invoice

REBZZ -> I tried with A, Z ...

In this point, i should check tx OB74 ? I'm trying to posting a payment entry for an open invoice.

Now i´m thinking use FM CLEAR_DOCUMENTS.

Any suggest or hint ?

Thanks.

Regards,

Manuel H.

Read only

0 Likes
5,552

Hint is that REBZZ has to be filled with item position number, not a follow-on document type indicator as you do. And REBZJ to be filled with year, not a position number. Please look attentively the sample before usage. Also fill REBZG_CHECK with: 'A' if you want to perform a full clearing, or 'N' if you don't.

Unfortunately, data from OB74 is not allowed to consider yet. To improve this you might:

  • use another special indicator value of REBZG_CHECK, let it be 'X', not 'A', in cases when your items are NOT collapsed according to TF123; use 'A' only if they're ready to be collapsed.
  • insert corrections below into FM
  • enjoy

Correction 1. Replace:

      IF t_accit-rebzg_check = 'A'.

        <fs_ausz2>-augbl = '*'.

        <fs_ausz2>-aktio = 'A'.

      ENDIF.

        ...

with

      IF t_accit-rebzg_check CO 'AX'.

        <fs_ausz2>-augbl = '*'.

        <fs_ausz2>-aktio = t_accit-rebzg_check.

      ENDIF.

        ...

Correction 2. Replace:

     MODIFY t_accit TRANSPORTING rebzg_check WHERE bukrs = <fs_ausz2>-bukrs AND rebzg_check = 'A'.

with

     MODIFY t_accit TRANSPORTING rebzg_check WHERE bukrs = <fs_ausz2>-bukrs AND rebzg_check CO 'AX'.


Correction 3. Replace:

        IF lines( t_ausz_clr[] ) = lines( t_accit[] ).

          t_accit-bstat = 'A'.

          MODIFY t_accit TRANSPORTING bstat WHERE bukrs = <fs_ausz2>-bukrs.

        ENDIF.

with

        IF lines( t_ausz_clr[] ) = lines( t_accit[] ) AND <fs_ausz2>-aktio = 'A'.

          t_accit-bstat = 'A'.

          MODIFY t_accit TRANSPORTING bstat WHERE bukrs = <fs_ausz2>-bukrs.

        ELSE.

          <fs_ausz2>-aktio = 'A'.

        ENDIF.

Good luck.

Read only

0 Likes
4,334

Hi sir,
It need create posting vendor partial clearing document. Please tell me, I must config how to fill REBZG_CHECK and value for it?
With my knowlegde i config  REBZG, REBZJ, REBZZ and  AUGBL in extension 2(item) but i don't know config REBZG_CHECK how?
Please help me,
Thank you,