Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

2/5/2020 Post a credit note – Residual Clearing | SAP Blogs

Community

Ask a Question Write a Blog Post Login

Former Member
September 25, 2014 5 minute read

Post a credit note – Residual Clearing


Follow RSS feed Like

2 Likes 1,443 View 4 Comments

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 nd
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 re ect 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 di erent 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 o set 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 eld)

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.

https://blogs.sap.com/2014/09/25/post-a-credit-note-residual-clearing/ 1/5
2/5/2020 Post a credit note – Residual Clearing | SAP Blogs

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 di erent 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 di erent user settings and that can make the BDC
recording inconsistent.

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

Settings->Editing options.

User speci c settings can have a signi cant 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.

https://blogs.sap.com/2014/09/25/post-a-credit-note-residual-clearing/ 2/5
2/5/2020 Post a credit note – Residual Clearing | SAP Blogs

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 di erent 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 de ne 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.

https://blogs.sap.com/2014/09/25/post-a-credit-note-residual-clearing/ 3/5
2/5/2020 Post a credit note – Residual Clearing | SAP Blogs

Alert Moderator

Assigned tags

ABAP Development | FIN (Finance) | HCM (Human Capital Management) | abap | abap excel |

View more...

Related Blog Posts

Inclusion of the personnel number of a traveler (PERNR) in the credit card transaction le when this data is absent
By Parag Parikh , Jan 03, 2013

SAP OSS Notes Series – Part 2 – Discovering and reading notes


By Fabio Pagoti , Nov 03, 2013

Automatic Clearing For Multiple Customers/ F-32 Clearing


By Former Member , Mar 29, 2012

Related Questions

Create Residual Items


By Former Member , Nov 20, 2007

Function Module/BAPI for Posting with Residual Clearing


By Former Member , Jun 02, 2010
RFBIBL00 - Residual Item (FB05 - Post with Clearing)
By Former Member , May 04, 2007

4 Comments

You must be Logged on to comment or reply to a post.

Rajesh Shanmugam S

November 5, 2014 at 8:08 am

Nice blog Ashish. Quite helpful.

Like (0)

Manjunath v

November 5, 2014 at 8:25 am

Hi Ashish,

It is good information and i would be interested to know the next steps

Thank you and it is good information !

Regards

Manjunath

https://blogs.sap.com/2014/09/25/post-a-credit-note-residual-clearing/ 4/5
2/5/2020 Post a credit note – Residual Clearing | SAP Blogs

Like (0)

Former Member | Post author

November 6, 2014 at 3:44 am

Hi Manjunath,

Thanks for appreciating the blog. Please let me know in case you need any more information.

Ashish

Like (0)

Rastogi Utkarsh

June 6, 2019 at 3:09 pm

Hi Ashish,

Can you please provide the code snippet in the attachment ChangeUserSettings.txt.

TIA.

Like (0)

Find us on

Privacy Terms of Use

Legal Disclosure Copyright

Trademark Cookie Preferences

Newsletter Support

https://blogs.sap.com/2014/09/25/post-a-credit-note-residual-clearing/ 5/5

You might also like