DECLARE
L_ITEM_REC INV_ITEM_GRP.ITEM_REC_TYPE;
X_ITEM_REC INV_ITEM_GRP.ITEM_REC_TYPE;
X_ERROR_TBL INV_ITEM_GRP.ERROR_TBL_TYPE;
L_TEMPLATE_ID NUMBER := 2083; --Purchased Item,table inv.mtl_item_templates --0101采购物料 mtl_item_templates_vl
X_RETURN_STATUS VARCHAR2(1);
L_USER_ID NUMBER :=11236; --User ID, Sysadmin here
L_MST_MFG_ORG_ID NUMBER := 107; --Master Inv Organization
L_CUR_MFG_ORG_ID NUMBER := 189; --Current Inv Organization
BEGIN
--Initialize first, or create_by will be -1
FND_GLOBAL.APPS_INITIALIZE(USER_ID => L_USER_ID
,RESP_ID => 50606
,RESP_APPL_ID =>401
);
--Item
L_ITEM_REC.ITEM_NUMBER := 'TEST_ITEM_0004';
L_ITEM_REC.DESCRIPTION := 'For API Test';
L_ITEM_REC.PRIMARY_UOM_CODE := 'KG';
--Master Inv Organization first, then Current Inv Organization
L_ITEM_REC.ORGANIZATION_ID := L_MST_MFG_ORG_ID;
--API
INV_ITEM_GRP.CREATE_ITEM(P_COMMIT => FND_API.G_FALSE
,P_ITEM_REC => L_ITEM_REC
,X_ITEM_REC => X_ITEM_REC
,X_RETURN_STATUS => X_RETURN_STATUS
,X_ERROR_TBL => X_ERROR_TBL
,P_TEMPLATE_ID => L_TEMPLATE_ID
);
--Result
IF X_RETURN_STATUS <> FND_API.G_RET_STS_SUCCESS THEN
ROLLBACK;
FOR I IN 1 .. X_ERROR_TBL.COUNT LOOP
dbms_output.PUT_LINE(
'Transaction ID :' || X_ERROR_TBL(I).TRANSACTION_ID
);
dbms_output.PUT_LINE('Unique ID :' || X_ERROR_TBL(I).UNIQUE_ID);
dbms_output.PUT_LINE('Message Name :' || X_ERROR_TBL(I).MESSAGE_NAME
);
dbms_output.PUT_LINE(
'Message Text: :' || X_ERROR_TBL(I).MESSAGE_TEXT
);
dbms_output.PUT_LINE('Table Name :' || X_ERROR_TBL(I).TABLE_NAME);
dbms_output.PUT_LINE('Column Name :' || X_ERROR_TBL(I).COLUMN_NAME);
dbms_output.PUT_LINE(
'Organization ID :' || X_ERROR_TBL(I).ORGANIZATION_ID
);
END LOOP;
IF (X_RETURN_STATUS = FND_API.G_RET_STS_UNEXP_ERROR) THEN
RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
ELSIF (X_RETURN_STATUS = FND_API.G_RET_STS_ERROR) THEN
RAISE FND_API.G_EXC_ERROR;
END IF;
ELSE
COMMIT;
dbms_output.PUT_LINE(X_ITEM_REC.INVENTORY_ITEM_ID);
END IF;
END;
效果如图: