Pages

OracleEBSpro is purely for knowledge sharing and learning purpose, with the main focus on Oracle E-Business Suite Product and other related Oracle Technologies.

I'm NOT responsible for any damages in whatever form caused by the usage of the content of this blog.

I share my Oracle knowledge through this blog. All my posts in this blog are based on my experience, reading oracle websites, books, forums and other blogs. I invite people to read and suggest ways to improve this blog.


Monday, November 3, 2014

Reprice an Order Line or Order

Suppose you need to price all lines of an order using pl/sql script, you may use following script. Advantage of using OE_LINE_REPRICE.Reprice_Line procedure:

  1. You will have access to correct value of oe_order_pub.g_line.line_id in QP_CUSTOM.get_custom_price procedure 

CREATE OR REPLACE PROCEDURE skm_reprice_lines
( p_header_id NUMBER
) IS
  l_line_rec      OE_Order_Pub.Line_Rec_Type;
  l_return_status VARCHAR2(10);
  i NUMBER;
  l_msg_data VARCHAR2(250);
  
  CURSOR c_lines IS
     SELECT line_id
       FROM oe_order_lines_all
      WHERE header_id = p_header_id;
BEGIN

  OE_DEBUG_PUB.debug_on();
  OE_DEBUG_PUB.Start_ONT_Debugger('/home/users/smisra','skm1',null);

  DBMS_APPLICATION_INFO.set_client_info('1');

  FOR l_line IN c_lines 
  LOOP
    OE_Line_Util.Query_Row
    ( p_line_id     =>    l_line.line_id
    , x_line_rec    =>    l_line_rec
    );

    DBMS_OUTPUT.put_line('Line Id:' || l_line_rec.line_id);
    DBMS_OUTPUT.put_line('ordered_item:' || l_line_rec.ordered_item);
    OE_LINE_REPRICE.Reprice_Line
    ( p_line_rec         => l_line_rec
    , p_Repricing_date    => 'SYSDATE'
    , p_Repricing_event    => 'LINE'
    , p_Honor_Price_Flag  => 'Y'
    , x_return_status    => l_return_status
    ) ;
  END LOOP;
 
  DBMS_OUTPUT.put_line('Return Message:' || l_return_status);

  IF fnd_msg_pub.count_msg > 0
  THEN
     FOR j in 1..FND_MSG_PUB.count_msg
     LOOP
        FND_MSG_PUB.get
        ( p_msg_index      => j
        , p_encoded       => 'F'
        , p_data          => l_msg_data
        , p_msg_index_out => i
        );
        dbms_output.put_line( 'Error: ' || j || ':' || l_msg_data);
     END LOOP;
  END IF;

OE_DEBUG_PUB.debug_off();
END;
/

References:
http://sanjaimisra.blogspot.com/2008/05/reprice-order-line.html

PROCEDURE reprice_order (p_in_header_id IN NUMBER)
   IS
      v_header_count    NUMBER;
      v_header_list     VARCHAR2 (32000);
      v_line_count      NUMBER;
      v_line_list       VARCHAR2 (32000);
      v_price_level     VARCHAR2 (32000);
      v_return_status   VARCHAR2 (32000);
      v_msg_count       NUMBER;
      v_msg_data        VARCHAR2 (32000);
   BEGIN

      v_header_count := 1;
      v_header_list := TO_CHAR (p_in_header_id);
      v_price_level := 'ORDER';

      BEGIN
         oe_order_adj_pvt.price_action (p_header_count       => v_header_count,
                                        p_header_list        => v_header_list,
                                        p_line_count         => v_line_count,
                                        p_line_list          => v_line_list,
                                        p_price_level        => v_price_level,
                                        x_return_status      => v_return_status,
                                        x_msg_count          => v_msg_count,
                                        x_msg_data           => v_msg_data
                                       );
         COMMIT;

         IF (v_return_status != fnd_api.g_ret_sts_success)
         THEN
            dbms_output.put_line(v_msg_data);
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            dbms_output.put_line(sqlerrm);
      END;
   EXCEPTION
      WHEN OTHERS
      THEN
        dbms_output.put_line(sqlerrm);
   END reprice_order;

References:
http://www.oracleappstoday.com/2014/08/api-to-reprice-order-total-in-oracle-r12.html

How does one add a day/hour/minute/second to a date value?

DATE is the datatype that we are all familiar with when we think about representing date and time values. It has the ability to store the month, day, year, century, hours, minutes, and seconds. It is typically good for representing data for when something has happened or should happen in the future. The problem with the DATE datatype is its' granularity when trying to determine a time interval between two events when the events happen within a second of each other. This issue is solved with the TIMESTAMP datatype. 
In order to represent the date stored in a more readable format, the TO_CHAR function has traditionally been wrapped around the date: 

SQL> SELECT TO_CHAR(hiredate,'DD.MM.YYYY:HH24:MI:SS') "hiredate"
  FROM employees; 
hiredate
-------------------
17.12.1980:00:00:00
20.02.1981:00:00:00 
The SYSDATE pseudo-column shows the current system date and time. Adding 1 to SYSDATE will advance the date by 1 day. Use fractions to add hours, minutes or seconds to the date. Look at these examples:


SQL> select sysdate, sysdate+1/24, sysdate +1/1440,sysdate +1/86400 from dual;

SYSDATE                        SYSDATE+1/24              SYSDATE+1/1440              SYSDATE+1/86400
--------------------           --------------------            --------------------               --------------------
03-Jul-2002 08:32:12     03-Jul-2002 09:32:12      03-Jul-2002 08:33:12        03-Jul-2002 08:32:13

Wondering how 30 seconds can be added to a timestamp, here is a typical example.


SQL>select sysdate NOW, sysdate+30/(24*60*60) NOW_PLUS_30_SECS from dual;

NOW                             NOW_PLUS_30_SECS
--------------------           --------------------
03-JUL-2005 16:47:23     03-JUL-2005 16:47:53

Seems pretty simple right ? :) here is a couple more that I did;


DescriptionDate Expression
NowSYSDATE
Tomorow/ next daySYSDATE + 1
Seven days from nowSYSDATE + 7
One hour from nowSYSDATE + 1/24
Three hours from nowSYSDATE + 3/24
An half hour from nowSYSDATE + 1/48
10 minutes from nowSYSDATE + 10/1440
30 seconds from nowSYSDATE + 30/86400
Tomorrow at 12 midnightTRUNC(SYSDATE + 1)
Tomorrow at 8 AMTRUNC(SYSDATE + 1) + 8/24
Next Monday at 12:00 noonNEXT_DAY(TRUNC(SYSDATE), 'MONDAY') + 12/24
First day of the month at 12 midnightTRUNC(LAST_DAY(SYSDATE ) + 1)
The next Monday, Wednesday or Friday at 9 a.mTRUNC(LEAST(NEXT_DAY(sysdate,''MONDAY' ' ),NEXT_DAY(sysdate,''WEDNESDAY''), NEXT_DAY(sysdate,''FRIDAY'' ))) + (9/24)

Hope it was helpful, enjoy. - 

References: 
http://bkintsiful.blogspot.com/2012/04/how-does-one-add-dayhourminutesecond-to.html

Friday, October 24, 2014

Oracle Inventory Transactions and Cost processing

This blog provide basic understanding about Oracle Inventory Transactions and Cost
processing procedure.


SCOPE & APPLICATION
-------------------
Oracle manufacturing customers, support, and consulting.
  
Transactions - Unprocessed Transactions/Closing INV Accounting Period
(TRXN-STK)

This document will be used to explain the flow of transactions
from the MTL_TRANSACTIONS_INTERFACE to the GL_INTERFACE.
The aim of this document is to help and assist in resolution of
Interface related issues.


CONTENTS
--------
Q1.  What is the MTL_TRANSACTIONS_INTERFACE table used for?
Q2.  What is the MTL_MATERIAL_TRANSACTIONS_TEMP table used for?
Q3.  What type of issues will you see with the MTL__TRANSACTIONS_INTERFACE and
     MTL_MATERIAL_TRANSACTIONS_TEMP tables?
Q4.  What type of issues will you see with the MTL_MATERIAL_TRANSACTIONS table?
Q5.  What type of issues will you see with the MTL_TRANSACTION_ACCOUNTS table?
Q6.  Where do you find Pending/Errored Inventory Transactions?
Q7.  Where do you find Pending/Errored WIP Move and WIP Resource Transactions?
Q8.  What are the major tables involved in Material Movement for Inventory and
     WIP Material, Move, and Resource Transactions?
Q9.  How do you resolve Pending Material Transactions?
Q10. How do you resolve Pending WIP Cost Transactions?
Q11. When attempting to load legacy data into the MTL_TRANSACTIONS_INTERFACE
     table, into what column is the PO number input?
Q12. Why is the distribution account ID required in MTL_TRANSACTIONS_INTERFACE?


FAQ: Frequent Asked Questions
=============================
Q1. What is the MTL_TRANSACTIONS_INTERFACE table used for?

A1. This is the Interface between non-Inventory applications and the Inventory
Transactions module.

In other words any other module other than Inventory that wants to update
Inventory has to come through this table. Modules such as WIP (Work In Progress)
and OE (Order Entry) first pass their records to the
MTL_TRANSACTIONS_INTERFACE (MTI)for validation.

There is an Interface Manager called the Transactions Manager (INCTCM) which
reads records from this table, validates them and moves the successful
transactions onto MTL_MATERIAL_TRANSACTIONS_TEMP, and submits Transaction
workers (sub-processes - INCTCW) which then processes these records through
inventory. This process consists of data derivation, validation,
and transfer of records from MTL_TRANSCTIONS_INTERFACE,
MTL_TRANSACTIONS_LOTS_INTERFACE and MTL_SERIAL_NUMBERS_INTERFACE
into their respective TEMP (temporary) tables from where the transactions
processor processes them.

Both the Lots and Serial number tables above are used when items being
updated are under 'Lot' or 'Serial' number control. Example :- In the case
of an Sales Order, the item is being shipped to a client so the lot and serial
number if being used, this needs to be updated to show that it is no
longer available in Inventory stock.

It is important to note that in general the processors will not move the
transactions from this table if the following fields are not set as follows.

LOCK_FLAG = 2
PROCESS_FLAG = 1
transaction_mode = 3


Q2.  What is the MTL_MATERIAL_TRANSACTIONS_TEMP table used for?

A2.  Once the transactions have been passed to this table after initial
     validation by the Transactions Manager (INCTCM) from the
     MTL_TRANSACTIONS_INTERFACE a job id is attached and a Transactions
     Worker (INCTCW) is submitted by the INCTCM process in order tothe
     get the records processed and moved to the MTL_MATERIAL_TRANSACTONS
     table.

     This table is also used by Inventory Module and Purchasing module which
     writes directly onto this table for any transactions entered within
     itself and each transaction in turn through a process of strict
     validation.     

     Inventory Module Forms like Miscellaneous transactions writes directly
     into this table. The transactions which are done through these form. are
     on-line processing. It is from here that the inventory quantities finally
     get updated,serial/lot numbers get marked as being used.


Q3.  What type of issues will you see with the MTL__TRANSACTIONS_INTERFACE and
     MTL_MATERIAL_TRANSACTIONS_TEMP tables?

A3.  The issues can be related to stuck transactions in these tables.

The following is the list of errors that you may see in error_code,
error_explanation columns in the above tables:

NOTE: In Release 11 the APP-XXX errors do not show any more.

ERROR_CODE                                 ERROR EXPLANATION

APP-05367                                  Invalid Item
APP-05341                                  Invalid sub-inventory
APP-05343                                  Invalid transaction date
APP-05345                                  Invalid transaction UOM
APP-05354                                  Invalid locator segments
APP-05365                                  Invalid distribution account segments
APP-05372                                  Transaction processor error
APP-05526                                  Invalid locator
APP-05518                                  Negative balances not allowed
APP-05064                                  Quantity must be less than or
                                           equal to available to transact
                                           for that item at its specific
                                           control level
APP-05520                                  No open period found for date entered
Account period
Lot records
Serial records


APP-05367 Invalid Item
    Check the attributes against the set required for the transaction type.
    i.e. Order entry, PO etc.

APP-05341 Invalid Subinventory
    Check and make sure that this record does not already exist on the
    MTL_MATERIAL_TRANSACTIONS_TEMP table as sometimes the process does not
    clear some of the records out of  MTL_TRANSACTIONS_INTERFACE correctly.
    If this is the case it is a simple matter of deleting the records from
    the  MTL_TRANSACTIONS_INTERFACE.

    Check the subinventory against the available MTL_SECONDARY_INVENTORIES
    on the system for the  given ORGANIZATION_ID against this transaction.
    If the subinventory exists, check the TRANSACTION_TYPE_ID, for example:
    If it is a Purchase Order then you need to check the MTL_SUPPLY to
    ensure that the supply exists for this transaction.

APP-05343 Invalid transaction date
    In certain circumstances and depending on the transaction type
    that the future period is not open. There is no issue in changing
    the date to the current date and resubmitting it through the system.
         
APP-05345 Invalid transaction UOM
    Check the UOM measure being used and find out if valid for the
    organization source. If not set up the UOM. It may also be a case
    where the conversion classes have not been set-up.

APP-05354 Invalid locator segments
    APP-05355 The Locator segments are invalid for the given sub inventory,
    organization Combination.

    Check under Inventory Responsibility -> set-up ->  flexfeilds ->  key ->  
    segments  'stock locators',check each segment has been enabled.

APP-05365 Invalid distribution account segments
    The distribution account segments has its base in the Account Key Flexfield
    set-up. It is this Flexfield structure that determines how many segments
    should be populated into the segments are MTL_TRANSACTION_INTERFACE table.
    Basically in order to check if the distribution account correct we need to
    join the details back to the GL_CODE_COMBINATION table to validate the
    account code being used for the transaction.Inquiry on the error_explanation
    field as this may identify what segment is actually incorrect.This might
    return result APP-1756 Value 'XXXX' is not defined.

    Need to check that the segments point to a valid row in
    GL_CODE_COMBINATIONS.

APP-05372 Transaction processor error
    For this error you really need to get the ERROR_EXPLANATION to
    find out the exact message as to why it is possibly failing.
    These can usually have their three flags reset and re-submitted
    as this error is usually attached to those records in a group
    where one of the records has been erred with one of the more
    severe errors.

APP-05526 Invalid locator
    There is a list of checks that you need to make to ensure that
    the above error is correct.

           1.Extract Organization_id and cross check tables to see if the
             org is under locator control.
           2.Are the locator details filled incorrectly on the transaction
           3.Has the Organisation set-up been modified.

APP-05518 Negative balances not allowed.
    This message will be prompted if there is not enouhg on hand quantity
    to satisfy all the transactions within a batch. Therefore, ensure
    that the transaction quantity is enough to satisfy the sum of all
    the transaction quantities for a particular batch.
     
   APP-05064 Quantity must be less than or equal to Available to
             transact for that item at its specific control level.
      (For Example: subinventory,locator,lot,serial)
   1. If you specify a subinventory/locator while entering the order,
      it means we just wants to ship it out from that
      subinventory/locator and if there is not enough available to
      reserve/transact in that particular subinventory/locator the
      inventory program will error out with the above errors.  However, if
      there are no subinventories/locators specified while
      entering the order, we will pick up from where its available
      in that Organization.

   2. Check onhand and availabe quantity for the errored items.

   3. The records would have errored out due to some other row in the
      batch not having enough stock, so the entire batch would fail,  
      find the row that has error explanation populated. Resubmit all
      the other rows except the one which has error explanation , if
      the same error occurs for other rows, do the same process once
      again excluding that row.

   4. Please note that Available Quantity = On Hand Quantity - Reservations
      (Soft and Hard Reservations).
              
APP-05520 No open period found for date entered
           Period is not currently open for the transaction to be costed
           against later.
           1.Check that the period is open
           2.Check that the date is a date between the open and close period.


Q4.  What type of issues will you see with the MTL_MATERIAL_TRANSACTIONS table?
        
A4.  Transaction is valued (unit cost*quantity = $ amount)
     Once data gets here the transaction is almost complete except for
     the fact that it needs to have the costing details finally updated
     and written to the Transaction Accounts table for transfer to
     General Ledger. This is a transactional historical table. However,
     it is the holding point for transactions to be cost.

     The Cost Manager is a concurrent job that runs in the background.
     (CMCTCM)

     COSTED_FLAG = 'N'(Not Processed)  This means record is pending.
                   If it is NULL then the transaction has already been
                   processed.
                   If it is set to 'E' then it has erred for some
                   reason.
        

Q5. What type of issues will you see with the MTL_TRANSACTION_ACCOUNTS table?
        
A5. The details of the transactions are usually written into this table
    as Debits and Credits and from here ct can kick off Transfer to GL
    Navigation Path -> Inventory Responsibility -> Accounting Close Cycle
    -> General Ledger Transfers) as a concurrent request takes the
    transactions with a GL_BATCH_ID of -1 and passes them to the
    GL_INTERFACE for processing. When it passes the transactions to the
    GL_INTERFACE it is at this time that the batch is given it's proper
    batch number.

    Now there is a new functionality introduced. When transfer to GL is done,
    there is a column called GROUP_ID which gets populated in gl_interface
    table with gl_batch_id. GL BATCH identifier is used in the GROUP ID field,
    only the one batch which is in error would be prevented from being imported
    and posted. Also, adding a GROUP ID would allow for a more definitive
    level of control not only across locations but within a location.

    Patches which gives this functionality:
    REL 10.7: 853450
    REL 11.0: 1114961
   

Q6.   Where do you find Pending/Errored Inventory Transactions?

A6.1. Navigate to Inventory Responsibility -> Accounting Close Cycle ->
      Inventory Accounting Periods
      -- Select Pending Button related to an OPEN period.
      -- In the top region -- Resolution Required
      -- If it show pending records, These must be fixed prior to
         trying to close the period.
      -- form. only shows a count of pending records against the period.

A6.2. Navigate Inventory Responsibility -> Transactions -> Transaction
      Open Interface
      -- This form. queries the MTL_TRANSACTIONS_INTERFACE table
      -- Records can be resubmitted from this form.
         
A6.3. Navigate Inventory Responsibility -> Transactions ->
      Pending Transactions
      -- This form. queries the MTL_MATERIAL_TRANSACTIONS_TEMP table
      -- Records can only be resubmitted via the form.
      -- Records must be processed out of this form. in order to close
         inventory accounting periods.
      
A6.4. Navigate Inventory Responsibility -> Transactions ->
      Material Transactions
      -- Records can be viewed from this form. to know whether the
         transactions has costed flag as 'YES' or 'No', also other
         related columns under Alternate Region -> 'Reason/Reference'.
      -- We re-submit the records only through SQL.


Q7.  Where do you find Pending/Errored WIP Move and WIP Resource Transactions?

A8.1. Navigate Work in Process Responsibility -> Move Transactions ->
      Pending Move Transactions
      -- This form. queries the WIP_MOVE_TXN_INTERFACE table
      -- Records can be updated, deleted, and resubmitted via the form.

A8.2. Navigate Work in Process Responsibility -> Resource Transactions ->
      Pending Resource Transactions
      -- This form. queries the WIP_COST_TXN_INTERFACE table
      -- Records can be updated, deleted, and resubmitted via the form.


Q8.  What are the major tables involved in Material Movement for Inventory and
     WIP Material, Move, and Resource Transactions?

A8.  See below:

     MTL_TRANSACTIONS_INTERFACE
        -- INCTCM is the Transaction Manager for this Table.

     MTL_MATERIAL_TRANSACTIONS_TEMP
        -- INCTCM is the Transaction Manager for this Table

     MTL_MATERIAL_TRANSACTIONS
        -- CMCTCM is the Cost Manager for the records to be costed in this
            table.
        -- CMCCCM is the Cost Collection Manager for the records to be
           imported to Project Mfg.

     WIP_MOVE_TXN_INTERFACE
        -- Wip Move Transaction Worker processes records in this table
           (WICTCM)
     WIP_MOVE_TRANSACTIONS
        -- Must be viewed and resubmitted via SQL with the scripts below

     WIP_COST_TXN_INTERFACE
-- Resource Cost Worker processes records in this table.


Q9.  How do you resolve Pending Material Transactions?

A9.  Resolving Pending Material Transactions is a process of determining
     and fixing what is preventing a record from being processed through
     the MTL_TRANSACTIONS_INTERFACE table. Details of pending transactions
     can be viewed through the application by navigating to the Transaction
     Open Interface form.
        
     Using the Transaction Open Interface window, you can view, edit,
     correct and resubmit transactions received through the open interface.
     There are five selections in the alternate region list of values: Error,
     Location, Source, Intransit and Other. These provide detailed information
     to help you resolve pending transactions. In the Error alternate region:

       a. The error code describes the error on the last attempt to process
          the line item.
       b. The error explanation gives a reason for the error.
       c. The process flag indicates whether the row has been processed by
          the concurrent manager.
          The process flag status codes are:

               1 = Pending
               2 = Running
               3 = Error

     Resubmitting Transactions for Processing:

     In the Transaction Open Interface window, check the Resubmit [] box
     next to the transaction you want to resubmit or choose Resubmit All
     from the Special menu. If you have many transactions  to resubmit,
     use the Resubmit All button to select all transactions for processing
     and then selectively deselect individual transactions you do not want
     to resubmit. Save your work to submit the transactions for processing.


Q10. How do you resolve Pending WIP Cost Transactions?
      
A10. Resolving Pending WIP Cost transactions is a process of determining
     and fixing what is preventing a record from being processed through
     the WIP_COST_TXN_INTERFACE table Pending transactions can be viewed
     through the application by navigating to the WIP Responsibility ->
     pending resource transaction form.

     In the Pending Resource Transaction window you can view, update,
     delete, and resubmit resource transactions that have failed validation
     and remain in the WIP_COST_TXN_INTERFACE table. You can also resubmit
     transactions whose concurrent process has failed and have a processing
     phase of Complete and process status of Error. There are eight
     selections in the alternative region list of values: Processing,
     Source, Concurrent Request, Job or Schedule Name, Operation, Resource,
     Transaction and Comments.

     Error transactions will have the Transaction ID and Group ID populated
     and the Status will be error. Pending transactions will have the
     Transaction Id and Group ID fields blank and the Status will be
     pending.

     To view error details for failed resource transactions, select the
     erred transaction and click on the [Error] button. The Pending
     Resource Transaction error window appears. Column indicates the
     name of the column in the resource transaction interface table
     (WIP_COST_TXN_INTERFACE)that failed validation. Message indicates
     why the transaction failed.

     To resubmit failed resource transactions:

            In the Pending Resource Transactions widow either check the
            transaction's Resubmit check box to resubmit one record or
            choose select All for Resubmit from the Special Menu then
            save your work.


Q11. When attempting to load legacy data into the MTL_TRANSACTIONS_INTERFACE
     table, into what column is the PO number input?

A11. There is not a direct column for PO number.In the Oracle Manufacturing
     Implementation Manual, locate the section on Open Transactions
     Interfaces.  This section describes the transaction type id's and
     there is not a PO number. Refer to the column of transaction_reference
     and this column will allow the po number. The column is optional and
     shows up on reports and transaction displays. Since a column for the
     PO number does not directly exist,a transaction_reference field can
     be used to input this information.
     In Release 10.7, we do a Miscellaneous Receipt (PO Receipts are not
     supported).
     In Release 11, Purchasing Module has a Receiving Interface and
     we do not see any data coming to this table anymore.

     Customers that currently have release 10.7 and do not have this
     functionality will need to upgrade to release 11.0 or higher,
     which contains the production version of this functionality.


Q12. Why is the distribution account ID required in MTL_TRANSACTIONS_INTERFACE?

A12. All issues and receipts of asset items to an asset subinventory and
     sales order shipments require the distribution account id that
     originates from GL code combinations. This account id is required to
     create a complete audit trail of the transaction.

References:
http://kishorecboracleapps.blogspot.com/2013/03/oracle-inventory-transactions-and-cost.html