Showing posts with label Oracle Inventory. Show all posts
Showing posts with label Oracle Inventory. Show all posts

Sunday, February 20, 2011

Items with Negative Quantity

This query can give list of items that have negative quantity in either cost layers table or onhand quantity table.
.


SELECT b.organization_id
, b.concatenated_segments
, b.description
, cst_qty
, onhand_qty
FROM (SELECT 'cst'
, organization_id
, inventory_item_id
, layer_quantity cst_qty
, 0 onhand_qty
FROM apps.cst_quantity_layers
WHERE layer_quantity < 0
UNION ALL
SELECT 'onhand'
, organization_id
, inventory_item_id
, 0
, b.transaction_quantity
FROM apps.mtl_onhand_quantities b
WHERE b.transaction_quantity < 0
) A
, apps.mtl_system_items_vl b
WHERE A.organization_id = b.organization_id
AND a.inventory_item_id = b.inventory_item_id;

Sunday, February 21, 2010

Picked line cancellation did not close Delivery and did not move inventory

At my work site, we wanted to allow sales order cancellation after it is picked. We changed some of custom processing constraints and users were able to cancel picked line but order line cancellation created two problems


  1. Delivery was still open

  2. Material did not move from staging inventory to original inventory



So we had to modify our custom order cancellation procedure and added following code.

This sql get delivery id that needs to be closed and sub inventory location where material should be moved back
    SELECT wdd.subinventory
, wdd.locator_id
, wdd.last_update_date
, wda.delivery_id
, wdd.requested_quantity cancelled_quantity
, ool.inventory_item_id
, ool.ship_from_org_id
, ool.order_quantity_uom
, ool.line_id
, mmt.subinventory_code to_subinventory
, mmt.locator_id to_locator_id
FROM wsh_delivery_details wdd
, wsh_delivery_assignments wda
, oe_order_lines_all ool
, mtl_material_transactions mmt
WHERE ool.header_id = p_header_id
AND ool.line_id = NVL(p_line_id, line_id)
AND wdd.source_line_id = ool.line_id
AND wdd.delivery_detail_id = wda.delivery_detail_id
AND mmt.transaction_id = wdd.transaction_id
AND wda.delivery_id IS NOT NULL

Stored query output into a pl/sql table l_delivery_tab and for each record selected by the above sql, we did the following

  1. Called WSH api to close delivery

    wsh_deliveries_pub.Delivery_Action
    ( p_api_version_number => 1.0
    , p_init_msg_list => FND_API.G_TRUE
    , x_return_status => l_return_status
    , x_msg_count => l_msg_count
    , x_msg_data => l_msg_data
    , p_action_code => 'CLOSE'
    , p_delivery_id => l_delivery_tab(i).delivery_id
    , x_trip_id => l_trip_id
    , x_trip_name => l_trip_name
    );


  2. For each record selected by the above query, inserted a record into material transaction interface table as given below
         INSERT INTO mtl_transactions_interface
    ( source_code
    , source_line_id
    , source_header_id
    , process_flag
    , transaction_mode
    , last_update_date
    , last_updated_by
    , creation_date
    , created_by
    , inventory_item_id
    , organization_id
    , transaction_quantity
    , transaction_uom
    , transaction_date
    , subinventory_code
    , locator_id
    , transaction_type_id
    , transfer_subinventory
    , transfer_organization
    , transfer_locator
    )
    VALUES ( 'CANCEL_ORDER' --SOURCE_CODE,
    , l_delivery_tab(i).line_id --SOURCE_LINE_ID,
    , l_header_id --SOURCE_HEADER_ID,
    , 1 --PROCESS_FLAG,
    , 3 --TRANSACTION_MODE,
    , SYSDATE --LAST_UPDATE_DATE,
    , -1 --LAST_UPDATED_BY,
    , SYSDATE --CREATION_DATE,
    , -1 --CREATED_BY,
    , l_delivery_tab(i).inventory_item_id --INVENTORY_ITEM_ID,
    , l_delivery_tab(i).ship_from_org_id --ORGANIZATION_ID,
    , l_delivery_tab(i).cancelled_quantity --TRANSACTION_QUANTITY,
    , l_delivery_tab(i).order_quantity_uom --TRANSACTION_UOM,
    , SYSDATE --TRANSACTION_DATE,
    , l_delivery_tab(i).subinventory --SUBINVENTORY_CODE,
    , l_delivery_tab(i).locator_id --LOCATOR_ID,
    , 2 --TRANSACTION_TYPE_ID,
    , l_delivery_tab(i).to_subinventory --TRANSFER_SUBINVENTORY,
    , l_delivery_tab(i).ship_from_org_id --TRANSFER_ORGANIZATION,
    , l_delivery_tab(i).to_locator_id --TRANSFER_LOCATOR
    );


Saturday, February 20, 2010

Adding Item Quantity

I had to test order import process and i needed to create multiple orders for multiple items. In our test system there was not enough item quantity available, so i used following script to add item qunatity as 'Miscellaneous receipt'. This script worked fine for me. All the records added to material transaction interface, will get picked by next execution of concurrent program 'Process transaction interface'. If this program is not scheduled to run then it can be executed using 'Inventory' Responsibility and select Setup -> Transaction Managers. Select 'Material transaction' and then hit Tools -> Launch Manager. It will start 'Process transaction interface'.


DECLARE
--
l_code_loc VARCHAR2(90);
l_org_id MTL_SYSTEM_ITEMS_B.organization_id % TYPE;
l_locator_id MTL_ITEM_LOCATIONS.inventory_location_id % TYPE;
l_trx_type_id MTL_TRANSACTION_TYPES.transaction_type_id % TYPE;
l_gl_acct MTL_SECONDARY_INVENTORIES.material_account % TYPE;
l_sub_inventory MTL_SECONDARY_INVENTORIES.secondary_inventory_name % TYPE;
l_sub_inv MTL_SECONDARY_INVENTORIES.secondary_inventory_name % TYPE;
--
-- This cursor get list of item for qunatity addition. This
-- query could be modified to select just a single item too
--
CURSOR c_items IS
SELECT inventory_item_id, segment1 , segment2 , segment3
FROM mtl_system_items_b a
, vvinv_styles b
WHERE a.segment1 LIKE &seq1
AND segment2 LIKE &seg2
AND segment3 LIKE &seg3
AND a.default_shipping_org = l_org_id
AND a.organization_id = l_org_id
AND a.customer_order_enabled_flag = 'Y'
AND a.segment1 = b.style_code
AND b.advanced_order_flag = 'N'
AND ROWNUM = 1
;

BEGIN
l_org_id := &org_id ;
l_sub_inv := &sub_inv;
--
--
l_code_loc := 'Get transaction type id';
SELECT transaction_type_id
INTO l_trx_type_id
FROM mtl_transaction_types
WHERE transaction_type_name = 'Miscellaneous receipt'
;
--
-- Get inventory name and account
--
l_code_loc := 'Get inventory name';
SELECT secondary_inventory_name, material_account
INTO l_sub_inventory
, l_gl_acct
FROM MTL_SECONDARY_INVENTORIES
WHERE secondary_inventory_name = l_sub_inv
;
--
-- Get Item location
--
l_code_loc := 'Get item location';
SELECT inventory_location_id
INTO l_locator_id
FROM mtl_item_locations
WHERE subinventory_code = l_sub_inventory
AND disable_date IS NULL
AND enabled_flag = 'Y'
AND ROWNUM = 1
;
--
-- Loop through item cursor and add record for each item
--
l_code_loc := 'For Loop';
FOR l_rec IN c_items LOOP
INSERT INTO mtl_transactions_interface
( source_code
, source_line_id
, source_header_id
, process_flag
, transaction_mode
, last_update_date
, last_updated_by
, creation_date
, created_by
, inventory_item_id
, organization_id
, transaction_quantity
, transaction_uom
, transaction_date
, subinventory_code
, locator_id
, transaction_type_id
, distribution_account_id
)
VALUES ( 'Manual' --SOURCE_CODE,
, 11 --SOURCE_LINE_ID,
, 11 --SOURCE_HEADER_ID,
, 1 --PROCESS_FLAG,
, 3 --TRANSACTION_MODE,
, SYSDATE --LAST_UPDATE_DATE,
, -1 --LAST_UPDATED_BY,
, SYSDATE --CREATION_DATE,
, -1 --CREATED_BY,
, l_rec.inventory_item_id --INVENTORY_ITEM_ID,
, l_org_id --ORGANIZATION_ID,
, 25 --TRANSACTION_QUANTITY,
, 'EA' --TRANSACTION_UOM,
, SYSDATE --TRANSACTION_DATE,
, l_sub_inventory --SUBINVENTORY_CODE,
, l_locator_id --LOCATOR_ID,
, l_trx_type_id --TRANSACTION_TYPE_ID
, l_gl_acct
) ;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error Encountered at ' || l_code_loc);
dbms_output.put_line('Error :'||SQLERRM);
END;

Tuesday, December 15, 2009

mtl_transactions_interface

***
*** Sample code to add item quantity is available here. It inserts records into mtl_transaction_interface table that add item quantity
***















Transaction_mode,lock_flag and Process_flaf Records with these columns values of 3,2 and 1 respectively are picked by transaction manager for processing. If process_flag is 3, then that record could not be processed due to some error. ERROR_CODE and
ERROR_EXPLANATION will be populated with the cause for the error.
.
transaction_type_idThis is foreign key to MTL_TRANSACTION_TYPES. TRANSACTION_TYPE_ID
Source_codeany text for your own reference