A Lot Number is a code that groups items that share the same specifications, and we generate the lot number to identify the expiration date of all items. Within Oracle ERP specifically, the Inventory module has complete lot number support for inventory transactions. Each lot is related to an inventory item that is a lot-controlled item whenever we create a new inventory receipt.
What is the API to create a new Lot Number in Oracle APPS R12? To create a new lot number, we use an API called “INV_LOT_API_PUB.CREATE_INV_LOT” to perform this action from the backend.
Goal:
Generate Lot Number using “INV_LOT_API_PUB.CREATE_INV_LOT” API
Forms Or Pages:
Example:
API IN/OUT Parameters :
Parameter Name | Type | Data Type |
---|---|---|
p_api_version | IN | NUMBER |
P_SOURCE | IN | NUMBER |
P_INIT_MSG_LIST | IN | VARCHAR2 |
P_COMMIT | IN | VARCHAR2 |
P_VALIDATION_LEVEL | IN | VARCHAR2 |
P_ORIGIN_TXN_ID | IN | NUMBER |
X_RETURN_STATUS | OUT | VARCHAR2 |
X_MSG_COUNT | OUT | NUMBER |
X_MSG_DATA | OUT | VARCHAR2 |
X_LOT_REC | OUT | MTL_LOT_NUMBERS%ROWTYPE |
X_ROW_ID | OUT | ROWID |
API Calling example:
DECLARE
-- Intialize Parameters
L_USER_ID NUMBER := 1318; -- USER_ID : OPERATIONS
L_RESP_ID NUMBER := 50583; -- Responsibility : Inventory, Vision Operations (USA)
L_RESP_APPL_ID NUMBER := 401; -- RESP_APPL_ID
-- API Standard Parameters
L_API_VERSION NUMBER := 1.0;
L_INIT_MSG_LIST VARCHAR2 (100) := FND_API.G_FALSE;
L_COMMIT VARCHAR2 (100) := FND_API.G_FALSE;
L_RETURN_STATUS VARCHAR2 (100);
L_MSG_COUNT NUMBER;
L_MSG_DATA VARCHAR2 (3000);
-- Message API Parameters
L_MSG_INDEX NUMBER;
L_MSG_INDEX_OUT NUMBER;
-- Lot Parameters
L_VALIDATION_LEVEL NUMBER := FND_API.G_VALID_LEVEL_FULL;
L_ORIGIN_TXN_ID NUMBER := NULL;
L_SOURCE NUMBER := NULL;
L_ROW_ID ROWID;
L_IN_LOT_REC MTL_LOT_NUMBERS%ROWTYPE;
X_LOT_REC MTL_LOT_NUMBERS%ROWTYPE;
BEGIN
-- Set EBS Grobal Informations
FND_GLOBAL.APPS_INITIALIZE (USER_ID => 1318, RESP_ID => 50559, RESP_APPL_ID => 222);
-- Initialize Message List
FND_MSG_PUB.INITIALIZE;
-- Set Parameters
L_IN_LOT_REC.INVENTORY_ITEM_ID := 4113; -- Item : AS80000 item lot control
L_IN_LOT_REC.ORGANIZATION_ID := 204; -- Org : M1
L_IN_LOT_REC.LOT_NUMBER := '102459';
L_IN_LOT_REC.PARENT_LOT_NUMBER := NULL;
L_IN_LOT_REC.EXPIRATION_DATE := TO_DATE ('31-MAR-2021', 'DD-MON-YYYY');
L_IN_LOT_REC.DISABLE_FLAG := NULL;
L_IN_LOT_REC.ORIGINATION_DATE := SYSDATE;
L_IN_LOT_REC.CREATION_DATE := SYSDATE;
L_IN_LOT_REC.LAST_UPDATE_DATE := SYSDATE;
L_IN_LOT_REC.CREATED_BY := FND_GLOBAL.USER_ID;
L_IN_LOT_REC.LAST_UPDATED_BY := FND_GLOBAL.USER_ID;
L_IN_LOT_REC.LAST_UPDATE_LOGIN := FND_GLOBAL.LOGIN_ID;
DBMS_OUTPUT.PUT_LINE ('********************************');
-- Call API
DBMS_OUTPUT.PUT_LINE ('Start CREATE_INV_LOT API');
INV_LOT_API_PUB.CREATE_INV_LOT (X_RETURN_STATUS => L_RETURN_STATUS
,X_MSG_COUNT => L_MSG_COUNT
,X_MSG_DATA => L_MSG_DATA
,X_ROW_ID => L_ROW_ID
,X_LOT_REC => X_LOT_REC
,P_LOT_REC => L_IN_LOT_REC
,P_SOURCE => L_SOURCE
,P_API_VERSION => L_API_VERSION
,P_INIT_MSG_LIST => L_INIT_MSG_LIST
,P_COMMIT => L_COMMIT
,P_VALIDATION_LEVEL => L_VALIDATION_LEVEL
,P_ORIGIN_TXN_ID => L_ORIGIN_TXN_ID);
DBMS_OUTPUT.PUT_LINE ('Create_Inv_lot return ' || L_RETURN_STATUS);
-- Error Handling
IF L_RETURN_STATUS = FND_API.G_RET_STS_SUCCESS THEN
IF L_MSG_COUNT = 0
OR L_MSG_COUNT IS NULL THEN
DBMS_OUTPUT.PUT_LINE ('Lot Number has been generated Successfully!!');
COMMIT;
DBMS_OUTPUT.PUT_LINE (' organization_id : ' || X_LOT_REC.ORGANIZATION_ID);
DBMS_OUTPUT.PUT_LINE (' inventory_item_id : ' || X_LOT_REC.INVENTORY_ITEM_ID);
DBMS_OUTPUT.PUT_LINE (' lot_number : ' || X_LOT_REC.LOT_NUMBER);
DBMS_OUTPUT.PUT_LINE (' created_by : ' || X_LOT_REC.CREATED_BY);
DBMS_OUTPUT.PUT_LINE (' creation_date : ' || X_LOT_REC.CREATION_DATE);
ELSE
DBMS_OUTPUT.PUT_LINE ('WARNING!!');
ROLLBACK;
END IF;
ELSIF L_RETURN_STATUS = FND_API.G_RET_STS_ERROR THEN
DBMS_OUTPUT.PUT_LINE ('ERROR!!');
ROLLBACK;
ELSIF L_RETURN_STATUS = FND_API.G_RET_STS_UNEXP_ERROR THEN
DBMS_OUTPUT.PUT_LINE ('UNEXPECTED ERROR!!');
ROLLBACK;
END IF;
-- Message Handling
IF L_MSG_COUNT = 1 THEN
DBMS_OUTPUT.PUT_LINE ('Error Message : ' || L_MSG_DATA);
ELSIF L_MSG_COUNT > 1 THEN
FOR L_MSG_INDEX IN 1 .. L_MSG_COUNT
LOOP
FND_MSG_PUB.GET (P_MSG_INDEX => L_MSG_INDEX
,P_ENCODED => FND_API.G_FALSE
,P_DATA => L_MSG_DATA
,P_MSG_INDEX_OUT => L_MSG_INDEX_OUT);
DBMS_OUTPUT.PUT_LINE ('Error Message' || L_MSG_INDEX || ' : ' || L_MSG_DATA);
END LOOP;
END IF;
DBMS_OUTPUT.PUT_LINE ('********************************');
EXCEPTION
WHEN OTHERS THEN
L_MSG_DATA := SUBSTR (SQLERRM, 0, 1000);
DBMS_OUTPUT.PUT_LINE ('***************************');
DBMS_OUTPUT.PUT_LINE ('There is an exception has been raised from API with error message: ' || L_MSG_DATA);
DBMS_OUTPUT.PUT_LINE ('***************************');
END;
Special Notes:
- The item must be a lot-controlled item; otherwise, an error would be returned from the API to indicate that the given item is not a lot-controlled item. You can check whether the item is lot controlled or not from the master item screen –> query about item -> navigate to inventory tab.
Final Result:
In this article, we have demonstrated how to generate a new lot number using API in Oracle APPS R12 .
Please Don’t use this code snippet directly in a production environment. Instead, test it on the test environment first to avoid any data corruption that might happen.
We are delighted to hear from you in the comment section below. If you face any issues, we can asset you.
Hopefully, it was clear and concise.
[convertkit form=1415728]