How to read Tkprof

KPROF: Release 12.2.0.1.0 - Development on Thu Dec 27 05:39:56 2018 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. Trace file: tracefile_10046.trc Sort options: default count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call SQL ID: 4m94ckmu16f9k Plan Hash: 3910148636 select count(*) from dual call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 2 0.00 0.00 0 0 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 0.00 0.00 0 0 0 1 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: SYS Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 1 1 1 SORT AGGREGATE (cr=0 pr=0 pw=0 time=21 us starts=1) 1 1 1 FAST DUAL (cr=0 pr=0 pw=0 time=1 us starts=1 cost=2 size=0 card=1) Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ Disk file operations I/O 1 0.00 0.00 SQLNet message to client 2 0.00 0.00 SQLNet message from client 2 10.63 10.63 TKProf output file mainly has following sections:- 1. Tabular Statistics 2. Row Source Operations 3. Wait Event Information We’ll study each section individually. Section 1: Tabular Statistics:- call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 2 0.00 0.00 0 0 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 4 0.00 0.00 0 0 0 1 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: SYS Number of plan statistics captured: 1 To understand these statistics we should understand following CALLS. PARSE: Translates the SQL statement into an execution plan, including checks for proper security authorization and checks for the existence of tables, columns, and other referenced objects. EXECUTE: Actual execution of the statement by Oracle. For INSERT, UPDATE, and DELETE statements, this modifies the data. For SELECT statements, this identifies the selected rows. FETCH: Retrieves rows returned by a query. Fetches are only performed for SELECT statements. The other columns of the TKProf output are combined statistics for all parses, all executes, and all fetches of a statement. All column names are self explanatory but just to give a brief idea:- count: It is the number of times a call (parse/execute/fetch) was performed. cpu: Total CPU time in seconds elapsed: Total elapsed time in seconds disk: Total number of data blocks physically read from the data files on disk. query: Total number of buffers retrieved in consistent mode. current: Total number of buffers retrieved in current mode. rows: Total number of rows processed by the SQL statement. Sum of query & current columns is the total number of buffers accessed i.e. LIOs. In this section, we should first look if any operation that is taking high number of cpu times. Or if we have high number of block reads i.e. query column, specially if the block read LIOs are very high compared to number of rows fetched. Another important thing is to see if there is lot of hard parsing which can be seen from count of parse call and the number of times it was hard parsed i.e. misses in library cache. All these things give a sense if there is something wrong with query or not and if there is a problem then where ? I would try to include some examples of Tabular Statistics in subsequent posts for scenarios where we have some problem with library cache or buffer cache etc. Section 2: Row Source Operations Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 1 1 1 SORT AGGREGATE (cr=0 pr=0 pw=0 time=21 us starts=1) 1 1 1 FAST DUAL (cr=0 pr=0 pw=0 time=1 us starts=1 cost=2 size=0 card=1) Where cr is consistent reads, pr is physical reads, pw is physical writes, time is time in microseconds. From Tabular Statistics we can understand if there is any problem with the query and then we can refer to Row Source Operations to see what operations are costly. Section 3: Wait Event Information We know if there is problem with a hint about the problem area from tabular statistics and the most costly operation from row source operation, now we can get the details where this query is waiting from wait event information. Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ Disk file operations I/O 1 0.00 0.00 SQLNet message to client 2 0.00 0.00 SQLNet message from client 2 10.63 10.63 This is another important section of TKProf output file as it gives us the details on the wait events on which the query is waiting. We can use Wait Event Information and link it to the theory deduced from tabular statistics to confirm the bottleneck of the query. From this information we can either try to reduce the cause for the waits or from row source information see if any other alternate access method can be used.

Discounts ,discount grace periods in oracle apps r12 ,account receivable Setup Payment Terms

  

Discounts:

Current State

At present Vista uses a billing extension for the purposes of generating revenue and invoices.  However, Vista also has customers for which they apply discounts.  Due to the implementation of the billing extension the standard Discount functionality is not available therefore, the coding for the extension needs to be updated to take the discounts into account.

Approach

The billing extension will be modified to identify if a discount has been assigned on the project per the screen shots below:

 When a labor discount is identified the revenue and invoice amounts will be reduced by the amount of the discount.


 

Standard Process in Oracle Receivables

1. Overview

Receivables lets you apply discounts to your customers when they pay for their invoices before a certain date. Discounts are determined by the payment terms you assign to your customers. You can also choose whether to allow discounts for partial payments and specify how you want Receivables to calculate the discount on your invoices.

Earned Discount: An earned discount is a discount you give to a customer who pays on or before the discount date or within the discount grace period. For example, a customer may earn a 2% discount on the original invoice if payment is received within 10 days. The earned discount period is determined by the invoice date, apply date of the receipt and any discount grace days.

When determining the discount percent for earned discounts, Receivables uses the invoice date, discount grace days, and the apply date of the receipt to determine the discount percentage for this payment term

Unearned Discount: Unearned discounts are discounts that you allow after the earned discount period has passed. The default discount taken is zero if the discount is unearned.

When determining the discount percent for unearned discounts, Receivables uses the maximum discount allowed for this payment term. To allow unearned discounts, set Allow Unearned Discounts to Yes in the System Options window

Entering Discounts:



Formulas Used to Calculate Discounts

Maximum Discount
Use the following formula to determine the maximum discount amount:
Maximum Discount = Amount Due Original * Highest Discount Percent - Discount Taken

Earned Discounts and Partial Payments Allowed

If the receipt amount is more than the amount due remaining less the discount, Receivables uses the following formula to determine the earned discount:
Earned Discount = Amount Due Remaining * Discount Percent
If the receipt amount is either the same or less than the amount due remaining less the discount, Receivables uses the following formula to determine the earned discount:
Earned Discount = (Receipt Amount * Discount Percent) / 1 - Discount Percent.

 

Unearned Discounts with Partial Payment Discounts Allowed
Receivables use the following formula to determine unearned discounts if partial payments are allowed:
Unearned Discount = Maximum Discount - Earned Discount

Earned Discounts with Partial Payment Discounts Not Allowed
If the Allow Discount on The partial Payments check box for your payment terms is not checked, Receivables only takes discounts if the receipt amount closes the installment
Receivables use the following formula to determine earned discounts if partial payment discounts are not allowed:
Earned Discount = Amount Due Original * Discount Percent

Unearned Discounts and Partial Payments Not Allowed
If the Allow Discount on Partial Payments check box for your payment terms is not checked, Receivables only takes discounts if the receipt amount closes the installment.
Receivables use the following formula to determine unearned discounts if partial payments are not allowed:
Unearned Discount = Amount Due Original * Maximum Discount Percent - Earned Discount

Discount on Lines Only
If the Discount Basis option for your payment term is set to Lines Only, Receivables does not take discounts on receipt amounts applied to tax, freight, or late charges and uses the following formula to determine the discount amount:
Line Percent = Discount Percent * (Sum of Lines + Sum of Line Adjustments - Sum of
Line Credits / Amount Due Original + Sum of Adjustments - Sum of Credits)
Once you determine the discount line percent, use this as the discount percent in the formulas above.

2. Setup for Discounts

2.1. Setup Payment Terms

Define your payment terms in the Payment Terms window. Enter a discount percent, choose whether to allow discounts on partial payments and select a discount basis.

Responsibility: Receivables Manager
Navigation: Setup > Transactions > Payment Terms

Define your payment terms in the Payment Terms window. Enter a discount percent, choose whether to allow discounts on partial payments and select a discount basis.

Click the Discounts push button


2.2 Setup System Options

Choose whether to allow partial and unearned discounts in the System Options window.

Responsibility:
 Receivables Manager
Navigation: Setup > System > System Options > Miscellaneous tab


In Vision demo instance:

 


 

2.3 Define earned and unearned discount accounts

Define your earned and unearned discount accounts in the Bank Accounts window

Responsibility:
 Receivables Manager
Navigation: Setup > Receipts >Receipt Classes > Query the class
Choose the Receipt Method >  
Click Bank Accounts to navigate to Remittance Bank Accounts window
In the GL Accounts tab
Earned and Unearned discounts are the receivable activities that need to be selected here

2.4 Setup Customer to allow discounts

Choose whether to allow discounts and assign discount grace days to your customers in the Customer Profile Classes window or the Profile: Transaction tabbed region of the Customers window.
The values you define in the Customers window take precedence over those in the Customer Profile Classes window.

Responsibility: Receivables Manager
Navigation: Customer > Profile Classes

3. Defaulting Discount Amounts

When entering receipts manually, Receivables determines whether discounts are allowed based on the payment terms, discount grace days, system options, transaction date, and receipt apply date. If discounts are allowed, Receivables determines the amount of earned and unearned discounts and displays this information in the Discount field.

Receivables defaults applied receipt amounts into the receipt application windows. The default amount applied is the remaining amount of the transaction, less any available discount. However, if the remaining amount of the receipt is less then the balance of the transaction, the default amount applied is the remaining amount of the receipt and Receivables takes the discount available on the transaction.


 

Discounts are calculated based on the following setups:

1. Payment Term with Billing Cycle Assigned.
2. Payment Term without a Billing Cycle.

Discount Date calculation:
Code Used: AR_TRX_DISCOUNTS_V

1. Payment Term with Billing Cycle Assigned.

The discount date is calculated based on the Billing Date.
This is true whether the customer/customer site/transaction is enabled for Balance Forward Billing or not.

Example:
A.
   Create payment term: Due15th, Cut25
   Billing Cycle (Cutoff-day) 
                          -- Day of Month: 25

   Payment Schedule 
                           -- Day of Month: 15
                           -- Months Ahead: 1

   Discount            
            --  Day of Month: 01
                           --  Months Ahead: 1
                           --  Percent : 10

case 1(Discount to be calculated based on billing date):

    Transaction created with 
          Trx_date         : 26-JUN-2015
          Billing_date     : 25-JUL-2015
          Due_date        : 15-AUG-2015  
          Discount_date  : 01-AUG-2015 

case 2(Discount to be calculated based on billing date):

    Transaction created with 
        Trx_date    : 24-JUN-2015
          Billing_date    : 25-JUN-2015
          Due_date       : 15-JUL-2015  
          Discount_date : 01-JUL-2015 

B.
   Create payment term: Due15th,Cut25
   Billing Cycle (Cutoff-day) 
                           -- Day of Month: 25

   Payment Schedule 
                           -- Day of Month: 15
                           -- Months Ahead: 1

   Discount            
                           --  Days     : 10
                           --  Percent     : 10


    Transaction created with 
        Trx_date    : 26-JUN-2015
          Billing_date    : 25-JUL-2015
          Due_date    : 15-AUG-2015  
          Discount_date    : 04-AUG-2015 

2. Payment Term without Billing Cycle

The discount date is calculated based on the Transaction Date.


Example:
A.
   Create payment term: Due15th

   Payment Schedule 
                           -- Day of Month: 15
                           -- Months Ahead: 1

   Discount            
                           --  Day of Month: 01
                           --  Months Ahead: 1
                           --  Percent : 10

case 1(Discount to be calculated based on Trx_date):
     Transaction created with 
          Trx_date         : 26-JUN-2015
          Due_date        : 15-JUL-2015  
          Discount_date  : 01-JUL-2015 



case 2(Discount to be calculated based on Trx_date):
--------------------------------------------------------
    Transaction created with 
         Trx_date          : 24-JUN-2015
          Due_date        : 15-JUL-2015  
          Discount_date  : 01-JUL-2015 

B.
   Create payment term: Due15th

   Payment Schedule 
                           -- Day of Month: 15
                           -- Months Ahead: 1

   Discount            
                           --  Days     : 10
                           --  Percent     : 10


    Transaction created with 
          Trx_date       : 26-JUN-2015
          Due_date      : 15-JUL-2015  
          Discount_date: 04-JUL-2015 

 

 


 

Discount Rounding calculated for earned Discounts for Receipts within Oracle Receivables.

The example below, which will explain how Discount Rounding is calculated

Following are the terms:

1. Payment Terms/Discount on line -3% (days 30)
2. Tax rounding in system options -nearest/precision 2
3. Customer discount at site level-Allow discount (checked), grace days 0.
4. Tax inclusive rate 7 %
.
Casse1:
1.Create a transaction of line 1346.17, tax calculates to 94.23
2.Create a receipt of 1400.01
3.Apply receipt to invoice.
4. Before saving, the discount amount is 40.39 (40.385) -Rounded Up-
.
Case 2:
1.Create a transaction of line 5025.5, tax calculates to 351.79
2.Create a receipt of 5377.29
3.Apply receipt to invoice.
4. Before saving, the discount amount is 150.76 (150.765). -Rounded Down-


The reason behind the discounts being rounding to different sides in the above cases is due to the fact that system also takes the division of the line amount by the total invoice amount and amount due remaining into account while doing discount calculation. In the two test cases above there is a difference in the in the interim calculations due to which the final values are coming different.

This is how it is getting calculated in these two test cases (short names used):

Case 1:
L1: 1346.17 T1: 94.23, amt due remaining = 1440.4
l_multiplier = 1346.17/1440.4 = 934580672
disc pct = .03 , earned disc pct = 0.03 * 934580672 = .02803742016
Now earned discount uses amt due remaining in its calculation here:
earned discount = earned disc pct * amount due remaining.
so it is = .02803742016 * 1440.4 = 40.385099998464
This rounded off to 40.39 standard PL-SQL ROUND function.

 

 


Case 2:
L1: 5025.5 , T1: 351.79 , amt due remaining = 5377.29
l_multiplier : 5025.2/5377.29 = .9345785702
disc pct = .03 , earned disc pct = 0.03 * .9345785702 = .028037357106
Here the earned discount comes to be :
.028037357106 * 5377.29 = 150.76499999252274 which now finally Rounds to 150.76.
Hence the difference. So there may be differences due to difft l_multiplier values and its
product with amount due remaining values.

To add conclusion to above discussion, the discount calculation does not takes into account any
rounding rule defined anywhere, whether in the system options or in the currency details. The rounding rule which is defined in the system options is for TAX rounding and has nothing to do with discounts. So there is no such rule that discount should only round in any particular direction- up or down or nearest. It takes final value depending upon above calculations.

 

The following table’s stores discount amount information:

Similar to AP in AR the AR_PAYMENT_SCHEDULES_ALL table captures the discount details

 

ZX_LINES_DET_FACTORS.CASH_DISCOUNT

 

AR_RECEIVABLE_APPLICATIONS_ALL.LINE_EDISCOUNTED

AR_RECEIVABLE_APPLICATIONS_ALL.ACCTD_EARNED_DISCOUNT_TAKEN

AR_RECEIVABLE_APPLICATIONS_ALL.EARNED_DISCOUNT_TAKEN

 

AR_PAYMENT_SCHEDULES_ALL.DISCOUNT_REMAINING      

AR_PAYMENT_SCHEDULES_ALL.DISCOUNT_TAKEN_EARNED