Oracle CRM Service Contracts Queries
Oracle CRM Service Contracts Queries
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
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.
okx_install_items_vocsi,
csi_item_instancescii_oks,
ra_customer_trx_allrcta,
ra_customer_trx_lines_allrctla
WHERErctla.customer_trx_id=rcta.customer_trx_id
ANDrctla.interface_line_attribute1=oks_hd.contract_number(+)
ANDNVL(rctla.interface_line_attribute2,'')=NVL
(oks_hd.contract_number_modifier(+),'')
ANDrctla.interface_line_attribute3=txn.bill_instance_number(+)
ANDbsl.cle_id=oks_ln.ID
ANDNVL(txn.bsl_id,999)=DECODE(txn.bsl_id,NULL,999,bsl.ID)
ANDtxn.bcl_id=bsl.bcl_id
ANDoks_ln.ID=oks_ln_sub.cle_id(+)
ANDoks_ln.ID=oki.cle_id(+)
ANDoki.object1_id1=ocsi.id1(+)
ANDoki.object1_id2=ocsi.id2(+)
ANDocsi.instance_id=cii_oks.instance_id(+)
ANDrcta.trx_number='&your_trans_num'
ANDoks_hd.contract_number='&your_contr_num'
jtot_object1_code Contact ID
------------------------ -------------OKX_PCONTACT
401670
OKX_RESOURCE
10199
The resource information is located in a table and a view. Either of these queries will
return the information:
select*fromOKX_RESOURCES_V
whereid1=10199;
select*fromJTF_RS_RESOURCE_EXTNS
whereresource_id=10199;
D3. This query returns data about the contract Line ids corresponding to each invoice
as well as invoice details.
SELECTBCL.id
,BCL.cle_id
,BCL.btn_id
,BCL.bill_action
,OKL.id"Lineid"
,OKH.id"Contractid"
,BTN.TRX_NUMBER"Invoice"
,bcl.date_billed_from
,bcl.date_billed_to
FROMOKS_BILL_CONT_LINESBCL,
OKC_K_LINES_BOKL,
OKC_K_HEADERS_BOKH,
OKS_BILL_TRANSACTIONSBTN,
OKS_BILL_TXN_LINESBTL
WHEREOKH.contract_number='<contractnumber>'
AndOKH.ID=OKL.DNZ_CHR_ID
AndOKL.CLE_IDISNULL
AndOKL.ID=BCL.CLE_ID
AndBTN.ID=BCL.BTN_ID
AndBTL.BTN_ID=BTN.ID
AndBTL.BILL_INSTANCE_NUMBERISNOTNULL;
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.
SELECTTO_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
FROMoks_bill_sub_linesbsl
,oks_bill_cont_linesbcl
,oks_level_elementslvl
,okc_K_LINES_Bkl
,okc_k_headers_bkh
WHEREkh.contract_number='&enter_contract_number'
ANDkl.dnz_chr_id=kh.id
ANDlvl.dnz_chr_id=kh.id
ANDbcl.cle_id=kl.id
ANDbcl.id=bsl.bcl_id
ANDlvl.cle_id=bsl.cle_id;
This query returns the Quote To information. It is a single query from multiple tables.
The query can be simplified to return specific fields.
selectsubstr(okc.contract_number,1,30)"ContractNumber",
hca.account_number"AccountNumber",
substr(hca.account_name,1,40)"AccountName",
substr(csv.description,1,60)"QuoteToAddress",
substr(hp.party_name,1,40)"ContactPartyName",
substr(cp.email_address,1,30)"EmailAddress",
oks.quote_to_contact_id,
car.cust_account_role_id,
car.party_id,
car.cust_account_id
fromOKS_K_HEADERS_Boks,
OKC_K_HEADERS_ALL_Bokc,
HZ_CUST_ACCOUNT_ROLEScar,
HZ_CUST_ACCOUNTShca,
HZ_CONTACT_POINTScp,
HZ_PARTIEShp,
OKX_CUST_SITES_Vcsv
whereoks.chr_id=okc.id
andoks.quote_to_contact_id=car.cust_account_role_id
andoks.quote_to_email_id=cp.contact_point_id
andhp.party_id=car.party_id
andcar.cust_account_id=hca.cust_account_id
andoks.quote_to_site_id=csv.id1
andokc.contract_number='23572';
Thequote_to_contact_idinOKS_K_HEADERS_Bmapsto
HZ_CUST_ACCOUNT_ROLES,
which then maps to HZ_CONTACT_POINTS.
The quote_to_email_id maps in OKS_K_HEADERS_B maps to HZ_CONTACT_POINTS
The quote_to_site_id in oks_k_headers_b is mapped to OKX_CUST_SITES_V
Refer to Note 471398.1 , How to Find the Quote To Party ID in a Service
Agreement, for additional information.
This query can be used to obtain the contract group(s) for a contract.
selectsubstr(k.contract_number,1,25)"ContractNumber",
substr(k.contract_number_modifier,1,25)"Modifier",
substr(tl.name,1,25)"GroupName"
fromOKC_K_HEADERS_ALL_Bk,
OKC_K_GRPINGSgp,
OKC_K_GROUPS_TLtl
wheregp.included_chr_id=k.id
andk.contract_number_modifierisnull
andtl.language='US'
ANDgp.cgp_parent_id=tl.id
andk.contract_number='23572';
Contract Number
----------------------23572
selectls.lty_code,
l.bill_to_site_use_id,
l.ship_to_site_use_id
fromokc_k_headers_all_bk,
OKC_K_LINES_Bl,
OKS_K_LINES_Bokls,
OKC_LINE_STYLES_Bls
wherek.id=l.dnz_chr_id
andl.id=okls.cle_id
andl.lse_id=ls.id
andk.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
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
SELECTDISTINCToal.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')"StartDate"
,TO_CHAR(oal.END_DATE,'DDMONYYYY')"EndDate"
,qpl.NAME"PriceListName"
,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
FROMoks_auth_lines_voal
,okc_launch_lgrid_voll
,qp_pricelists_lov_vqpl
,oks_line_details_vold
WHEREoal.id=oll.id
ANDcle_idISNULL
ANDqpl.PRICE_LIST_ID=oal.PRICE_LIST_ID
ANDold.CONTRACT_ID=oll.chr_id
ANDoll.chr_id='<valueofidtakenfromqueryA1>'
ORDERBYto_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*
fromOKC_K_LINES_B
whereCHR_IDIN(selectid
fromokc_k_headers_b
wherecontract_number='<contractnumber>');
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.
anditbp.object1_id1=bproc.business_process_id
andreactline.cle_id=bpline.id
andreactline.lse_id=4
andreactline.id=at.cle_id
andreactline.id=reactoksline.cle_id
andat.cov_action_type_id=att.id
andatt.cle_id=reactline.id
andatt.action_type_code='RCN'
andreactoksline.incident_severity_id=css.incident_severity_id;
Lets 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.
selectsubstr(k.contract_number,1,25)"ContractNumber",
substr(k.contract_number_modifier,1,25)"ModifierNumber",
substr(mtl.segment1,1,30)"ServiceName",
it.jtot_object1_code"ObjectCode"
fromOKC_K_HEADERS_ALL_Bk,
OKC_K_LINES_Bokc,
MTL_SYSTEM_ITEMS_Bmtl,
OKC_K_ITEMSit
wherek.contract_number='23572'
andk.id=okc.dnz_chr_id
andokc.lse_id='1'
andokc.id=it.cle_id
andit.object1_id1=mtl.inventory_item_id
andit.object1_id2=mtl.organization_id;
Contract Number Modifier Number Service Name Object Code
------------------------ ------------------------ ------------------- ----------------23572
WRTEST
OKX_SERVICE
The value for object_code isnt that important for this query, but we will see other
object_code values are used to identify the line or subline type.
You may see similarities to a previous header level query. The Bill To and Site
information are stored in OKC_K_LINES_B.
selectsubstr(k.contract_number,1,25)"ContractNumber",
substr(okc.line_number,1,10)"LineNumber",
okc.bill_to_site_use_id"BillTo",
okc.ship_to_site_use_id"ShipTo"
fromOKC_K_HEADERS_ALL_Bk,
OKC_K_LINES_Bokc,
OKS_K_LINES_Boks
wherek.contract_number='23572'
andk.id=okc.dnz_chr_id
andokc.id=oks.cle_id
andokc.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.
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.
selectsubstr(k.contract_number,1,25)"ContractNumber",
substr(okc.line_number,1,10)"LineNumber",
substr(tl.invoice_text,1,30)"InvoiceText"
fromOKC_K_HEADERS_ALL_Bk,
OKC_K_LINES_Bokc,
OKS_K_LINES_Boks,
OKS_K_LINES_TLtl
wherek.contract_number='23572'
andk.id=okc.dnz_chr_id
andokc.lse_id='1'
andokc.id=oks.cle_id
andoks.id=tl.id;
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.
selectcle_id,rle_code,object1_id1
fromOKC_K_PARTY_ROLES_B
wherecle_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
Use the cle_id to find the entry in okc_contacts:
selectcontact.cro_code,contact.object1_id1
fromOKC_K_PARTY_ROLES_Bpr,
OKC_CONTACTScontact
wherecontact.cpl_id=pr.id
andpr.cle_id=224040514744789738490100474035657399323
CRO_CODE
OBJECT1_ID1
------------------------------ -----------------CUST_BILLING
56854
CUST_SHIPPING
3736
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
fromOKC_K_LINES_B
whereDNZ_CHR_IDIN(selectid
fromokc_k_headers_b
wherecontract_number='<contractnumber>')
andlse_idIN(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
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
fromOKC_K_LINES_B
whereDNZ_CHR_IDIN(selectid
fromokc_k_headers_b
wherecontract_number='<contractnumber>')
andcle_idIN(selectid
fromokc_k_lines_b
wherechr_idIN(selectid
fromokc_k_headers_b
wherecontract_number='<contract
number>')
andline_number=<parentlinenumber>)
andlse_idIN(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).
SELECTkl.line_number,
ks.NAME
,i.segment1
FROM
okc_k_headers_bkh,
okc_k_lines_bkl,
okc_k_itemski,
okc_line_styles_vks,
csi_item_instancesc,
mtl_system_items_bi
WHERE
kh.contract_number='<contractnumber>'
ANDkh.contract_number_modifierISNULLcanbepopulated
ANDkh.ID=kl.dnz_chr_id
ANDkh.ID=ki.dnz_chr_id
ANDkl.ID=ki.cle_id
ANDkl.lse_id=ks.ID
ANDki.jtot_object1_codeIN('OKX_CUSTPROD')
ANDc.last_vld_organization_id=i.organization_id
ANDTO_NUMBER(ki.object1_id1)=c.instance_id
ANDc.inventory_item_id=i.inventory_item_id;
We know the line id from previous queries. This query returns the information that
appears at the top of the Billing Schedule form.
selectokc.inv_rule_id,
oks.acct_rule_id,
oks.billing_schedule_type
fromOKC_K_LINES_Bokc,
OKS_K_LINES_Boks
whereokc.id=oks.cle_id
and okc.id = 224040514744789738490100474035657399323;
INV_RULE_ID
ACCT_RULE_ID
BILLING_SCHEDULE_TYPE
--------------------------------------------------------------------2
1
T
The unbilled, credit, suppressed credit amount, etc. are also stored in
OKS_K_LINES_B.
There are two billing streams in this example. This query returns the pertinent
information.
selectsequence_no,
level_periods,
start_date,
end_date,
uom_per_period,
uom_code
fromOKS_STREAM_LEVELS_B
wherecle_id=224040514744789738490100474035657399323;
SEQUENCE_NO
LEVEL_PERIODS
START_DATE
END_DATE
UOM_PER_PERIOD
UOM_CODE
------------------------------------------------------------------------------------------------------------------1
1
11-MAY-10
10-NOV-10
6
MTH
2
2
11-NOV-10
10-MAY-11
1
QRT
Remember that these billing streams exist at the subline level too.
This query displays the schedule information. Again, remember that this information
appears at the subline level too.
selectsubstr(sequence_number,1,15)"SequenceNumber",
date_start,
date_end,
amount,
date_completed
fromOKS_LEVEL_ELEMENTS
wherecle_id=224040514744789738490100474035657399323
orderbysequence_number,date_start;
Sequence Number DATE_START
DATE_COMPLETED
------------------------- -----------------------------------------1
11-MAY-10
1
11-NOV-10
2
11-FEB-11
DATE_END
AMOUNT
---------------
--------------
10-NOV-10
10-FEB-11
10-MAY-11
55
27.5
27.5
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.
DATE_END
---------------
10-NOV-10
10-NOV-10
224040514744789738490100474035657399323 11-NOV-10
27.5
1
1
224040514744789738490100474035657399323
224654994456990219633500215272306024339 11-NOV-10
27.5
10-FEB-11
10-FEB-11
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.
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
Lets 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.
selectsubstr(sequence_number,1,15)"SequenceNumber",
date_start,
date_end,
amount,
date_completed
fromOKS_LEVEL_ELEMENTS
wherecle_id=224040514744789738490100474035657399323
orderbysequence_number,date_start;
Sequence Number DATE_START
DATE_COMPLETED
------------------------- -----------------------------------------1
11-MAY-10
10-NOV-10
1
11-NOV-10
2
11-FEB-11
DATE_END
AMOUNT
---------------
--------------
10-NOV-10
10-FEB-11
10-MAY-11
55
27.5
27.5
The date_completed is now populated. We know from this query that an invoice has
been generated for schedule entry 1.
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.
Contract Number Modifier
Creation Date
TO_CHAR(BCL.BTN_ID)
TO_CHAR(BCL.CLE_ID)
BILL_ACTION AMOUNT
----------------------- -------------------------------------------------------------------------------------------------------------------- -------------23572
05/19/2010 17:29:24
224763666759272367907400019617050675714
224040514744789738490100474035657399323 RI
55
23572
05/19/2010 17:57:30
224040514744789738490100474035657399323 TR
-52.61
DATE_END
---------------
10-NOV-10
10-NOV-10
224040514744789738490100474035657399323 11-NOV-10
0
10-FEB-11
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.
okc_k_headers_bokh,
okc_k_lines_bokl
WHEREcsi.instance_number='<InstanceNumber>'
ANDose.order_line_id=csi.last_oe_order_line_id
ANDokh.id=ose.dnz_chr_id
ANDokl.chr_id=okh.id
ANDokl.id=ose.dnz_cle_id;
G. Order Details for Contracts Created from Order Management
G1. Query which retrieves the order header id and order line id for a given contract.
object1_id1 gives the order header id where jtot_object1_code = OKX_ORDERHEAD
and the order line id where jtot_object1_code = OKX_ORDERLINE
selectokl.idSubline
,okl.cle_idService_Line
,okl.dnz_chr_id
,obj.object1_id1
,obj.jtot_object1_code
fromokc_k_lines_bokl
,okc_k_rel_objs_vobj
whereokl.dnz_chr_id=obj.chr_id
andokl.dnz_chr_id=<contractidfromqueryA1>
andlse_idin(7,8,9,10,11,18,25,35);
G2. The table OKS_K_ORDER_DETAILS captures service contract details when a
service is ordered in Order Management.
SELECT*
FROMOKS_K_ORDER_DETAILS
WHERE
CHR_ID=<contractidfromqueryA1>
hz_cust_acct_sites_allhcas
where1=1
andgroups1.name='GROUPNAME'
andgroups1.language='US'
andgroups1.id=grpings.cgp_parent_id
andgrpings.included_chr_id=k.id
andk.ship_to_site_use_id=hcsu.site_use_id
andhcsu.site_use_code='SHIP_TO'
andhca.party_id=hp.party_id
andhps.party_id=hp.party_id
andhps.location_id=hl.location_id
andhcsu.cust_acct_site_id=hcas.cust_acct_site_id
andhcas.party_site_id=hps.party_site_id
andk.ID=okc.dnz_chr_id
andk.ID=ki.dnz_chr_id
andokc.lse_id=9
andokc.ID=ki.cle_id
andokct.ID=okc.cle_id
andokc.start_date<=SYSDATE
andokc.end_date>SYSDATE
ANDk.start_date<=SYSDATE
aNDk.end_Date>=SYSDATE
andokct.start_date<=SYSDATE
andokct.end_Date>=SYSDATE
andNVL(okc.date_terminated,SYSDATE+1)>SYSDATE
andNVL(k.date_terminated,SYSDATE+1)>SYSDATE
andki.jtot_object1_codeIN('OKX_CUSTPROD')
andcsi.last_vld_organization_id=mtl.organization_id
andTO_NUMBER(ki.object1_id1)=csi.instance_id
andcsi.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:
SELECTk.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.segment1item,mtl.description
item_des,okct.line_number||'.'||okc.line_number,ocl.service_name,
k.date_terminated
FROM
csi_item_instancescii,
OKC_K_ITEMSki,
OKC_K_LINES_Bokc,
apps.OKS_AUTH_LINES_Vokct,
apps.OKS_LINE_DETAILS_Vocl,
OKC_K_HEADERS_Bk,
mtl_system_itemsmtl,
okc_k_grpingsgrpings,
hz_cust_accounts_allhca,hz_partieshp,
hz_cust_site_uses_allhcsu,hz_locationshl,
hz_party_siteshps,hz_cust_acct_sites_allhcas
WHERE1=1
ANDTO_NUMBER(ki.object1_id1)=cii.instance_id
ANDki.jtot_object1_codeIN('OKX_CUSTPROD')
ANDcii.inv_master_organization_id=104ParentOrganizationID
ANDokct.ID=okc.cle_id
ANDokct.id=ocl.line_id(+)
ANDokc.lse_id=9
ANDokc.ID=ki.cle_id
ANDk.ID=okc.dnz_chr_id
ANDk.start_date<=TO_DATE('31DEC2011','DDMONYYYY')
ANDk.start_date>=TO_DATE('01JAN2011','DDMONYYYY')
ANDcii.inventory_item_id=mtl.inventory_item_id
ANDmtl.organization_id=last_vld_organization_id
ANDgrpings.cgp_parent_id=10000oryoucanreplacethiswitha
listofGroupIDsorallIDs
ANDgrpings.included_chr_id=k.id
ANDk.ship_to_site_use_id=hcsu.site_use_id
ANDhcsu.site_use_code='SHIP_TO'
ANDhca.party_id=hp.party_id
ANDhps.party_id=hp.party_id
ANDhps.location_id=hl.location_id
ANDhcsu.cust_acct_site_id=hcas.cust_acct_site_id
ANDhcas.party_site_id=hps.party_site_id
ANDhcsu.org_id=116