Enterprise Resource Planning Blogs by Members
Gain new perspectives and knowledge about enterprise resource planning in blog posts from community members. Share your own comments and ERP insights today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Posting a credit note and doing partial / full clearing of a invoice following residual clearing method was a customer requirement in our latest project. I am sure this would be a very common requirement and the sole purpose of writing this blog is to assist other colleagues out there in future to refer to this blog for all their questions. We did a lot of internet research and did not find any BAPI or a function module in order to do the residual clearing for us. The existing standard BAPI could post credit notes but could not do partial / full clearing. Partial or a full clearing was a fundamental requirement from the customer as the amount of the invoice outstanding to be paid must reflect the exact outstanding amount and as one line item only in the AR ageing report.

There were number of posts on SCN hinting about recording a BDC and then clearing the invoices dynamically, but nothing seems to answer all the questions that we had. Some of them are hereby posted:

  1. How to dynamically identify the invoice which needs to be cleared (either partial or full depending on the amount) with the credit note.
  2. How to make sure that all the users have the correct user settings in order to post the credit notes, as in F-30 or FB05 there can be different user settings and that can make the BDC recording inconsistent.
  3. How to dynamically determine the number of line items of the credit note and then accordingly populate the BDC recording.
  4. Which is better BDC run from a “Batch session” of a “Call Transaction” and its corresponding advantages and disadvantages?

We had to really invest a lot of time in order to determine the answer of all the above mentioned questions before we could actually start the implementation. With some bit of research and some functional background we were able to handle this requirement.

Lets discuss each question one by one and then the solution to handle that.

1.    How to dynamically identify the right invoice which needs to be cleared (either partial or full depending on the amount) with the credit note.

Solution: Before I answer the above mentioned questions it is important to understand the relationship between the credit note no and the invoice. The “Invoice number” from the online system (portal) was mapped to the “Reference No” (or XBLNR) in ECC. When the invoice was posted in ECC it was made sure that the reference number is correctly populated in ECC. In the online system it was ensured that the Invoice no is always unique.

Now if a credit note is created to offset a certain invoice, then the invoice number must be related to the credit note number and this has to be a unique combination. So when the credit note was to be posted to did the below mentioned mapping in ECC.

Invoice No = XBLNR (Reference no)

Credit note No = ZUONR (Assignment field)

Related invoice No of the credit note = XBLNR (Reference No).

In order to do the residual clearing for a invoice, I need to know all the open items for the customer and the corresponding sequence. This can be done by using the BAPI “BAPI_AR_ACC_GETOPENITEMS”. By passing the company code, customer code and the current date I was able to determine all the invoices which are open as of date.

It is important to determine the correct index of the invoice which is to be cleared, as that is going to the key to be used in the BDC recording. Once all my line items are sorted based on the reference i.e. the invoice number I can get the correct index.

The sequence of invoices present in the residual items tab is still going to be different as compared to what you have in the above mentioned internal table and hence you need to sort the items present in the residual items tab as well based on the “Reference”.

2.    How to make sure that all the users have the correct user settings in order to post the credit notes, as in F-30 or FB05 there can be different user settings and that can make the BDC recording inconsistent.

Solution: There are certain user specific settings which the user can do in FB05 or F-30 using the below mentioned menu path.

Settings->Editing options.

User specific settings can have a significant impact on the BDC. Hence it is very important to standardize it. I used the below mentioned code in order to standardize the user options before actually running the BDC for residual clearing.

Kindly refer to the attached documents for further information on how to change the user settings dynamically in the BDC.

1. Refer to code snippet as an attachment "ChangeUserSettings.txt"

1.   3. How to dynamically determine the number of line items of the credit note and then accordingly populate the BDC recording.

Solution: Each credit note which is to be posted can have a different number of line items, and it is important to determine how this will impact the BDC recording.

1.    4. Which is better BDC run from a “Batch session” of a “Call Transaction” and its corresponding advantages and disadvantages

Solution: The answer to this question can vary as per the requirement. Just comparing some pros and cons.

Using Batch session:

-      The batch session is there in SM35 to determine what got posted and what sort of error occurred. Here you can define the background user which is to be used to do the postings in ECC. This is a typical audit requirement in which the postings in ECC must always be done using a system id and not the actual user.

-      If the batch resulted into error then the user has to manually go into SM35 and rerun the batch session again correcting the errors.

-      Once the error records are posted, there are still chances that the batch can be rerun and hence we have to make sure the batch is locked for future reruns (by mistake) which might result into duplicate postings.

-      Reading the messages from the batch session is not that easy and a custom function module is required to do that. One mightalso require a select at BKPF and BSEG in order to determine what got posted.

Using Call Transaction:

-      Easy to retrieve the messages back for each credit note posted, and determine if the transaction was successful or not.

-      No background error handling to be done directly in ECC. The corrections needs to be made in online credit note and then posted again.

-      User ID switch to a background user is a bit tricky, as call transaction does not allow to change the user ID. I will post another blog post to share what we did in order to switch the user id.

4 Comments
Labels in this area