You are on page 1of 12

--- IR to INV Reservation Transfer process ---

A. Business Requirement

 Bug number for the task is - 13343630 - USAF SERIAL NUMBER RESERVATIONS FOR RECEIVED
INTERNAL ORDERS.
 Product: 508 - Oracle Inventory Management
 Desired Behavior –
CMRO user will identify an item in another organization where a specific instance is required
(associated IB attributes and maintenance requirements - CMRO tracks). Reservations at an
instance level is required (Internal Order) rather than just at an item level. Initiating Inventory
move from one organization to another organization will require reservations be specific to
instance level (serial number association) attributes. When the item arrives at the demand
location, we need the reservation to transfer from internal order to inventory. This process
also requires instance to be at the serial number level. Serial Number Reservation association
is required to be visible by Inventory, ASCP and CMRO users.
 Business Impact –
Without Inventory Serial Number Reservation enhancement, an item instance could be
transferred or issued to non-desired/low priority CMRO WO. Aircraft Inventory has a very high
monetary value and the availability is extremely important to Aircraft Operations and to our
CMRO customers. It is essential for the following users of EBS; Inventory, ASCP and CMRO to
be able to view associated CMRO WO serial number reservations. We anticipate that serial
number reservation enhancement will only pertain to CMRO work orders.

B. Technical Overview

 When an ISO (Internal Sales Order) is created from CMRO’s Material Management Workbench –
Demand and Supply UI, an IR (Internal Requisition) to WIP (Demand work order) type of
reservation is created in the demand organization.
 In supply organization the selected serials are reserved against the sales order line(s) of the ISO.
 ER (Existing Reservations) tab captures the IR to WIP reservation details, the serials picked for the
ISO and displays in the result table.
 When ISO is completed and the reserved serials are shipped to the demand organization i.e. the
required serials are received in the demand organization against the IR, the IR to WIP reservation
should get converted into Inventory to WIP reservation.
 Though Inventory currently supports this logic, serial numbers are not reserved as of today.
 The custom logic mentioned in this document needs to be added in inventory code to support
serial reservation.
 The fix has been put to INV_MAINTAIN_RESERVATION_PUB.TRANSFER_RES() procedure.
 Due to some constraints, INV could not check in the code. Hence user has to manually apply the
code changes into the environment.
 This customization is implemented only if the IR reservation is against a CMRO work order.
Following are the details.

 Package Modified - INV_MAINTAIN_RESERVATION_PUB (INVPMRVB.pls)


 Modified on version - 120.26.12010000.9 2009/08/05 09:08:40
 Existing code modified – No
 Existing code removed – No
 Code appended – Yes
 Code appended by – CMRO (Sandeep Satpathy)
 Code verified by – INV (Gagan Jyoti)
 Where ever code is added for CMRO, it is enclosed with following comments.
-- Code added by CMRO for IR to INV reservation transfer task – Begins
/*Added Code*/
-- Code added by CMRO for IR to INV reservation transfer task - Ends
 Only one procedure has been modified where code is appended.
PROCEDURE TRANSFER_RES (
p_from_reservation_id IN NUMBER DEFAULT NULL
,p_from_source_header_id IN NUMBER DEFAULT NULL
,p_from_source_line_id IN NUMBER DEFAULT NULL
,p_supply_source_type_id IN NUMBER DEFAULT NULL
,p_to_source_header_id IN NUMBER DEFAULT NULL
,p_to_source_line_id IN NUMBER DEFAULT NULL
,p_to_supply_source_type_id IN NUMBER DEFAULT NULL
,p_subinventory_code IN VARCHAR2 DEFAULT NULL
,p_locator_id IN NUMBER DEFAULT NULL
,p_lot_number IN VARCHAR2 DEFAULT NULL
,p_revision IN VARCHAR2 DEFAULT NULL
,p_lpn_id IN VARCHAR2 DEFAULT NULL --#Bug3020166
,p_primary_uom_code IN VARCHAR2 DEFAULT NULL
,p_primary_res_quantity IN NUMBER DEFAULT NULL
,p_secondary_uom_code IN VARCHAR2 DEFAULT NULL
,p_secondary_res_quantity IN NUMBER DEFAULT NULL
,x_msg_count OUT NOCOPY NUMBER
,x_msg_data OUT NOCOPY VARCHAR2
,x_return_status OUT NOCOPY VARCHAR2);

C. Pre-reqs
 INV patch - Apply the patch 13503144:R12.INV.B to the environment.
 Profile Setup needed - Set the profile INV: Create RCV Shipments in Bulk value to Yes.

D. Code Changes in API INV_MAINTAIN_RESERVATION_PUB.TRANSFER_RES()


procedure

 Add new local variables.


Declare following variables in the declaration section.

-- Code added by CMRO for IR to INV reservation transfer task - Begins


-- sansatpa added for IR to INV reservation transfer
L_SERIAL_NUMBER_TABLE INV_RESERVATION_GLOBAL.SERIAL_NUMBER_TBL_TYPE;
L_AHL_RESERVATION_ID NUMBER;
L_ORG_ID NUMBER;
L_SUP_ORG_ID NUMBER;
L_DEM_ORG_ID NUMBER;
l_inv_item_id number;
L_MARKING_SUCCESS NUMBER:= -1; /* Added for bug 13829182 */
L_SUCCESS NUMBER;
L_MARKED_RSRV_ID NUMBER;
l_sup_serial_control_flag varchar2(1);
l_dem_serial_control_flag varchar2(1);
L_INTRANSIT_TYPE NUMBER;
L_SHIP_LINE_ID NUMBER;
L_MMT_TXN_ID NUMBER;
-- Code added by CMRO for IR to INV reservation transfer task – Ends

 Add code.
Please find following existing code in the procedure TRANSFER_RES().
inv_reservation_pvt.transfer_reservation
(
p_api_version_number => 1.0
, p_init_msg_lst => fnd_api.g_false
, x_return_status => l_return_status
, x_msg_count => x_msg_count
, x_msg_data => x_msg_data
--, p_is_transfer_supply => fnd_api.g_true
, p_original_rsv_rec => l_rsv
, p_to_rsv_rec => l_rsv_new
, p_original_serial_number => g_dummy_sn_tbl -- no serial contorl
-- , p_to_serial_number => g_dummy_sn_tbl -- no serial control
, p_validation_flag => fnd_api.g_true
, x_reservation_id => l_new_rsv_id
);

Please add the following code right before the call to the above mentioned API call.

-- Code added by CMRO for IR to INV reservation transfer task - Begins


-- sansatpa - adding for Marshalling - to transfer IR reservation to INV - for serial marking -
begins
l_Fnd_Log_message := 'Checking if the transfer reservation is for AHL related reservation,
Reservation ID - ' || P_FROM_RESERVATION_ID;
IF G_debug= C_Debug_Enabled THEN
mydebug(l_Fnd_Log_Message, c_api_name,9);
END IF;

/* Added BEGIN block for bug 13829182 so that for reservation of all other flows should not
raise any exception and execute inv_reservation_pvt.transfer_reservation */
BEGIN
-- Check if the reservation id is IR type and belongs to AHL
SELECT RESERVATION_ID,
ORGANIZATION_ID,
INVENTORY_ITEM_ID
INTO L_AHL_RESERVATION_ID,
L_ORG_ID,
L_INV_ITEM_ID
FROM MTL_RESERVATIONS
WHERE SUPPLY_SOURCE_TYPE_ID =
INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_INTERNAL_REQ
AND DEMAND_SOURCE_TYPE_ID = INV_RESERVATION_GLOBAL.G_SOURCE_TYPE_WIP
AND EXTERNAL_SOURCE_CODE = 'AHL'
AND RESERVATION_ID = P_FROM_RESERVATION_ID;

-- Get the supply and demand org id


SELECT SOURCE_ORGANIZATION_ID,
DESTINATION_ORGANIZATION_ID
INTO L_SUP_ORG_ID,
L_DEM_ORG_ID
FROM PO_REQUISITION_LINES_ALL REQ_LINE /* Added for bug 13829182 */
WHERE REQ_LINE.REQUISITION_LINE_ID = P_FROM_SOURCE_LINE_ID;
EXCEPTION
WHEN OTHERS THEN
IF g_debug = C_Debug_Enabled THEN
L_AHL_RESERVATION_ID:= NULL;
L_ORG_ID := NULL;
L_INV_ITEM_ID := NULL;
L_SUP_ORG_ID := NULL;
L_DEM_ORG_ID := NULL;
l_Fnd_Log_Message := 'The reservation is not CMRO WO reservation ';
mydebug(l_Fnd_Log_Message,c_api_name,9);
END IF;
END;

-- The reservation is against IR and belongs to AHL


IF(L_AHL_RESERVATION_ID IS NOT NULL)
THEN
x_return_status := FND_API.G_RET_STS_SUCCESS;
l_Fnd_Log_message := 'Its AHL realted IR reservation. Check if the item is serial controlled
or not.';
IF G_debug= C_Debug_Enabled THEN
mydebug(l_Fnd_Log_Message, c_api_name,9);
END IF;

-- Check if the item is serial controlled or not for SUPPLY Org.


SELECT DECODE(SERIAL_NUMBER_CONTROL_CODE, 2,'Y', 5, 'Y', 'N') /* Added for bug
13829182 */
INTO L_SUP_SERIAL_CONTROL_FLAG
FROM MTL_SYSTEM_ITEMS_B
WHERE INVENTORY_ITEM_ID = L_INV_ITEM_ID
AND ORGANIZATION_ID = L_SUP_ORG_ID;

-- Check if the item is serial controlled or not for DEMAND Org.


SELECT DECODE(SERIAL_NUMBER_CONTROL_CODE, 2,'Y', 5, 'Y', 'N') /* Added for bug
13829182 */
INTO L_DEM_SERIAL_CONTROL_FLAG
FROM MTL_SYSTEM_ITEMS_B
WHERE INVENTORY_ITEM_ID = L_INV_ITEM_ID
AND ORGANIZATION_ID = L_DEM_ORG_ID;

-- Check if the item is serial controlled for both Demand and Supply Org.
IF(L_SUP_SERIAL_CONTROL_FLAG = 'Y' and L_DEM_SERIAL_CONTROL_FLAG = 'Y')
THEN

l_Fnd_Log_message := 'This is a serial controlled item. Get the Serial details and mark
those with the reservation id';
IF G_debug= C_Debug_Enabled THEN
MYDEBUG(L_FND_LOG_MESSAGE, C_API_NAME,9);
END IF;

-- Check if the shipping network is Direct or Intransit


SELECT intransit_type /* Added for bug 13829182 */
INTO l_intransit_type
FROM MTL_SHIPPING_NETWORK_VIEW
WHERE (from_organization_id , to_organization_id ) IN
(SELECT SOURCE_ORGANIZATION_ID,
DESTINATION_ORGANIZATION_ID
FROM po_requisition_lines_all
WHERE REQUISITION_LINE_ID = p_from_source_line_id
);

l_Fnd_Log_Message := 'USAF l_intransit_type value : '|| l_intransit_type;


mydebug(l_fnd_log_message, c_api_name,9);

-- Intransit type of shipping network


IF (L_INTRANSIT_TYPE = 2) THEN

l_fnd_log_message := 'Intransit type of shipping network.';


IF G_debug= C_Debug_Enabled THEN
mydebug(l_fnd_log_message, c_api_name,9);
END IF;

-- Get the serial details which are received at demand.


SELECT INVENTORY_ITEM_ID, /* Added for bug 13829182 */
SERIAL_NUMBER BULK COLLECT
INTO L_SERIAL_NUMBER_TABLE
FROM MTL_SERIAL_NUMBERS
WHERE LAST_TRANSACTION_ID IN
(SELECT TRANSACTION_ID
FROM MTL_MATERIAL_TRANSACTIONS
WHERE RCV_TRANSACTION_ID IN
(SELECT MAX(TRANSACTION_ID)
FROM RCV_TRANSACTIONS
WHERE REQUISITION_LINE_ID = P_FROM_SOURCE_LINE_ID
AND SOURCE_DOCUMENT_CODE = 'REQ'
AND DESTINATION_TYPE_CODE = 'INVENTORY'
AND PRIMARY_QUANTITY = P_PRIMARY_RES_QUANTITY
)
)
AND LAST_TXN_SOURCE_ID = P_FROM_SOURCE_HEADER_ID
AND LAST_RECEIPT_ISSUE_TYPE = 2
AND RESERVATION_ID IS NULL
AND NVL(GROUP_MARK_ID, -1) = -1;

-- Direct type of shipping network


ELSIF(L_INTRANSIT_TYPE = 1) THEN /* Added for bug 13829182 */

l_fnd_log_message := 'Direct type of shipping network.';


IF G_debug= C_Debug_Enabled THEN
mydebug(l_fnd_log_message, c_api_name,9);
end if;

SELECT MAX(SHIPMENT_LINE_ID),
MAX(NVL(MMT_TRANSACTION_ID,0))
INTO L_SHIP_LINE_ID,
L_MMT_TXN_ID
FROM RCV_SHIPMENT_LINES
WHERE REQUISITION_LINE_ID = P_FROM_SOURCE_LINE_ID
AND SOURCE_DOCUMENT_CODE = 'REQ'
AND DESTINATION_TYPE_CODE = 'INVENTORY'
AND QUANTITY_RECEIVED = P_PRIMARY_RES_QUANTITY;

l_Fnd_Log_Message := 'USAF l_mmt_txn_id, l_ship_line_id => ' ||l_mmt_txn_id||',


'||l_ship_line_id;
IF G_debug= C_Debug_Enabled THEN
mydebug(l_fnd_log_message, c_api_name,9);
end if;

SELECT RSL.ITEM_ID, /* Added for bug 13829182 */


RST.SERIAL_NUM BULK COLLECT
INTO L_SERIAL_NUMBER_TABLE
FROM RCV_SERIAL_TRANSACTIONS RST,
RCV_TRANSACTIONS RT,
RCV_SHIPMENT_LINES RSL
WHERE RT.SHIPMENT_LINE_ID = RSL.SHIPMENT_LINE_ID
AND RT.SHIPMENT_LINE_ID = L_SHIP_LINE_ID
AND RT.TRANSACTION_TYPE = 'DELIVER'
AND RST.SERIAL_TRANSACTION_TYPE = 'TRANSACTION'
AND RST.TRANSACTION_ID = RT.TRANSACTION_ID ;

END IF; --end to shipping network type check

l_Fnd_Log_Message := 'USAF - Total count of serials found to be stamped => ' ||


l_serial_number_table.count;
IF G_debug= C_Debug_Enabled THEN
mydebug(l_fnd_log_message, c_api_name,9);
END IF;

for j in 1 ..l_serial_number_table.count
LOOP
l_fnd_log_message := 'L_SERIAL_NUMBER_TABLE(' || j || ') - ' ||
L_SERIAL_NUMBER_TABLE(J).SERIAL_NUMBER;
IF G_debug= C_Debug_Enabled THEN
mydebug(l_fnd_log_message, c_api_name,9);
END IF;
END LOOP;

FOR J IN 1 ..L_SERIAL_NUMBER_TABLE.COUNT
LOOP
l_Fnd_Log_message := 'Marking Serial - ' ||
L_SERIAL_NUMBER_TABLE(J).SERIAL_NUMBER || ' for the reservation - ' ||
P_FROM_RESERVATION_ID;
IF G_debug= C_Debug_Enabled THEN
mydebug(l_Fnd_Log_Message, c_api_name,9);
END IF;

SERIAL_CHECK.INV_MARK_RSV_SERIAL /* Added for bug 13829182 */


(FROM_SERIAL_NUMBER => L_SERIAL_NUMBER_TABLE(J).SERIAL_NUMBER,
TO_SERIAL_NUMBER => L_SERIAL_NUMBER_TABLE(J).SERIAL_NUMBER,
ITEM_ID =>
L_SERIAL_NUMBER_TABLE(J).INVENTORY_ITEM_ID,
ORG_ID => L_ORG_ID,
HDR_ID => P_FROM_RESERVATION_ID,
TEMP_ID => NULL,
LOT_TEMP_ID => NULL,
P_RESERVATION_ID => P_FROM_RESERVATION_ID,
P_UPDATE_RESERVATION => FND_API.G_TRUE,
SUCCESS => L_SUCCESS
);

L_MARKING_SUCCESS := L_SUCCESS;

IF L_MARKING_SUCCESS < 0 THEN /* Added for bug 13829182 */


l_Fnd_Log_message := 'Could not mark Serial - ' ||
L_SERIAL_NUMBER_TABLE(J).SERIAL_NUMBER;
IF G_debug = C_Debug_Enabled THEN
MYDEBUG(L_FND_LOG_MESSAGE, C_API_NAME,9);
END IF;
l_Fnd_Log_message := 'AHL: IR to INV reservation transfer process cannot continue
as serial marking failed.';
IF G_debug = C_Debug_Enabled THEN
MYDEBUG(L_FND_LOG_MESSAGE, C_API_NAME,9);
END IF;
x_return_status := fnd_api.g_ret_sts_error;
END IF;
EXIT WHEN L_MARKING_SUCCESS < 0;

SELECT RESERVATION_ID /* Added for bug 13829182 */


INTO L_MARKED_RSRV_ID
FROM MTL_SERIAL_NUMBERS
WHERE SERIAL_NUMBER = L_SERIAL_NUMBER_TABLE(J).SERIAL_NUMBER
AND inventory_item_id = L_SERIAL_NUMBER_TABLE(J).inventory_item_id /* Added
for bug 13829182 */
AND current_organization_id = L_DEM_ORG_ID; /* Added for bug 13829182 */

l_Fnd_Log_message := 'Marked Serial - ' ||


L_SERIAL_NUMBER_TABLE(J).SERIAL_NUMBER || ' with reservation ID - ' ||
L_MARKED_RSRV_ID;
IF G_debug = C_Debug_Enabled THEN
MYDEBUG(L_FND_LOG_MESSAGE, C_API_NAME,9);
END IF;

END LOOP; -- end to FOR J IN 1 ..L_SERIAL_NUMBER_TABLE.COUNT

END IF; -- end to IF(L_SERIAL_CONTROL_FLAG = 'Y')

END IF; -- end to IF(L_AHL_RESERVATION_ID IS NOT NULL)

-- sansatpa - adding for Marshalling - to transfer IR reservation to INV - for serial marking -
ends
-- Code added by CMRO for IR to INV reservation transfer task – Ends

 Add code.
Please find following existing code in the same PROCEDURE TRANSFER_RES() procedure.
inv_reservation_pvt.transfer_reservation
(
p_api_version_number => 1.0
, p_init_msg_lst => fnd_api.g_false
, x_return_status => l_return_status
, x_msg_count => x_msg_count
, x_msg_data => x_msg_data
--, p_is_transfer_supply => fnd_api.g_true
, p_original_rsv_rec => l_rsv
, p_to_rsv_rec => l_rsv_new
, p_original_serial_number => g_dummy_sn_tbl -- no serial contorl
-- , p_to_serial_number => g_dummy_sn_tbl -- no serial control
, p_validation_flag => fnd_api.g_true
, x_reservation_id => l_new_rsv_id
);

Add the following code immediately after the above mentioned API call.

-- Code added by CMRO for IR to INV reservation transfer task - Begins


-- sansatpa added for marshalling Begins
-- Update mtl_serial_numbers table with group mark id and reservation id
IF(L_MARKING_SUCCESS > 0 and L_RETURN_STATUS = FND_API.G_RET_STS_SUCCESS AND
L_NEW_RSV_ID IS NOT NULL
AND x_return_status =FND_API.G_RET_STS_SUCCESS )
THEN

l_Fnd_Log_message := 'Calling transfer_reservation API was successful. Update Serial


Number table with group_mark_id and reservation_id - ' || l_new_rsv_id;
IF G_debug= C_Debug_Enabled THEN
mydebug(l_Fnd_Log_Message, c_api_name,9);
END IF;

UPDATE MTL_SERIAL_NUMBERS /* Added for bug 13829182 */


SET RESERVATION_ID = L_NEW_RSV_ID,
GROUP_MARK_ID = L_NEW_RSV_ID
WHERE RESERVATION_ID = P_FROM_RESERVATION_ID
AND INVENTORY_ITEM_ID = L_INV_ITEM_ID
AND CURRENT_ORGANIZATION_ID = L_DEM_ORG_ID;
END IF;
-- Update mtl_serial_numbers table with group mark id and reservation id ends.
-- sansatpa added for marshalling Ends
-- Code added by CMRO for IR to INV reservation transfer task - Begins

NB: Text in BROWN indicates the code added for the feature.

 Following are two text files attached.


 One is the last checked in version of the package INV_MAINTAIN_RESERVATION_PUB
(INVPMRVB.pls).
 The other one is with the package INV_MAINTAIN_RESERVATION_PUB (INVPMRVB.pls) after
all code changes done for the task.

E. Apply changes to the DB

 Make sure to take back up of original file (INVPMRVB.pls).


 Apply modified code as:
sqlplus apps/<apps_pwd>@<db_sid> @<filename>
 Compile invalids.

F. Testing Process

 Create an ISO and see the reserved serial details in ER tab.


 Ship confirm the ISO and receive the serials into the demand org.
 Retrieve the reservation details in ER tab again.
 The existing IR reservation is transferred to INV type.

You might also like