Saturday, August 7, 2010

Service Contracts Queries


How to Query the Service Contracts Tables for Header, Line, Subline and Billing Information in 11.5.10 [ID 467334.1]



Modified 04-JUN-2009     Type HOWTO     Status PUBLISHED

In this Document
  Goal
  Solution
  References



Applies to:

Oracle Service Contracts - Version: 11.5.10 to 11.5.10.2
Information in this document applies to any platform.

Goal

How to query service contracts tables and tables from other schemas to find underlying data about contract headers, lines, sublines and contract billing in 11.5.10. (For R12 queries please see Note 816374.1).

This note gives a variety of queries which can be used to find the required data for a particular contract. 

In the SQL statements given, represents text that needs to be replaced with the actual values indicated between the brackets.  For example, if you want to execute a query for a contract with number Test1, then whenever you see in the SQL below, replace it with Test1.

Sections in this note are:
A. Contract Header Data
B. Contract Line Data 
C. Contract Subline Data
D. Contract Billing Data 
E. Receivables Interface Data 
F. Subscription Contracts 

Solution

A. Contract Header Data 

A1. This SQL takes data from views rather than from actual contracts tables and is useful for reviewing data but not ideal for verifying if base tables hold correct data.
SELECT CONTRACT_NUMBER "Contract" 
, TO_CHAR( id ) "Id" 
, SHORT_DESCRIPTION "Description" 
, INV_ORGANIZATION_ID "Organization Id" 
, STS_CODE "Status", scs_code 
, CURRENCY_CODE "Currency" 
, TO_CHAR( DATE_TERMINATED, 'DD-MON-YYYY' ) "Date Terminated" 
, TRN_CODE 
, TO_CHAR( START_DATE, 'DD-MON-YYYY' ) "Start Date" 
, TO_CHAR( END_DATE, 'DD-MON-YYYY' ) " End Date" 
, UPG_ORIG_SYSTEM_REF 
, PRICE_LIST_ID 
, BILL_TO_SITE_USE_ID 
, SHIP_TO_SITE_USE_ID 
, PAYMENT_TERM_ID 
, ACCT_RULE_ID 
, INV_RULE_ID 
, AR_INTERFACE_YN 
, CLASS_MEANING 
, TEMPLATE_YN 
, HOLD_BILLING 
FROM oks_auth_headers_v 
WHERE CONTRACT_NUMBER like ''; 


B. Contract Line Data 

Note: in OKC_K_LINES_B the chr_id field is only populated with the contract header id for contract lines.  For contract sublines, this value is NULL.  Dnz_chr_id is populated with the contract header id for both lines and sublines. 

B1. This SQL takes data from views rather than from actual contracts tables and is useful for reviewing data but not ideal for verifying if base tables hold correct data 

SELECT DISTINCT oal.LINE_NUMBER 
, oll.lse_name 
, oal.STS_CODE "Status" 
, oal.TRN_CODE, oal.LSE_ID, old.service_name 
, oal.CURRENCY_CODE "Currency|Code" 
, TO_CHAR( oal.START_DATE, 'DD-MON-YYYY' ) "Start Date" 
, TO_CHAR( oal.END_DATE, 'DD-MON-YYYY' ) "End Date" 
, qpl.NAME "Price List Name" 
, CUST_ACCT_ID 
, BILL_TO_SITE_USE_ID 
, INV_RULE_ID 
, SHIP_TO_SITE_USE_ID 
, SHIP_TO_SITE_USE_ID 
, ACCT_RULE_ID 
, USAGE_PERIOD 
, USAGE_TYPE 
, UOM_QUANTIFIED 
, BILLING_SCHEDULE_TYPE 
, INVOICE_TEXT 
FROM oks_auth_lines_v oal 
, okc_launch_lgrid_v oll 
, qp_pricelists_lov_v qpl 
, oks_line_details_v old 
WHERE oal.id = oll.id 
AND cle_id IS NULL 
AND qpl.PRICE_LIST_ID = oal.PRICE_LIST_ID 
AND old.CONTRACT_ID = oll.chr_id 
AND oll.chr_id = '' 
ORDER BY to_number(line_number); 


B2. Data taken directly from contract table.  (Note that this query may appear to return duplicate lines, as the query on okc_k_headers_b will return more than one contract if the contract has been renewed).
select * 
from OKC_K_LINES_B 
where CHR_ID IN (select id 
from okc_k_headers_b 
where contract_number = ' 


C. Contract Subline Data 

Note: When you add a subline to a contract OKC_K_LINES_B is populated with data, some of the data created there for each subline is internal data.  Use the LSE_ID to restrict the data returned when querying. 

C1. Query for all the sublines on a contract with a Level type that can be seen when authoring the contract (i.e. restricts to lines which have Level of Product, Site, Item, System, Customer or Site).  (Note that this query may appear to return duplicate lines, as the query on okc_k_headers_b will return more than one contract if the contract has been renewed). 

select 
id 
, line_number 
, cle_id 
, sts_code 
, hidden_ind 
, decode(lse_id, 
         8, 'Party', 
         7, 'Item', 
         9, 'Product', 
         10, 'Site', 
         11, 'System', 
         35, 'Customer') "Level" 
, object_version_number 
, price_negotiated 
, price_level_ind 
, price_unit 
, price_unit_percent 
, price_type 
, currency_code 
, price_list_id 
, price_list_line_id 
, item_to_price_YN 
, pricing_date 
, date_terminated 
, start_date 
, end_date 
from OKC_K_LINES_B 
where DNZ_CHR_ID IN (select id 
                    from okc_k_headers_b 
                    where contract_number = '') 
and lse_id IN(8, 7, 9, 10, 11, 35);
 

C2. Query for contract sublines for a given contract line only. Replace with the line number of the required contract line (e.g. 1, 2. 3), taken either from the contract form, or from query B2.  (Note that this query may appear to return duplicate lines, as the query on okc_k_headers_b will return more than one contract if the contract has been renewed). 
select 
id 
, line_number 
, cle_id 
, sts_code 
, decode(lse_id, 
         8, 'Party', 
         7, 'Item', 
         9, 'Product', 
         10, 'Site', 
         11, 'System', 
         35, 'Customer') "Level" 
, object_version_number 
, price_negotiated 
, price_level_ind 
, price_unit 
, price_unit_percent 
, price_type 
, currency_code 
, price_list_id 
, price_list_line_id 
, item_to_price_YN 
, pricing_date 
, date_terminated 
, start_date 
, end_date 
from OKC_K_LINES_B 
where DNZ_CHR_ID IN (select id 
                    from okc_k_headers_b 
                    where contract_number = '') 
and cle_id IN (select id 
             from okc_k_lines_b 
             where chr_id IN (select id 
                             from okc_k_headers_b 
                             where contract_number = '
             and line_number = ) 
and lse_id IN(8, 7, 9, 10, 11, 35);

C3. This query returns the inventory item for a given contract subline where the Level = Product (i.e. the subline is for a particular install base instance).
SELECT kl.line_number,
ks.NAME
, i.segment1 
FROM 
okc_k_headers_b kh, 
okc_k_lines_b kl, 
okc_k_items ki, 
okc_line_styles_v ks, 
csi_item_instances c, 
mtl_system_items_b i 
WHERE 
kh.contract_number = '' 
AND kh.contract_number_modifier IS NULL --can be populated 
AND kh.ID = kl.dnz_chr_id 
AND kh.ID = ki.dnz_chr_id 
AND kl.ID = ki.cle_id 
AND kl.lse_id = ks.ID 
AND ki.jtot_object1_code IN ('OKX_CUSTPROD') 
AND c.last_vld_organization_id = i.organization_id 
AND TO_NUMBER(ki.object1_id1) = c.instance_id 
AND c.inventory_item_id = i.inventory_item_id ;


D. Contract Billing Data 

D1. This query shows the billing invoice details. Note that –99 will be shown for invoice number if the 'Service Contracts Fetch Receivables Info For Billing' concurrent program has not been run after Autoinvoice has been run. 
SELECT DISTINCT d.contract_number 
,a.trx_number "Invoice Number" 
,TO_CHAR( b.date_billed_from, 'DD-MON-YYYY HH24-MI' ) "Bill From" 
,TO_CHAR( b.date_billed_to, 'DD-MON-YYYY HH24-MI' ) "Bill To" 
,b.amount 
FROM oks_bill_transactions a 
, oks_bill_txn_lines aa 
, oks_bill_cont_lines b 
, okc_k_lines_b c 
, okc_k_headers_b d 
WHERE A.ID = AA.BTN_ID 
AND AA.BCL_ID = B.ID 
AND B.CLE_ID = C.CLE_ID 
AND C.DNZ_CHR_ID = D.ID 
AND d.id = ;

D2. This query shows the billing transaction details. The data in this table is shown in the ‘History’ tab of the ‘Billing Schedule’ form in the contract. 

For the bill_action, the codes have the following meanings: 
Regular Invoice -RI, 
Termination Credit - TR, 
Averaging - AV, 
Settlement Invoice - SRI, 
Settlement Credit - STR. 
SELECT hdr.contract_number "Contract" 
, hdr.contract_number_modifier "Modifier" 
, hdr.id 
, TO_CHAR( cont.creation_date, 'DD-MON-YYYY HH24:MI') "Creation Date" 
, bill_action 
, btn_id "Billing Transaction ID"
, amount 
, TO_CHAR( DATE_BILLED_FROM, 'DD-MON-YYYY' ) "Date Billed From" 
, TO_CHAR( DATE_BILLED_TO, 'DD-MON-YYYY' ) "Date Billed To" 
FROM oks_bill_cont_lines cont 
, okc_k_lines_b line 
, okc_k_headers_b hdr 
WHERE hdr.id = line.dnz_chr_id 
AND cont.cle_id = line.id 
AND hdr.id =  
ORDER BY cont.creation_date; 

D3. This query returns data about the contract Line ids corresponding to each invoice as well as invoice details.
SELECT BCL.id 
,BCL.cle_id 
,BCL.btn_id 
,BCL.bill_action 
,OKL.id "Line id" 
,OKH.id "Contract id" 
, BTN.TRX_NUMBER "Invoice" 
,bcl.date_billed_from 
, bcl.date_billed_to 
FROM OKS_BILL_CONT_LINES BCL, 
OKC_K_LINES_B OKL, 
OKC_K_HEADERS_B OKH, 
OKS_BILL_TRANSACTIONS BTN, 
OKS_BILL_TXN_LINES BTL 
WHERE OKH.contract_number = '' 
And OKH.ID = OKL.DNZ_CHR_ID 
And OKL.CLE_ID IS NULL 
And OKL.ID = BCL.CLE_ID 
And BTN.ID = BCL.BTN_ID  
And BTL.BTN_ID = BTN.ID 
And BTL.BILL_INSTANCE_NUMBER IS NOT NULL ;
D4. This query returns information about what the contract billing schedule for a contract and can be used to investigate amounts expected to be billed in a billing period.
SELECT TO_CHAR(bcl.id) 
, TO_CHAR(bsl.id) 
, TO_CHAR(lvl.id) 
, lvl.date_start 
, bsl.date_billed_from 
, lvl.date_end 
, bsl.date_billed_to 
, bcl.DATE_NEXT_INVOICE 
, lvl.DATE_TRANSACTION 
, lvl.DATE_TO_INTERFACE 
, lvl.DATE_COMPLETED 
, TO_CHAR(RUL_ID) 
, TO_CHAR(lvl.PARENT_CLE_ID) 
, bsl.amount 
FROM oks_bill_sub_lines bsl 
,oks_bill_cont_lines bcl 
,oks_level_elements lvl 
,okc_K_LINES_B kl 
,okc_k_headers_b kh 
WHERE kh.contract_number = '&enter_contract_number' 
AND kl.dnz_chr_id = kh.id 
AND lvl.dnz_chr_id = kh.id 
AND bcl.cle_id = kl.id 
AND bcl.id = bsl.bcl_id 
AND lvl.cle_id = bsl.cle_id ;



E. Receivables Interface Data 

E1. Query to return all the data in the RA interface table for a given service contract.  This will return the data populated into the table by Service Contracts Main Billing.   Note that this query will not return any data if Autoinvoice has been run since the records are deleted from this table once they have been successfully processed by Autoinvoice.
SELECT * 
FROM ra_interface_lines_all 
WHERE sales_order = '' ;

F. Subscription Contracts
F1.  
How to find the install base instance created for the subscription line item.  (Note that when you enter a subscription line, the application automatically creates an Oracle Install Base item instance.  This is what this query is retrieving).
SELECT osh.instance_id, 
okh.contract_number, 
okh.contract_number_modifier, 
okl.line_number 
FROM oks_subscr_header_b osh, 
okc_k_headers_b okh, 
okc_k_lines_b okl 
WHERE osh.dnz_chr_id = okh.id 
AND osh.cle_id = okl.id 
AND okl.chr_id = okh.id 
AND okh.contract_number = '' 
AND NVL(okh.contract_number_modifier,'-') = NVL('','-');
F2. Query to find the install base instances created by a Subscription Contract as a result of subscription fulfillment.
SELECT csi.instance_number 
FROM oks_subscr_elements ose, 
csi_item_instances csi 
WHERE ose.dnz_chr_id IN (SELECT id 
FROM okc_k_headers_b 
WHERE contract_number = '' 
AND NVL(contract_number_modifier,'-') = Nvl('','-')) 
AND ose.order_line_id = csi.last_oe_order_line_id; 

F3. Query to find which subscription contract line created the install base instance, for a subscription fulfillment.
SELECT okh.contract_number, 
okh.contract_number_modifier, 
okl.line_number 
FROM oks_subscr_elements ose, 
csi_item_instances csi, 
okc_k_headers_b okh, 
okc_k_lines_b okl 
WHERE csi.instance_number = '' 
AND ose.order_line_id = csi.last_oe_order_line_id 
AND okh.id = ose.dnz_chr_id 
AND okl.chr_id = okh.id 
AND okl.id = ose.dnz_cle_id;

References

NOTE:816374.1 - R12: How to Query the Service Contracts Tables for Header, Line, Subline and Billing Information



1 comment:

  1. Awesome. U have provided a superb list of useful queries

    ReplyDelete