Thursday, 29 January 2015

HZ(TCA) tables in Oracle Receivables

HZ(TCA) tables in Oracle Receivables
This article describes few important HZ tables in AR and their relationships with each other.
HZ_PARTIES:
The HZ_PARTIES table stores basic information about parties that can be shared with any relationship that the party might establish with another party. The primary key for this table is PARTY_ID.
Few Important Columns are
  • PARTY_ID: Party identifier
  • PARTY_NUMBER: Unique identification number for this party
  • PARTY_NAME: Name of the party
  • PARTY_TYPE: The party type can only be Person, Organization, Group or Relationship.
HZ_PARTY_SITES:
The HZ_PARTY_SITES table links a party (HZ_PARTIES) and a location (HZ_LOCATIONS) and stores location-specific party information. One party can optionally have one or more party sites. One location can optionally be used by one or more parties. The primary key for this table is PARTY_SITE_ID.
Few Important Columns are
  • PARTY_SITE_ID: Party site identifier.
  • PARTY_ID: Identifier for the party. Foreign key to the HZ_PARTIES table.
  • LOCATION_ID: Identifier for the party site. Foreign key to the HZ_LOCATIONS table.
  • PARTY_SITE_NUMBER: Party site number.
  • PARTY_SITE_NAME: User-defined name for the site.
  • ADDRESSEE: Addressee information.
HZ_LOCATIONS:
The HZ_LOCATIONS table stores information about a delivery or postal address such as building number, street address, postal code, and directions to a location. This table provides physical location information about parties (organizations and people) and customer accounts. The primary key for this table is LOCATION_ID.
Few Important Columns are
  • LOCATION_ID: Unique identifier for this location
  • COUNTRY: Country code from the TERRITORY_CODE column in the FND_TERRITORY table
  • ADDRESS1: First line for address
  • ADDRESS2: Second line for address
  • ADDRESS3: Third line for address
  • ADDRESS4: Fourth line for address
  • CITY: City
  • POSTAL_CODE: Postal Code
  • STATE: State
  • ADDRESS_KEY: Derived key that facilitates fuzzy searches
HZ_CUST_ACCOUNTS:
The HZ_CUST_ACCOUNTS table stores information about customer accounts , or business relationships that the deploying company establishes with a party of type Organization or Person. This table focuses on business relationships and how transactions are conducted in the relationship. Since a party can have multiple customer accounts, this table might contain several records for a single party. For example, an individual person can establish a personal account, family account, and a professional account for a consulting practice. The primary key for this table is CUST_ACCOUNT_ID.
Few Important Columns are
  • CUST_ACCOUNT_ID: Customer account identifier
  • PARTY_ID: A foreign key to the HZ_PARTY table.
  • ACCOUNT_NUMBER: Account Number
  • CUSTOMER_TYPE: Receivables lookup code for the CUSTOMER_TYPE attribute. I for internal customers, R for revenue generating external customers.
  • CUSTOMER_CLASS_CODE: Customer class identifier
HZ_CUST_ACCT_SITES_ALL:
The HZ_CUST_ACCT_SITES_ALL table stores all customer account sites across all operating units. Customer account sites are addresses, for customer accounts, where the deploying company does business with its customers. One customer account can have multiple customer account sites, and customer account sites for one customer account can belong to multiple operating units. The primary key for this table is CUST_ACCT_SITE_ID.
Few Important Columns are
  • CUST_ACCT_SITE_ID: Customer site identifier
  • CUST_ACCOUNT_ID: Identifier for a customer account. Foreign key to the HZ_CUST_ACCOUNTS table
  • PARTY_SITE_ID: Identifier for a party site. Foreign key to the HZ_PARTY_SITES table
  • BILL_TO_FLAG: Indicates if this is a Bill-To site.
  • SHIP_TO_FLAG: Indicates if this is a Ship-To site.
  • MARKET_FLAG: Indicates if this is a Marketing site.
HZ_CUST_SITE_USES_ALL:
The HZ_CUST_SITE_USES_ALL table stores business purposes assigned to customer account sites, for example Bill-To, Ship-To, and Statements. Each customer account site can have one or more purposes. This table is a child of the HZ_CUST_ACCT_SITES_ALL table, with the foreign
key CUST_ACCT_SITE_ID. The HZ_CUST_SITE_USES_ALL table also stores operating unit identifier, though the HZ_CUST_ACCT_SITES_ALL table itself stores the operating unit for customer account sites. The primary key for this table is SITE_USE_ID.
Few Important Columns are
  • SITE_USE_ID: Site use identifier
  • CUST_ACCT_SITE_ID: Identifier for the customer account site. Foreign key to the HZ_CUST_ACCT_SITES_ALL table
  • SITE_USE_CODE: Business purpose assigned to customer site account, such as Bill-To, Market, and Statements.
  • PRIMARY_FLAG: Indicates if this site is the primary site for this customer account. Y for the primary customer account site. N for other customer account sites.
HZ_CUSTOMER_PROFILES:
The HZ_CUSTOMER_PROFILES table stores information about the credit characteristics of a single customer account or a customer account site or a party. A profile class defined in the
HZ_CUSTOMER_PROFILE_CLASSES table can be used to provide default values for the attributes in this table. The primary key for this table is CUST_ACCOUNT_PROFILE_ID.
Few Important Columns are
  • CUST_ACCOUNT_PROFILE_ID: Unique identifier of this customer profile
  • CUST_ACCOUNT_ID: Identifier for the Customer Account. Foreign key to the HZ_CUST_ACCOUNTS table.
  • STATUS: Indicates whether the profile is active or inactive
HZ_CUST_PROFILE_CLASSES:
The HZ_CUST_PROFILE_CLASSES table stores information about the credit characteristics that are common across a group of customer accounts. The characteristics specified in this table can be used as default characteristics for similar customer accounts. The primary key for this table is PROFILE_CLASS_ID.
HZ_PARTY_RELATIONSHIPS:
The HZ_PARTY_RELATIONSHIPS table stores information about relationships between parties.

Query to Get In hand Inventory Information

SELECT
NVL(substr(org.organization_code, 1,3), ' ') orgcode
,NVL(substr(msi.segment1, 1, 8), ' ') seg11
,NVL(substr(msi.segment1, 9, 8), ' ') seg12
,NVL(substr(msi.segment1, 17, 4), ' ') seg13
,NVL(moq.subinventory_code, ' ') sub_inv_code
,NVL(to_char(round(sum(moq.transaction_quantity))), ' ') trans_qnty
FROM mtL_system_items msi
,org_organization_definitions org
,mtl_onhand_quantities moq
,hr_organization_units hou
WHERE moq.inventory_iteM_id = msi.inventory_item_id
AND moq.organizatioN_id = msi.organizatioN_id
AND moq.organizatioN_id = org.organizatioN_id
AND moq.organization_id = hou.organization_id
-- AND hou.type = 'DC'
GROUP BY org.organization_code
, moq.subinventory_code
, msi.segment1;

AR Invoice Interface

AR Invoice Interface

The main three steps for AR Invoice Interface are:
1] Put the data into your staging tables.
2] Calls your package to validate the data and load into AR Interface tables (RA_INTERFACE_LINES_ALL & RA_INTERFACE_DISTRIBUTIONS_ALL).
3] Then submits a concurrent request for AutoInvoice.
If any errors occur it can be found in ra_interface_errors_all table. The concurrent program has 2 stages. First the Master program fires which intern kicks of the Import Program. Once this is completed data is inserted into the following tables.
1) ra_customer_trx_all (Invoice Header Info)
2) ra_customer_trx_lines_all (Invoice Line Level Info)
3) ra_cust_trx_line_gl_dist_all (Accounting Info. One record for each Account Type is inserted into this… ex. Receivable Revenue Tax Freight etc)
4) ar_payment_schedules_all (All Payment related info)
Validations:
Validation are generally done on the below columns.
  • Batch_source_name
  • Set_of_books_id
  • Orig_sys_batch_name
  • orig_system_bill_customer_ref
  • orig_system_bill_address_ref
  • Line_Type
  • Currency_Code
  • Term_name
  • Transaction_type
  • Interface_line_attribute1-7
  • Account_class
  • Accounting Flexfields segments
1- AR Transaction Type Validation: Check if the Transaction type provided in data file is defined in AR transaction types (RA_CUST_TRX_TYPES_ALL)
2- Transaction Batch Source Validation: Check if the source provided in data file is defined in AR transaction Batch source (RA_BATCH_SOURCES_ALL).
3- Invoice Currency Validation: Check if the currency provided in data file is defined in AR Currency (FND_CURRENCIES).
4- Customer Validation: Check if the Bill to Customer Number, Ship to Customer Number, Bill to Custom Location, Ship to Customer Location provided in the data file is defined in AR Customer (RA_CUSTOMERS).
5- Primary Sales Representative Validation: Sales representative number to be hardcode to “-3” for “No Sales Credit.”
6- Term Name: Check if the Term name provided in the data file is defined in Payment terms (RA_TERMS)
7- Inventory Item Validation: Check if the Item provided in data file is defined in Inventory Items (MTL_SYSTEM_ITEMS).
8- Unit of Measurement validation: Check if the UOM provided is defined in MTL_UNITS_OF_MEASURE Table
9- Invoice Tax Code Validation: Check if the Tax Code provided in data file is defined in AR_VAT_TAX_ALL_B Table.
10- Invoice GL Date Validation: Check if the GL Data of provided invoices is in open period.
For MOAC:
You need to add the below columns and need to do validations if your application supports MOAC.
  • conversion_type
  • conversion_rate
  • conversion_date
Sample Code to run Autoinvoice Master Program:
01DECLARE
02v_phase     VARCHAR2(100);
03v_dev_phase     VARCHAR2(100);
04v_status    VARCHAR2(100);
05v_dev_status    VARCHAR2(100);
06v_message   VARCHAR2(100);
07v_reqid     NUMBER(15);
08v_pid       BOOLEAN;
09v_user_id   NUMBER(30);
10v_batch_source_id NUMBER;
11v_order     NUMBER;
12v_org_id    NUMBER;
13v_resp_id   number;
14v_resp_appl_id  number;
15v_appl_short_name fnd_application.application_short_name%TYPE;
16 
17CURSOR c1 IS
18select fcr.responsibility_id
19,fr.application_id
20from fnd_concurrent_requests fcr
21,fnd_responsibility fr
22where fcr.request_id = '${4}'
23and   fcr.responsibility_id = fr.responsibility_id;
24 
25CURSOR c2 IS
26select fa.application_short_name
27from fnd_concurrent_programs fcp, fnd_application fa
28where fcp.concurrent_program_name = v_program_short_name
29and fcp.application_id = fa.application_id;
30 
31CURSOR c_batch_id IS
32SELECT 1, batch_source_id, name
33FROM apps.ra_batch_sources_all
34WHERE name IN (SELECT distinct a.batch_source_name
35FROM xxfin.xxfin_ar_ol_invoices a
36WHERE a.batch_source_name like '%DEBIT'
37AND filename = '${file1}')
38UNION
39SELECT 2, batch_source_id, name
40FROM apps.ra_batch_sources_all
41WHERE name IN (SELECT distinct a.batch_source_name
42FROM xxfin.xxfin_ar_ol_invoices a
43WHERE a.batch_source_name like '%CREDIT'
44AND filename = '${file1}')
45order by 1;
46 
47BEGIN
48open c1;
49fetch c1 into v_resp_id,v_resp_appl_id;
50close c1;
51 
52open c2;
53fetch c2 into v_appl_short_name;
54close c2;
55 
56FOR v_batch_data IN c_batch_id LOOP
57 
58fnd_global.apps_initialize('${FCP_USERID}',v_resp_id,v_resp_appl_id);
59 
60v_reqid := fnd_request.submit_request('AR',
61'RAXMTR',
62NULL,
63to_char(trunc(sysdate),'YYYY/MM/DD HH24:MI:SS'),
64FALSE,
65'1',
66-99,
67v_batch_data.batch_source_id,
68v_batch_data.name,
69to_char(trunc(sysdate),'YYYY/MM/DD HH24:MI:SS'),
70NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,
71NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,
72'Y',
73NULL);
74commit;
75v_pid := fnd_concurrent.wait_for_request(v_reqid,
763,
770,
78v_phase,
79v_status,
80v_dev_phase,
81v_dev_status,
82v_message);
83END LOOP;
84END;

AP-PO use full Query

- VENDOR, PO AND INVOICE DETAILS (2 WAY MATCH)

SELECT DISTINCT
a.org_id "ORG ID", e.segment1 "VENDOR NUM",
e.vendor_name "SUPPLIER NAME",
UPPER (e.vendor_type_lookup_code) "VENDOR TYPE",
f.vendor_site_code "VENDOR SITE CODE", f.address_line1 "ADDRESS",
f.city "CITY", f.country "COUNTRY",
TO_CHAR (TRUNC (d.creation_date)) "PO DATE", d.segment1 "PO NUM",
d.type_lookup_code "PO TYPE", c.quantity_ordered "QTY ORDERED",
c.quantity_cancelled "QTY CANCELLED", g1.quantity_received, g1.quantity_rejected, g1.quantity_billed,
g.item_id "ITEM ID",
g.item_description "ITEM DESCRIPTION", g.unit_price "UNIT PRICE",
(NVL (c.quantity_ordered, 0) - NVL (c.quantity_cancelled, 0)
)
* NVL (g.unit_price, 0) "PO LINE AMOUNT",
(SELECT DECODE (ph.approved_flag, 'Y', 'Approved')
FROM po.po_headers_all ph
WHERE ph.po_header_id = d.po_header_id) "PO APPROVED?",
a.invoice_type_lookup_code "INVOICE TYPE",
a.invoice_amount "INVOICE AMOUNT",
TO_CHAR (TRUNC (a.invoice_date)) "INVOICE DATE",
a.invoice_num "INVOICE NUMBER",
(SELECT DECODE (x.match_status_flag,
'A', 'Approved'
)
FROM ap.ap_invoice_distributions_all x
WHERE x.invoice_distribution_id = b.invoice_distribution_id)
"INVOICE APPROVED?",
a.amount_paid
FROM ap.ap_invoices_all a,
ap.ap_invoice_distributions_all b,
po.po_distributions_all c,
po.po_headers_all d,
ap.ap_suppliers e,
ap.ap_supplier_sites_all f,
po.po_lines_all g,
po.po_line_locations_all g1
WHERE a.invoice_id = b.invoice_id
AND b.po_distribution_id = c.po_distribution_id(+)
AND c.po_header_id = d.po_header_id(+)
AND e.vendor_id(+) = d.vendor_id
AND f.vendor_site_id(+) = d.vendor_site_id
AND d.po_header_id = g.po_header_id
AND g1.po_header_id = c.po_header_id
AND g1.po_line_id = g.po_line_id
AND c.po_line_id = g.po_line_id
AND c.line_location_id = g1.line_location_id
AND g1.inspection_required_flag = 'N'
AND g1.receipt_required_flag = 'N'

-- VENDOR, PO AND INVOICE DETAILS (3 WAY MATCH)SELECT DISTINCT
a.org_id "ORG ID", e.segment1 "VENDOR NUM",
e.vendor_name "SUPPLIER NAME",
UPPER (e.vendor_type_lookup_code) "VENDOR TYPE",
f.vendor_site_code "VENDOR SITE CODE", f.address_line1 "ADDRESS",
f.city "CITY", f.country "COUNTRY",
TO_CHAR (TRUNC (d.creation_date)) "PO DATE", d.segment1 "PO NUM",
d.type_lookup_code "PO TYPE", c.quantity_ordered "QTY ORDERED",
c.quantity_cancelled "QTY CANCELLED", g1.quantity_received, g1.quantity_rejected, g1.quantity_billed,
g.item_id "ITEM ID",
g.item_description "ITEM DESCRIPTION", g.unit_price "UNIT PRICE",
(NVL (c.quantity_ordered, 0) - NVL (c.quantity_cancelled, 0)
)
* NVL (g.unit_price, 0) "PO LINE AMOUNT",
(SELECT DECODE (ph.approved_flag, 'Y', 'Approved')
FROM po.po_headers_all ph
WHERE ph.po_header_id = d.po_header_id) "PO APPROVED?",
a.invoice_type_lookup_code "INVOICE TYPE",
a.invoice_amount "INVOICE AMOUNT",
TO_CHAR (TRUNC (a.invoice_date)) "INVOICE DATE",
a.invoice_num "INVOICE NUMBER",
(SELECT DECODE (x.match_status_flag,
'A', 'Approved'
)
FROM ap.ap_invoice_distributions_all x
WHERE x.invoice_distribution_id = b.invoice_distribution_id)
"INVOICE APPROVED?",
a.amount_paid
FROM ap.ap_invoices_all a,
ap.ap_invoice_distributions_all b,
po.po_distributions_all c,
po.po_headers_all d,
ap.ap_suppliers e,
ap.ap_supplier_sites_all f,
po.po_lines_all g,
po.po_line_locations_all g1
WHERE a.invoice_id = b.invoice_id
AND b.po_distribution_id = c.po_distribution_id(+)
AND c.po_header_id = d.po_header_id(+)
AND e.vendor_id(+) = d.vendor_id
AND f.vendor_site_id(+) = d.vendor_site_id
AND d.po_header_id = g.po_header_id
AND g1.po_header_id = c.po_header_id
AND g1.po_line_id = g.po_line_id
AND c.po_line_id = g.po_line_id
AND c.line_location_id = g1.line_location_id
AND g1.inspection_required_flag = 'N'
AND g1.receipt_required_flag = 'Y'

-- VENDOR, PO AND INVOICE DETAILS (4 WAY MATCH)SELECT DISTINCT
a.org_id "ORG ID", e.segment1 "VENDOR NUM",
e.vendor_name "SUPPLIER NAME",
UPPER (e.vendor_type_lookup_code) "VENDOR TYPE",
f.vendor_site_code "VENDOR SITE CODE", f.address_line1 "ADDRESS",
f.city "CITY", f.country "COUNTRY",
TO_CHAR (TRUNC (d.creation_date)) "PO DATE", d.segment1 "PO NUM",
d.type_lookup_code "PO TYPE", c.quantity_ordered "QTY ORDERED",
c.quantity_cancelled "QTY CANCELLED", g1.quantity_received, g1.quantity_rejected, g1.quantity_billed,
g.item_id "ITEM ID",
g.item_description "ITEM DESCRIPTION", g.unit_price "UNIT PRICE",
(NVL (c.quantity_ordered, 0) - NVL (c.quantity_cancelled, 0)
)
* NVL (g.unit_price, 0) "PO LINE AMOUNT",
(SELECT DECODE (ph.approved_flag, 'Y', 'Approved')
FROM po.po_headers_all ph
WHERE ph.po_header_id = d.po_header_id) "PO APPROVED?",
a.invoice_type_lookup_code "INVOICE TYPE",
a.invoice_amount "INVOICE AMOUNT",
TO_CHAR (TRUNC (a.invoice_date)) "INVOICE DATE",
a.invoice_num "INVOICE NUMBER",
(SELECT DECODE (x.match_status_flag,
'A', 'Approved'
)
FROM ap.ap_invoice_distributions_all x
WHERE x.invoice_distribution_id = b.invoice_distribution_id)
"INVOICE APPROVED?",
a.amount_paid
FROM ap.ap_invoices_all a,
ap.ap_invoice_distributions_all b,
po.po_distributions_all c,
po.po_headers_all d,
ap.ap_suppliers e,
ap.ap_supplier_sites_all f,
po.po_lines_all g,
po.po_line_locations_all g1
WHERE a.invoice_id = b.invoice_id
AND b.po_distribution_id = c.po_distribution_id(+)
AND c.po_header_id = d.po_header_id(+)
AND e.vendor_id(+) = d.vendor_id
AND f.vendor_site_id(+) = d.vendor_site_id
AND d.po_header_id = g.po_header_id
AND g1.po_header_id = c.po_header_id
AND g1.po_line_id = g.po_line_id
AND c.po_line_id = g.po_line_id
AND c.line_location_id = g1.line_location_id
AND g1.inspection_required_flag = 'Y'
AND g1.receipt_required_flag = 'Y'

-- VENDOR, PO, INVOICE AND PAYMENT DETAILSSELECT DISTINCT a.org_id "ORG ID", e.segment1 "VENDOR NUMBER",
e.vendor_name "VENDOR NAME",
UPPER (e.vendor_type_lookup_code) "VENDOR TYPE",
f.vendor_site_code "VENDOR SITE CODE",
TO_CHAR (TRUNC (d.creation_date)) "PO DATE",
d.segment1 "PO NUM", d.type_lookup_code "PO TYPE",
c.quantity_ordered "QTY ORDERED",
c.quantity_cancelled "QTY CANCELLED",
g.item_description "ITEM DESCRIPTION",
g.unit_price "UNIT PRICE",
(NVL (c.quantity_ordered, 0) - NVL (c.quantity_cancelled, 0)
)
* NVL (g.unit_price, 0) "PO LINE AMOUNT",
(SELECT DECODE (ph.approved_flag,
'Y', 'Approved'
)
FROM po.po_headers_all ph
WHERE ph.po_header_id = d.po_header_id) "PO APPROVED?",
a.invoice_type_lookup_code "INVOICE TYPE",
a.invoice_amount "INVOICE AMOUNT",
TO_CHAR (TRUNC (a.invoice_date)) "INVOICE DATE",
a.invoice_num "INVOICE NUMBER",
(SELECT DECODE (x.match_status_flag,
'A', 'Approved'
)
FROM ap.ap_invoice_distributions_all x
WHERE x.invoice_distribution_id = b.invoice_distribution_id)
"INVOICE APPROVED?",
a.amount_paid, h.check_id, i.check_number,
h.invoice_payment_id,
TO_CHAR (TRUNC (i.check_date)) "PAYMENT DATE"
FROM ap.ap_invoices_all a,
ap.ap_invoice_distributions_all b,
po.po_distributions_all c,
po.po_headers_all d,
ap.ap_suppliers e,
ap.ap_supplier_sites_all f,
po.po_lines_all g,
ap.ap_invoice_payments_all h,
ap.ap_checks_all i
WHERE a.invoice_id = b.invoice_id
AND b.po_distribution_id = c.po_distribution_id(+)
AND c.po_header_id = d.po_header_id(+)
AND e.vendor_id(+) = d.vendor_id
AND f.vendor_site_id(+) = d.vendor_site_id
AND d.po_header_id = g.po_header_id
AND c.po_line_id = g.po_line_id
AND a.invoice_id = h.invoice_id
AND h.check_id = i.check_id
AND c.po_header_id IS NOT NULL
AND a.payment_status_flag = 'Y'
AND d.type_lookup_code != 'BLANKET'
ORDER BY E.VENDOR_NAME

API TO CANCEL PO invoice

AP_CANCEL_PKG.IS_INVOICE_CANCELLABLE:
Is_Invoice_Cancellable is a Function in the AP_CANCEL_PKG package that checks that an Invoice is cancellable or not when an Invoice Cancellation process starts.
It follows the following steps and returns a Boolean value depending on the result.

    If invoice contains distribution that does not have open GL period return FALSE.
    If invoice has an effective payment, return FALSE.
    If invoice is selected for payment, return FALSE.
    If invoice is already cancelled, return FALSE.
    If invoice is credited invoice, return FALSE.
    If invoices have been applied against this invoice, return FALSE.
    If invoice is matched to Finally Closed PO’s, return FALSE.
    If project related invoices have pending adjustments, return FALSE.
    If cancelling will cause qty_billed or amount_billed to less than 0, return FALSE.
    If none of above, invoice is cancellable return True.

Here is a small procedure to check if an Invoice is cancellable or not.
--*****************************************************************************
 CREATE OR REPLACE PROCEDURE XX_INV_CANCELLABLE (p_inv_id IN NUMBER)
is
v_boolean               BOOLEAN;
v_error_code            VARCHAR2(100);
v_debug_info            VARCHAR2(1000);
begin
v_boolean :=AP_CANCEL_PKG.IS_INVOICE_CANCELLABLE(
                P_invoice_id       => p_inv_id,
                P_error_code       => v_error_code,
                P_debug_info       => v_debug_info,
                P_calling_sequence => NULL);
IF v_boolean=TRUE
THEN
DBMS_OUTPUT.put_line ('Invoice '||p_inv_id|| ' is cancellable' );
ELSE
DBMS_OUTPUT.put_line ('Invoice '||p_inv_id|| ' is not cancellable :'|| v_error_code );
END IF;
End XX_INV_CANCELLABLE;

Execute XX_INV_CANCELLABLE(12960);

--************************************************************************
AP_CANCEL_PKG.AP_CANCEL_SINGLE_INVOICE:
AP_CANCEL_SINGLE_INVOICE is a Function in the AP_CANCEL_PKG package that cancels one invoice by executing the following sequence of steps, returning TRUE if successful and FALSE otherwise.
1] Check if the invoice is cancellable. if yes, proceed otherwise return false.
2] If invoice has tax withheld, undo withholding.
3] Clear out all payment schedules.
4] Cancel all the non-discard lines.
a. reverse matching
b. fetch the maximum distribution line number
c. Set encumbered flags to ‘N’
d. Accounting event generation
e. reverse the distributions
f. update Line level Cancelled information
5] Zero out the Invoice.
6] Run AutoApproval for this invoice.
7] Check posting holds remain on this cancelled invoice.
a. if NOT exist – complete the cancellation by updating header level information set return value to TRUE.
b. if exist – no update, set the return values to FALSE, NO DATA rollback.
8] Commit the Data.
9] Populate the out parameters.
Here is a small procedure to cancel a single invoice.

--*********************************************************

CREATE OR REPLACE PROCEDURE XX_INV_CANCEL(
                            P_xx_invoice_id IN NUMBER,
                            P_xx_last_updated_by IN  NUMBER,
                            P_xx_last_update_login IN  NUMBER,
                            P_xx_accounting_date IN  DATE)
is
v_boolean               BOOLEAN;
v_message_name          VARCHAR2(1000);
v_invoice_amount        NUMBER;
v_base_amount           NUMBER;
v_temp_cancelled_amount NUMBER;
v_cancelled_by          VARCHAR2(1000);
v_cancelled_amount      NUMBER;
v_cancelled_date        DATE;
v_last_update_date      DATE;
v_orig_prepay_amt       NUMBER;
v_pay_cur_inv_amt       NUMBER;
v_token                 VARCHAR2(100);
BEGIN
v_boolean := AP_CANCEL_PKG.AP_CANCEL_SINGLE_INVOICE
            (p_invoice_id                 => P_xx_invoice_id,
             p_last_updated_by            => P_xx_last_updated_by,
             p_last_update_login          => P_xx_last_update_login,
             p_accounting_date            => P_xx_accounting_date,
             p_message_name               => v_message_name,
             p_invoice_amount             => v_invoice_amount,
             p_base_amount                => v_base_amount,
             p_temp_cancelled_amount      => v_temp_cancelled_amount,
             p_cancelled_by               => v_cancelled_by,
             p_cancelled_amount           => v_cancelled_amount,
             p_cancelled_date             => v_cancelled_date,
             p_last_update_date           => v_last_update_date,
             p_original_prepayment_amount => v_orig_prepay_amt,
             p_pay_curr_invoice_amount    => v_pay_cur_inv_amt,
             P_Token                      => v_token,
             p_calling_sequence           => NULL
             );

IF v_boolean
THEN
DBMS_OUTPUT.put_line ('Successfully Cancelled the Invoice' );
COMMIT;
ELSE
DBMS_OUTPUT.put_line ('Failed to Cancel the Invoice' );
ROLLBACK;
END IF;

END XX_INV_CANCEL;

EXECUTE XX_INV_CANCEL(120573,2325,-1,SYSDATE);

Oracle Apps Cancel PO API Training

 Oracle Apps Cancel PO API Training
Following is a sample script to cancel the purchase order using Cancel PO API:

To cancel the whole PO, submit the cancel API using sqlplus as follows:


DECLARE
   l_return_status   VARCHAR2 (1);
BEGIN
   fnd_global.apps_initialize (1053, 50578, 201);
   -- mo_global.init('PO'); -- need for R12

   --call the Cancel API for PO
   PO_Document_Control_PUB.control_document (1.0,  -- p_api_version
                                             FND_API.G_TRUE, -- p_init_msg_list
                                             FND_API.G_TRUE,       -- p_commit
                                             l_return_status, -- x_return_status
                                             'PO',               -- p_doc_type
                                             'STANDARD',      -- p_doc_subtype
                                             NULL,                 -- p_doc_id
                                             '23975',             -- p_doc_num
                                             NULL,             -- p_release_id
                                             NULL,            -- p_release_num
                                             NULL,            -- p_doc_line_id
                                             NULL,           -- p_doc_line_num
                                             NULL,        -- p_doc_line_loc_id
                                             NULL,       -- p_doc_shipment_num
                                             'CANCEL',             -- p_action
                                             SYSDATE,         -- p_action_date
                                             NULL,          -- p_cancel_reason
                                             'N',        -- p_cancel_reqs_flag
                                             NULL,             -- p_print_flag
                                             NULL);        -- p_note_to_vendor

   -- Get any messages returned by the Cancel API
   FOR i IN 1 .. FND_MSG_PUB.count_msg
   LOOP
      DBMS_OUTPUT.put_line (
         FND_MSG_PUB.Get (p_msg_index => i, p_encoded => 'F'));
   END LOOP;
END;




The first run of the API will demonstrate cancelling shipment number 3 on line number 1 of the PO. Submit the cancel API using sqlplus as follows:

DECLARE
   l_return_status   VARCHAR2 (1);
BEGIN
   fnd_global.apps_initialize (1053, 50578, 201);
   -- mo_global.init('PO'); -- need for R12

   --call the Cancel API for PO
   PO_Document_Control_PUB.control_document (1.0,  -- p_api_version
                                             FND_API.G_TRUE, -- p_init_msg_list
                                             FND_API.G_TRUE,       -- p_commit
                                             l_return_status, -- x_return_status
                                             'PO',               -- p_doc_type
                                             'STANDARD',      -- p_doc_subtype
                                             NULL,                 -- p_doc_id
                                             '23975',             -- p_doc_num
                                             NULL,             -- p_release_id
                                             NULL,            -- p_release_num
                                             NULL,            -- p_doc_line_id
                                             '1',            -- p_doc_line_num
                                             NULL,        -- p_doc_line_loc_id
                                             '3',        -- p_doc_shipment_num
                                             'CANCEL',             -- p_action
                                             SYSDATE,         -- p_action_date
                                             NULL,          -- p_cancel_reason
                                             'N',        -- p_cancel_reqs_flag
                                             NULL,             -- p_print_flag
                                             NULL);        -- p_note_to_vendor

   -- Get any messages returned by the Cancel API
   FOR i IN 1 .. FND_MSG_PUB.count_msg
   LOOP
      DBMS_OUTPUT.put_line (
         FND_MSG_PUB.Get (p_msg_index => i, p_encoded => 'F'));
   END LOOP;
END;



This time, the API will be used to cancel all of line 1. Submit the cancel API using sqlplus as follows:
DECLARE
   l_return_status   VARCHAR2 (1);
BEGIN
   fnd_global.apps_initialize (1053, 50578, 201);
   -- mo_global.init('PO'); -- need for R12

   --call the Cancel API for PO
   PO_Document_Control_PUB.control_document (1.0,  -- p_api_version
                                             FND_API.G_TRUE, -- p_init_msg_list
                                             FND_API.G_TRUE,       -- p_commit
                                             l_return_status, -- x_return_status
                                             'PO',               -- p_doc_type
                                             'STANDARD',      -- p_doc_subtype
                                             NULL,                 -- p_doc_id
                                             '23975',             -- p_doc_num
                                             NULL,             -- p_release_id
                                             NULL,            -- p_release_num
                                             NULL,            -- p_doc_line_id
                                             '1',            -- p_doc_line_num
                                             NULL,        -- p_doc_line_loc_id
                                             NULL,       -- p_doc_shipment_num
                                             'CANCEL',             -- p_action
                                             SYSDATE,         -- p_action_date
                                             NULL,          -- p_cancel_reason
                                             'N',        -- p_cancel_reqs_flag
                                             NULL,             -- p_print_flag
                                             NULL);        -- p_note_to_vendor

-- Get any messages returned by the Cancel API
   FOR i IN 1 .. FND_MSG_PUB.count_msg
   LOOP
      DBMS_OUTPUT.put_line (
         FND_MSG_PUB.Get (p_msg_index => i, p_encoded => 'F'));
   END LOOP;
END;

Tuesday, 20 January 2015

Submit Standard concurrent Program from Back end In R12

DECLARE
ln_responsibility_id NUMBER;
ln_application_id     NUMBER;
ln_user_id           NUMBER;
ln_request_id            NUMBER;
BEGIN

--  FND_GLOBAL.APPS_INITIALIZE (ln_user_id,ln_responsibility_id,ln_application_id);
    FND_GLOBAL.APPS_INITIALIZE (1312,20434,101);

   -- Submitting Concurrent Request
  ln_request_id := FND_REQUEST.SUBMIT_REQUEST (
                            application   => 'XXSVL', -- Application Short Code
                            program       => 'XXCUSTCONVPRG', -- Concurrent Program Short NAme
                            description   => 'SVL Customer Conversion Program', -- Concurrent Program Description
                            start_time    => SYSDATE,
                            sub_request   => FALSE,
argument1     => 100 -- Parameter Value
  );

  COMMIT; -- It is Mandatory

  IF ln_request_id = 0
  THEN
     DBMS_OUTPUT.PUT_LINE ('Concurrent Request Failed to Submit.');
  ELSE
     DBMS_OUTPUT.PUT_LINE('Successfully Submitted the Concurrent Request. Request Id: '||ln_request_id);
  END IF;

EXCEPTION
WHEN OTHERS THEN
  DBMS_OUTPUT.PUT_LINE('Error While Submitting Concurrent Request '||TO_CHAR(SQLCODE)||'-'||SQLERRM);
END;
/