Você está na página 1de 6

4/16/2019 Document 753244.

1
Copyright (c) 2019, Oracle. All rights reserved. Oracle Confidential.

Credit Memo API: Sample Code to Apply and Unapply On Account Credit Memos using
AR_CM_API_PUB API in 11.5.10.2 and R12 (Doc ID 753244.1)

In this Document

Purpose
Requirements
Configuring
Instructions
Sample Code
Sample Output
References

APPLIES TO:

Oracle Receivables - Version 11.5.10.2 to 12.1.3 [Release 11.5.10 to 12.1]


Information in this document applies to any platform.
AR_CM_API_PUB

PURPOSE

Oracle has provided a new API AR_CM_API_PUB through which we can Apply and Unapply On-Account Credit Memos to to
open Invoices / Debit Memos.
This feature was developed in Bug 5257046 NEED AN API TO APPLY ON ACCOUNT CREDIT MEMO TO OPEN DEBIT ITEMS

The code was delivered via ARXPCMEB.pls, and is released for 11i.AR.N via Patch 10185853 and is also available in Release
12.1 via Patch 14065856.
If there is no patch available for your release, and you require this functionality, please contact the E-Business Patching
Community.

REQUIREMENTS

You can use SQL PLUS /SQL*Plus / Oracle SQL Developer to run the script

CONFIGURING

Run the script and create procedure in APPS schema.

INSTRUCTIONS

The following 2 Procedures are provided through this API:


AR_CM_API_PUB.APPLY_ON_ACCOUNT
==============================
Call this routine to apply on-account credit memos to a debit item.
Besides the standard input parameters, the API accepts the credit memo related parameters as a record type.The API needs
input parameters to determine the credit memo and the debit memo transaction. If the required parameters are not passed in
a call to this API, then the call will fail.

https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=7pj20vo1o_4&id=753244.1 1/6
4/16/2019 Document 753244.1

AR_CM_API_PUB.UNAPPLY_ON_ACCOUNT
================================
Call this routine to unapply on-account credit memo applied to a debit item.
Besides the standard input parameters, the API accepts the receivable application parameters as a record type. The API needs
input parameters to determine the transaction to unapply. If the required parameters are not passed in a call to this API, then
the call will fail.

For other uses of the Credit Memo API, please see Note 1272600.1: Oracle Receivables Credit Memo API: Setup and Sample
Scripts

For Invoice API information, please see Note 1242202.1: Oracle Receivables Invoice API: Setup and Sample Scripts

CAUTION

This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested
internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before
using.
SAMPLE CODE

The API code (AR_CM_API_PUB) was written and is supported by Oracle. However, Oracle Support cannot assist in
debugging or troubleshooting the custom code you write to call the API.

The sample code below was written and has been tested successfully in our internal instances. The code here is provided
as examples to guide you in adapting it to your particular requirements. Please test your code thoroughly before
implementing in a Production instance.

The following code can be used to apply Credit Memo to Invoice :

Do the following to prepare for using the Apply API:

Step 1. Find out user_id and RESPONSIBILITY_ID through which you will submit the program to set the context :

SELECT USER_ID,RESPONSIBILITY_ID
FROM FND_USER_RESP_GROUPS
WHERE USER_ID = (SELECT USER_ID
FROM FND_USER
WHERE USER_NAME = '&user_name')
AND RESPONSIBILITY_ID = (SELECT RESPONSIBILITY_ID
FROM FND_RESPONSIBILITY_VL
WHERE RESPONSIBILITY_NAME = '&resp_name');

Step 2. Determine the customer_trx_id of the Invoice and Credit Memo using the following sql :

select Customer_Trx_ID
from RA_CUSTOMER_TRX_ALL
where trx_number ='&transaction_number';

Important parameters to be passed are:


Customer Trx Id of Invoice and Credit Memo and Amount applied. You can change the Apply_date and GL_date to desired
value instead of sysdate.
If Receipt Application Information DFF are set then please pass the value in appropriate attributes.

https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=7pj20vo1o_4&id=753244.1 2/6
4/16/2019 Document 753244.1

DECLARE

K_api_version CONSTANT NUMBER := 1;


K_init_msg_list CONSTANT VARCHAR2(1) := FND_API.g_false;
K_comments CONSTANT ar_receivable_applications.comments%TYPE := 'Test';
K_commit CONSTANT VARCHAR2(1) := FND_API.g_false;
l_acctd_amount_applied_from ar_receivable_applications_all.
acctd_amount_applied_from%TYPE;
l_acctd_amount_applied_to ar_receivable_applications_all.
acctd_amount_applied_to%TYPE;
l_cm_app_rec AR_CM_API_PUB.cm_app_rec_type;
l_msg_count NUMBER;
l_msg_data VARCHAR2(255);
l_out_rec_application_id NUMBER;
l_return_status VARCHAR2(1);

BEGIN
/* IMPORTANT: Before calling the API, you need properly initialize org/user/resp information,
otherwise the API will fail.
Please read the following instructions to set these properly.

1. Setting Org Context


Oracle Application tables are striped by Org, and you first need to identify what org you are
processing in
The procedure to set Org has changed between R11.5 and R12:

R11.5: fnd_client_info.set_org_context(&org_id);

R12: Mo_global.init('AR');
Mo_global.set_policy_context('S', 204);

2. User/Responsibility Information
Before running the API, you need to provide your login credentials using
fnd_global.apps_initialize()
This procedure requires three parameters: UserId, ResponsibilityId, applicationId
See Step 1. above to get the proper values and use them in the following line of code
*/

-- Set Org Context


-- see instructions above to identify what call you need to use, and uncomment that line below.
-- if you are on R11.5, remove the -- in the following line:
-- fnd_client_info.set_org_context(&org_id);

-- if you are on R12, remove the -- in the next 2 lines:


-- Mo_global.init('AR');
-- Mo_global.set_policy_context('S', 204);

-- Set User/Resp

Fnd_Global.apps_initialize(&user_Id,&responsibility_Id,222)

l_cm_app_rec.cm_customer_trx_id := &Credit_Memo_Customer_trx_id;
l_cm_app_rec.cm_trx_number := null; -- Credit Memo Number
l_cm_app_rec.inv_customer_trx_id := &Invoice_Customer_trx_id;
l_cm_app_rec.inv_trx_number := null ; -- Invoice Number
l_cm_app_rec.installment := null;
l_cm_app_rec.applied_payment_schedule_id := null;
l_cm_app_rec.amount_applied := &Amount_to_be_applied;
l_cm_app_rec.apply_date := TRUNC(SYSDATE);
l_cm_app_rec.gl_date := TRUNC(SYSDATE);
l_cm_app_rec.inv_customer_trx_line_id := null;
l_cm_app_rec.inv_line_number := null;
l_cm_app_rec.show_closed_invoices := null;
l_cm_app_rec.ussgl_transaction_code := null;
l_cm_app_rec.attribute_category := null;
l_cm_app_rec.attribute1 :=null ;

https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=7pj20vo1o_4&id=753244.1 3/6
4/16/2019 Document 753244.1
l_cm_app_rec.attribute2 :=null ;
l_cm_app_rec.attribute3 := null ;
l_cm_app_rec.attribute4 := null;
l_cm_app_rec.attribute5 := null;
l_cm_app_rec.attribute6 := null;
l_cm_app_rec.attribute7 := null;
l_cm_app_rec.attribute8 := null;
l_cm_app_rec.attribute9 := null;
l_cm_app_rec.attribute10 := null;
l_cm_app_rec.attribute11 := null;
l_cm_app_rec.attribute12 := null;
l_cm_app_rec.attribute13 := null;
l_cm_app_rec.attribute14 := null;
l_cm_app_rec.attribute15 := null;
l_cm_app_rec.global_attribute_category := null;
l_cm_app_rec.global_attribute1 := null;
l_cm_app_rec.global_attribute2 := null;
l_cm_app_rec.global_attribute3 := null;
l_cm_app_rec.global_attribute4 := null;
l_cm_app_rec.global_attribute5 := null;
l_cm_app_rec.global_attribute6 := null;
l_cm_app_rec.global_attribute7 := null;
l_cm_app_rec.global_attribute8 := null;
l_cm_app_rec.global_attribute9 := null;
l_cm_app_rec.global_attribute10 := null;
l_cm_app_rec.global_attribute11 := null;
l_cm_app_rec.global_attribute12 := null;
l_cm_app_rec.global_attribute12 := null;
l_cm_app_rec.global_attribute14 := null;
l_cm_app_rec.global_attribute15 := null;
l_cm_app_rec.global_attribute16 := null;
l_cm_app_rec.global_attribute17 := null;
l_cm_app_rec.global_attribute18 := null;
l_cm_app_rec.global_attribute19 := null;
l_cm_app_rec.global_attribute20 := null;
l_cm_app_rec.comments := K_comments;
l_cm_app_rec.called_from := null;

ar_cm_api_pub.apply_on_account( p_api_version => K_api_version


, p_init_msg_list => K_init_msg_list
, p_commit => K_commit
, p_cm_app_rec => l_cm_app_rec
, x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
, x_out_rec_application_id =>
l_out_rec_application_id
, x_acctd_amount_applied_from =>
l_acctd_amount_applied_from
, x_acctd_amount_applied_to =>
l_acctd_amount_applied_to
);
dbms_output.put_line('return_status: '||l_return_status);
dbms_output.put_line('msg_count: '||l_msg_count);
dbms_output.put_line('out_rec_application_id: '||l_out_rec_application_id);
dbms_output.put_line('acctd_amount_applied_from: '|| l_acctd_amount_applied_from);
dbms_output.put_line('acctd_amount_applied_to: '|| l_acctd_amount_applied_to);
IF l_msg_count = 1 THEN
dbms_output.put_line(l_msg_data);
ELSIF l_msg_count > 1 THEN
FOR I IN 1..l_msg_count
LOOP
dbms_output.put_line(I||'. '||SubStr(FND_MSG_PUB.Get(p_encoded => FND_API.
G_FALSE ), 1, 255));
END LOOP;
END IF;
END;
/
Commit;
/
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=7pj20vo1o_4&id=753244.1 4/6
4/16/2019 Document 753244.1

The following code can be used to unapply Credit Memo to Invoice:

Do the following to prepare for using the Unapply API:

1. Identify the receivable_application_id of the Application line which is joining Credit Memo and Invoice is:

select receivable_application_id from ar_receivable_applications_all


where customer_trx_id= &Credit_Memo_Customer_trx_id
and applied_customer_trx_id= &Invoice_Customer_trx_id;

Important parameters to be passed are:


Customer Trx Id of Invoice and Credit Memo, and receivable_application_id. You can change the Apply_date and GL_date to
desired value instead of sysdate.

DECLARE

K_api_version CONSTANT NUMBER := 1;


K_init_msg_list CONSTANT VARCHAR2(1) := FND_API.g_false;
K_commit CONSTANT VARCHAR2(1) := FND_API.g_false;
l_cm_unapp_rec AR_CM_API_PUB.cm_unapp_rec_type;
l_msg_count NUMBER;
l_msg_data VARCHAR2(255);
l_out_rec_application_id NUMBER;
l_return_status VARCHAR2(1);

BEGIN
/* IMPORTANT: Before calling the API, you need properly initialize org/user/resp information,
otherwise the API will fail.
Please read the following instructions to set these properly.

1. Setting Org Context


Oracle Application tables are striped by Org, and you first need to identify what org you are
processing in
The procedure to set Org has changed between R11.5 and R12:

R11.5: fnd_client_info.set_org_context(&org_id);

R12: Mo_global.init('AR');
Mo_global.set_policy_context('S', 204);

2. User/Responsibility Information
Before running the API, you need to provide your login credentials using
fnd_global.apps_initialize()
This procedure requires three parameters: UserId, ResponsibilityId, applicationId
See Step 1. above to get the proper values and use them in the following line of code
*/

-- Set Org Context


-- see instructions above to identify what call you need to use, and uncomment that line below.
-- if you are on R11.5, remove the -- in the following line:
-- fnd_client_info.set_org_context(&org_id);

-- if you are on R12, remove the -- in the next 2 lines:


-- Mo_global.init('AR');
-- Mo_global.set_policy_context('S', 204);

-- Set User/Resp
Fnd_Global.apps_initialize(&user_Id,&responsibility_Id,222)

l_cm_unapp_rec.cm_customer_trx_id := &Credit_Memo_Customer_trx_id;
l_cm_unapp_rec.cm_trx_number := null; -- Credit Memo Number
l_cm_unapp_rec.inv_customer_trx_id := &Invoice_Memo_Customer_trx_id;
l_cm_unapp_rec.inv_trx_number := null ; -- Invoice Number
https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=7pj20vo1o_4&id=753244.1 5/6
4/16/2019 Document 753244.1
l_cm_unapp_rec.installment := null;
l_cm_unapp_rec.applied_payment_schedule_id := null;
l_cm_unapp_rec.receivable_application_id := &receivable_application_id;
l_cm_unapp_rec.reversal_gl_date := TRUNC(SYSDATE);
l_cm_unapp_rec.called_from := null;

ar_cm_api_pub.unapply_on_account( p_api_version => K_api_version


, p_init_msg_list => K_init_msg_list
, p_commit => K_commit
, p_cm_unapp_rec => l_cm_unapp_rec
, x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
);
dbms_output.put_line('return_status: '||l_return_status);
dbms_output.put_line('msg_count: '||l_msg_count);
IF l_msg_count = 1 THEN
dbms_output.put_line(l_msg_data);
ELSIF l_msg_count > 1 THEN
FOR I IN 1..l_msg_count
LOOP
dbms_output.put_line(I||'. '||SubStr(FND_MSG_PUB.Get(p_encoded => FND_API.G_FALSE ), 1, 255));
END LOOP;
END IF;
END;
/

SAMPLE OUTPUT

The sample output for 1st code block may be:

return_status: S
msg_count: 0
out_rec_application_id: 163958
acctd_amount_applied_from: 100
acctd_amount_applied_to: 100

The sampl output for 2nd code block may be:

return_status: S

REFERENCES

NOTE:1272600.1 - Oracle Receivables Credit Memo API: Setup and Sample Scripts
Didn't find what you are looking for?

https://support.oracle.com/epmos/faces/DocumentDisplay?_adf.ctrl-state=7pj20vo1o_4&id=753244.1 6/6

Você também pode gostar