Beruflich Dokumente
Kultur Dokumente
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, <xxx> 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 <contract
number> in the SQL below, replace it with Test1.
Table: OKC_K_HEADERS_B
Product: OKC - Contracts Core
Description: Top level of a contract structure and groups all the lines and terms and
conditions of a contract.
Implementation/DBA Data: OKC.OKC_K_HEADERS_B
Table: OKC_K_ITEMS
Product: OKC - Contracts Core
Description: Contract items
Implementation/DBA Data: OKC.OKC_K_ITEMS
Table: OKC_K_LINES_B
Product: OKC - Contracts Core
Oracle CRM Service Contracts Queries
Description: Deliverable ITEMS grouped into a logical set usually defined by unitary
price, delivery or some other classification.
Implementation/DBA Data: OKC.OKC_K_LINES_B
Table: OKS_BILL_SUB_LINES
Product: OKS - Service Contracts
Description: Related to a lower level contract line eg. coverage level or product.
Implementation/DBA Data: OKS.OKS_BILL_SUB_LINES
Table: OKS_BILL_CONT_LINES
Product: OKS - Service Contracts
Description: Records which are sent to AR.
Implementation/DBA Data: OKS.OKS_BILL_CONT_LINES
Table: OKS_BILL_SUB_LINE_DTLS
Product: OKS - Service Contracts
Description: The detail of quantities and monetary amounts either regular or
adjustment.
Implementation/DBA Data: OKS.OKS_BILL_SUB_LINE_DTLS
Table: OKS_BILL_TRANSACTIONS
Product: OKS - Service Contracts
Description: The transaction (invoice, credit etc.) which is eventually received from
AR.
Implementation/DBA Data: OKS.OKS_BILL_TRANSACTIONS
Table: OKS_BILL_TXN_LINES
Product: OKS - Service Contracts
Description: Holds the actual transaction amount and tax returned from AR.
Implementation/DBA Data: OKS.OKS_BILL_TXN_LINES
Table: OKS_STREAM_LEVELS_B
Product: OKS - Service Contracts
Description: Service Contracts Billing Stream Levels
Implementation/DBA Data: OKS.OKS_STREAM_LEVELS_B
Table: OKS_REV_DISTRIBUTIONS
Product: OKS - Service Contracts
Description: Database table used for storing revenue distribution information for
service
contract lines.
Oracle CRM Service Contracts Queries
The eTRM contains also the following information of the tables and ERD Diagrams:
- OKS - Service Contracts
- R11510 Service Contracts ERD.pdf
- sub_erd_billing.pdf
- sub_erd_billing_profile.pdf
- sub_erd_defaults.pdf
- sub_erd_order_details.pdf
- sub_erd_sales_credit.pdf
When AutoInvoice has been run program RAXTRX takes transactions that are on table
RA_INTERFACE_LINES_ALL, validates them and if valid, passes the information into
the AR tables,
- RA_CUSTOMER_TRX_ALL
- RA_CUSTOMER_TRX_LINES_ALL
- RA_CUST_TRX_LINE_GL_DIST_ALL
- RA_SALESCREDITS_ALL
- AR_PAYMENT_SCHEDULES_ALL
SELECT rcta.trx_number invoice_no,
rctla.line_number invoice_line_no,
txn.bill_instance_number,
rctla.inventory_item_id,
oks_hd.contract_number,
oks_hd.contract_number_modifier,
oks_ln.line_number cont_line_no,
cii_oks.instance_id,
cii_oks.serial_number sn
FROM okc_k_headers_b oks_hd,
okc_k_lines_b oks_ln,
oks_k_lines_b oks_ln_sub,
okc_k_items oki,
oks_bill_txn_lines txn,
oks_bill_sub_lines bsl,
Oracle CRM Service Contracts Queries
okx_install_items_v ocsi,
csi_item_instances cii_oks,
ra_customer_trx_all rcta,
ra_customer_trx_lines_all rctla
WHERE rctla.customer_trx_id = rcta.customer_trx_id
AND rctla.interface_line_attribute1 = oks_hd.contract_number(+)
AND NVL (rctla.interface_line_attribute2, '') = NVL
(oks_hd.contract_number_modifier(+),'')
AND rctla.interface_line_attribute3 = txn.bill_instance_number(+)
AND bsl.cle_id = oks_ln.ID
AND NVL (txn.bsl_id, 999) = DECODE (txn.bsl_id, NULL, 999, bsl.ID)
AND txn.bcl_id = bsl.bcl_id
AND oks_ln.ID = oks_ln_sub.cle_id(+)
AND oks_ln.ID = oki.cle_id(+)
AND oki.object1_id1 = ocsi.id1(+)
AND oki.object1_id2 = ocsi.id2(+)
AND ocsi.instance_id = cii_oks.instance_id(+)
AND rcta.trx_number = '&your_trans_num'
AND oks_hd.contract_number = '&your_contr_num'
Oracle CRM Service Contracts Queries
11i
select * from OKC_K_HEADERS_B
where contract_number = '23572';
Note: In release 11.5.10, the table name is OKC_K_HEADERS_B. In R12, the table
name is OKC_K_HEADERS_ALL_B. This was done so that Service Contracts can use
the MO: Security Profile to control which organizations are accessible from a given
responsibility. There is a synonym from OKC_K_HEADERS_B to
OKC_K_HEADERS_ALL_B. Queries in R12 should reference OKC_K_HEADERS_ALL_B
unless client_info is set to the appropriate organization.
A. Contract Header Data
SELECT *
FROM okc_k_headers_b
WHERE contract_number = '&contract_number'
AND contract_number_modifier = '&contract_modifier';
Oracle CRM Service Contracts Queries
It is a good idea to run queries from both tables and save them in a spreadsheet so
that changes can be observed as additional information is entered in the contract.
select oks.*
from OKC_K_HEADERS_ALL_B k,
OKS_K_HEADERS_B oks
where contract_number = '23572'
and k.id = oks.chr_id;
This information is returned. Notice that the jtot_object1_code for the new entry is
OKX_RESOURCE. The results will be different when you run this query because line
level contacts are created later in this presentation.
The resource information is located in a table and a view. Either of these queries will
return the information:
select * from OKX_RESOURCES_V
where id1 = 10199;
select * from JTF_RS_RESOURCE_EXTNS
where resource_id = 10199;
Oracle CRM Service Contracts Queries
The values are the id’s in other tables. For example, this query returns the Corporate
price list:
select name
from QP_LIST_HEADERS_B pl,
QP_LIST_HEADERS_TL tl
where pl.list_header_id = 1000
and pl.list_header_id = tl.list_header_id;
SELECT DISTINCT d.contract_number
,a.trx_number "Invoice Number"
,TO_CHAR( b.date_billed_from, 'DDMONYYYY HH24MI' ) "Bill From"
,TO_CHAR( b.date_billed_to, 'DDMONYYYY HH24MI' ) "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 = <contract id from query A1>;
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.
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 = '<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
Oracle CRM Service Contracts Queries
,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 ;
Oracle CRM Service Contracts Queries
The Approval (Required) is returned by running this query. The value is ‘Y’ when
approval is required.
select approval_type
from OKC_K_HEADERS_ALL_B
where contract_number = '23572';
The price list information is stored in QP_LIST_HEADERS_B, but this query will provide
the list header name.
select pr.name
from OKC_K_HEADERS_ALL_B k,
QP_LIST_HEADERS_TL pr
where k.price_list_id = pr.list_header_id
and pr.source_lang = 'US'
and k.contract_number = '23572';
This query returns the Quote To information. It is a single query from multiple tables.
The query can be simplified to return specific fields.
select substr(okc.contract_number,1,30) "Contract Number",
hca.account_number "Account Number",
substr(hca.account_name,1,40) "Account Name",
substr(csv.description,1,60) "Quote To Address",
substr(hp.party_name,1,40) "Contact Party Name",
substr(cp.email_address,1,30) "Email Address",
oks.quote_to_contact_id,
car.cust_account_role_id,
car.party_id,
car.cust_account_id
from OKS_K_HEADERS_B oks,
OKC_K_HEADERS_ALL_B okc,
HZ_CUST_ACCOUNT_ROLES car ,
HZ_CUST_ACCOUNTS hca,
HZ_CONTACT_POINTS cp,
HZ_PARTIES hp,
OKX_CUST_SITES_V csv
where oks.chr_id = okc.id
and oks.quote_to_contact_id = car.cust_account_role_id
and oks.quote_to_email_id = cp.contact_point_id
and hp.party_id = car.party_id
and car.cust_account_id = hca.cust_account_id
and oks.quote_to_site_id = csv.id1
and okc.contract_number = '23572';
The quote_to_contact_id in OKS_K_HEADERS_B maps to
HZ_CUST_ACCOUNT_ROLES,
This query can be used to obtain the contract group(s) for a contract.
select substr(k.contract_number,1,25) "Contract Number",
substr(k.contract_number_modifier,1,25) "Modifier",
substr(tl.name,1,25) "Group Name"
from OKC_K_HEADERS_ALL_B k,
OKC_K_GRPINGS gp,
OKC_K_GROUPS_TL tl
where gp.included_chr_id = k.id
and k.contract_number_modifier is null
and tl.language = 'US'
AND gp.cgp_parent_id = tl.id
and k.contract_number = '23572';
select ls.lty_code,
l.bill_to_site_use_id,
l.ship_to_site_use_id
from okc_k_headers_all_b k,
OKC_K_LINES_B l,
OKS_K_LINES_B okls,
OKC_LINE_STYLES_B ls
where k.id = l.dnz_chr_id
and l.id = okls.cle_id
and l.lse_id = ls.id
and k.contract_number = '23572';
From this query you can see that the relationship between OKC_K_LINES_B and
OKS_K_LINES_B is similar to the relationship for the corresponding tables at the
header level.
The cle_id in OKS_K_LINES_B points to the id in OKC_K_LINES_B.
A new table is introduced, OKC_LINE_STYLES_B. This table has descriptions for the
lse_id, an important identifier in a contract line. From this query you see that the
lse_id indicates that this is a service line.
LTY_CODE BILL_TO_SITE_USE_ID SHIP_TO_SITE_USE_ID
-------------- ----------------------------- ----------------------
SERVICE 3731 6798
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, 'DDMONYYYY' ) "Start Date"
, TO_CHAR( oal.END_DATE, 'DDMONYYYY' ) "End Date"
Oracle CRM Service Contracts Queries
, 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 = '<value of id taken from query A1>'
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 = '<contract number>');
Oracle CRM Service Contracts Queries
Exit the contract and navigate to Setup / Contract / Standard Coverage. Search for
the Gold coverage. Again use Help / Diagnostics / Examine to review the id. Notice
that the values are the same. This is a new feature in R12. The coverages for all
contract lines reference a standard coverage. This allows users to change all
contract coverages simply by modifying the standard coverage.
Oracle CRM Service Contracts Queries
This is returned:
COVERAGE_ID STANDARD_COV_YN
---------------------- ----------------------------
224040514744793365267559317923181517851 N
For reference purposes, run a similar query for a contract line that uses a standard
coverage. You will see that the coverage_id is the id for the standard coverage.
Oracle CRM Service Contracts Queries
The first two columns in the result are from the coverage record. The cle_id in the
coverage points to it’s parent, in this case, the top line.
TO_CHAR(COVERAGE.ID) LTY_CODE
TO_CHAR(TOPLINE.ID) LTY_CODE
---------------------------------- --------------
------------------------------
-------------224040514744793365267559317923181517851 COVERAGE
224040514744789738490100474035657399323 SERVICE
and itbp.object1_id1 = bproc.business_process_id
and reactline.cle_id = bpline.id
and reactline.lse_id = 4
and reactline.id = at.cle_id
and reactline.id = reactoksline.cle_id
and at.cov_action_type_id = att.id
and att.cle_id = reactline.id
and att.action_type_code = 'RCN'
and reactoksline.incident_severity_id = css.incident_severity_id;
Oracle CRM Service Contracts Queries
Let’s examine several of the fields at the line level. How do you identify the item
name? The item information for a contract topline is stored in okc_k_items. The
column object1_id1 has the inventory_item_id, a value that is mapped to the table
mtl_system_items_b. The column object1_id2, is the org_id. The org_id is also stored
in okc_k_headers_all_b.
select substr(k.contract_number,1,25) "Contract Number",
substr(k.contract_number_modifier,1,25) "Modifier Number",
substr(mtl.segment1,1,30) "Service Name",
it.jtot_object1_code "Object Code"
from OKC_K_HEADERS_ALL_B k,
OKC_K_LINES_B okc,
MTL_SYSTEM_ITEMS_B mtl,
OKC_K_ITEMS it
where k.contract_number = '23572'
and k.id = okc.dnz_chr_id
and okc.lse_id = '1'
and okc.id = it.cle_id
and it.object1_id1 = mtl.inventory_item_id
and it.object1_id2 = mtl.organization_id;
The value for object_code isn’t that important for this query, but we will see other
object_code values are used to identify the line or subline type.
Oracle CRM Service Contracts Queries
You may see similarities to a previous header level query. The Bill To and Site
information are stored in OKC_K_LINES_B.
select substr(k.contract_number,1,25) "Contract Number",
substr(okc.line_number,1,10) "Line Number",
okc.bill_to_site_use_id "Bill To",
okc.ship_to_site_use_id "Ship To"
from OKC_K_HEADERS_ALL_B k,
OKC_K_LINES_B okc,
OKS_K_LINES_B oks
where k.contract_number = '23572'
and k.id = okc.dnz_chr_id
and okc.id = oks.cle_id
and okc.lse_id = '1';
Why did I restrict the query to lse_id = 1? The top line lse_id for a Service Line in a
Service Agreement is ‘1’. When in doubt about the values, remember to check the
values in OKC_LINE_STYLES_B.
Oracle CRM Service Contracts Queries
This query displays the invoice text. The text is located in OKS_K_LINES_TL a
translation table for OKS_K_LINES_B. To obtain the information, join the contract
header to the line, the line to the oks line and then the oks line to the translation
table.
select substr(k.contract_number,1,25) "Contract Number",
substr(okc.line_number,1,10) "Line Number",
substr(tl.invoice_text,1,30) "Invoice Text"
from OKC_K_HEADERS_ALL_B k,
OKC_K_LINES_B okc,
OKS_K_LINES_B oks,
OKS_K_LINES_TL tl
where k.contract_number = '23572'
and k.id = okc.dnz_chr_id
and okc.lse_id = '1'
and okc.id = oks.cle_id
and oks.id = tl.id;
Oracle CRM Service Contracts Queries
The contact information is in okc_contacts. Two main okc tables retain the data. The
cle_id (contract line id) is in OKC_K_PARTY_ROLES_B.
select cle_id, rle_code, object1_id1
from OKC_K_PARTY_ROLES_B
where cle_id = 224040514744789738490100474035657399323;
This query returns the party_id, a link to hz_parties for the customer record.
CLE_ID RLE_CODE
OBJECT1_ID1
---------------------------------------------------------------- ------------------------------
----------------------------------------
224040514744789738490100474035657399323 CUSTOMER 4429
CRO_CODE OBJECT1_ID1
------------------------------ ------------------
CUST_BILLING 56854
CUST_SHIPPING 3736
Oracle CRM Service Contracts Queries
The query does not need to access CSI_ITEM_INSTANCES, but the table is included in
case other columns from that table are needed.
Run this query to get a general idea of the type of content in OKC_K_ITEMS. You will
see the object codes that are used to identify usage items, covered system, etc.
select distinct jtot_object1_code
from OKC_K_ITEMS;
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 = '<contract number>')
and lse_id IN(8, 7, 9, 10, 11, 35);
C2. Query for contract sublines for a given contract line only. Replace <parent line
number> 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
Oracle CRM Service Contracts Queries
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 = '<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 = '<contract
number>')
and line_number = <parent 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
Oracle CRM Service Contracts Queries
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 = '<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 ;
Oracle CRM Service Contracts Queries
We know the line id from previous queries. This query returns the information that
appears at the top of the Billing Schedule form.
select okc.inv_rule_id,
oks.acct_rule_id,
oks.billing_schedule_type
from OKC_K_LINES_B okc,
OKS_K_LINES_B oks
where okc.id = oks.cle_id
There are two billing streams in this example. This query returns the pertinent
information.
select sequence_no,
level_periods,
start_date,
end_date,
uom_per_period,
uom_code
from OKS_STREAM_LEVELS_B
where cle_id = 224040514744789738490100474035657399323;
This query displays the schedule information. Again, remember that this information
appears at the subline level too.
select substr(sequence_number,1,15) "Sequence Number",
date_start,
date_end,
amount,
date_completed
from OKS_LEVEL_ELEMENTS
where cle_id = 224040514744789738490100474035657399323
order by sequence_number, date_start;
The date_completed is not populated. This is a critical field in the table. This column
is populated when an invoice is generated for the contract.
Oracle CRM Service Contracts Queries
This is insufficient though because it does not show the information for the sublines.
The level elements table also has a column parent_cle_id, one that is populated with
224040514744789738490100474035657399323 for all of the sublines. A minor
change in the query allows us to display the information for all of the sublines.
select strm.sequence_no "Stream Number",
substr(lvl.sequence_number,1,15) "Sequence Number",
to_char(lvl.parent_cle_id) "Top Level Line ID",
to_char(lvl.cle_id) "Level Element Line ID",
lvl.date_start,
lvl.date_end,
lvl.amount,
lvl.date_completed
from OKS_STREAM_LEVELS_B strm,
OKS_LEVEL_ELEMENTS lvl
where strm.cle_id = lvl.cle_id
and lvl.parent_cle_id = 224040514744789738490100474035657399323;
Oracle CRM Service Contracts Queries
The first entry is for the top line. Notice that the Top Level Line ID and Level Element
Line ID have the same value. The second entry is for the subline, the schedule entry
for May 11 to Nov 10.
Oracle CRM Service Contracts Queries
Lines 3 and 4 are for the next schedule entry for stream 1, the billing schedule for
Nov 11 to Feb 11, 2011.SERVICE CONTRACT BILLING TABLES
Let’s run Main Billing for the first Billing Period. One invoice has been generated.
See what happens to the level elements when this query is rerun after billing.
select substr(sequence_number,1,15) "Sequence Number",
date_start,
date_end,
amount,
date_completed
from OKS_LEVEL_ELEMENTS
where cle_id = 224040514744789738490100474035657399323
order by sequence_number, date_start;
The date_completed is now populated. We know from this query that an invoice has
been generated for schedule entry 1.
Oracle CRM Service Contracts Queries
The bill_action is generally RI, for regular invoice, and TR, for termination.
Oracle CRM Service Contracts Queries
Run the same query again. Notice that there is another entry, a termination, TR,
transaction. The btn_id is not populated. Because it is not yet populated, I know that
Main Billing has not picked up the transaction.
If you compare this result to the one that was run earlier you will see that the Nov 11
entry for the subline, cle_id 224654994456990219633500215272306024339, no
longer exists. The termination process truncated all of the schedule entries if the
date_start is greater than the termination date. The entry still exists at the line level,
only because the subline was terminated, not the line.
Oracle CRM Service Contracts Queries
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 = '<contract number>'
AND NVL(okh.contract_number_modifier,'') = NVL('<contract
modifier>','');
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 = '<contract number>'
AND NVL(contract_number_modifier,'') = Nvl('<contract modifier>',''))
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,
Oracle CRM Service Contracts Queries
okc_k_headers_b okh,
okc_k_lines_b okl
WHERE csi.instance_number = '<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;
hz_cust_acct_sites_all hcas
where 1 = 1
and groups1.name = 'GROUP NAME'
and groups1.language = 'US'
and groups1.id = grpings.cgp_parent_id
and grpings.included_chr_id = k.id
and k.ship_to_site_use_id = hcsu.site_use_id
and hcsu.site_use_code = 'SHIP_TO'
and hca.party_id = hp.party_id
and hps.party_id = hp.party_id
and hps.location_id = hl.location_id
and hcsu.cust_acct_site_id = hcas.cust_acct_site_id
and hcas.party_site_id = hps.party_site_id
and k.ID = okc.dnz_chr_id
and k.ID = ki.dnz_chr_id
and okc.lse_id = 9
and okc.ID = ki.cle_id
and okct.ID = okc.cle_id
and okc.start_date <= SYSDATE
and okc.end_date > SYSDATE
AND k.start_date <= SYSDATE
aND k.end_Date >= SYSDATE
and okct.start_date <= SYSDATE
and okct.end_Date >= SYSDATE
and NVL(okc.date_terminated, SYSDATE + 1) > SYSDATE
and NVL(k.date_terminated, SYSDATE + 1) > SYSDATE
and ki.jtot_object1_code IN ('OKX_CUSTPROD')
and csi.last_vld_organization_id = mtl.organization_id
and TO_NUMBER(ki.object1_id1) = csi.instance_id
and csi.inventory_item_id = mtl.inventory_item_id
Another option without considering the termination date as the filter but just select
the termination date would be:
SELECT k.contract_number, k.start_date, k.end_date,hp.party_name
customer_name, hcsu.location,hl.address1, hl.address2,hl.address3,
hl.city, hl.state, hl.postal_code, hl.country,
cii.serial_number, mtl.segment1 item , mtl.description
item_des,okct.line_number||'.'||okc.line_number, ocl.service_name ,
k.date_terminated
FROM
csi_item_instances cii,
OKC_K_ITEMS ki,
OKC_K_LINES_B okc,
apps.OKS_AUTH_LINES_V okct,
apps.OKS_LINE_DETAILS_V ocl,
OKC_K_HEADERS_B k,
Oracle CRM Service Contracts Queries
mtl_system_items mtl,
okc_k_grpings grpings,
hz_cust_accounts_all hca,hz_parties hp,
hz_cust_site_uses_all hcsu, hz_locations hl,
hz_party_sites hps, hz_cust_acct_sites_all hcas
WHERE 1 = 1
AND TO_NUMBER(ki.object1_id1) = cii.instance_id
AND ki.jtot_object1_code IN ('OKX_CUSTPROD')
AND cii.inv_master_organization_id = 104 Parent Organization ID
AND okct.ID = okc.cle_id
AND okct.id = ocl.line_id (+)
AND okc.lse_id = 9
AND okc.ID = ki.cle_id
AND k.ID = okc.dnz_chr_id
AND k.start_date <= TO_DATE('31DEC2011', 'DDMONYYYY')
AND k.start_date >= TO_DATE('01JAN2011', 'DDMONYYYY')
AND cii.inventory_item_id = mtl.inventory_item_id
AND mtl.organization_id = last_vld_organization_id
AND grpings.cgp_parent_id = 10000 or you can replace this with a
list of Group IDs or all IDs
AND grpings.included_chr_id = k.id
AND k.ship_to_site_use_id = hcsu.site_use_id
AND hcsu.site_use_code = 'SHIP_TO'
AND hca.party_id = hp.party_id
AND hps.party_id = hp.party_id
AND hps.location_id = hl.location_id
AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id
AND hcas.party_site_id = hps.party_site_id
AND hcsu.org_id = 116