The following lines contain the word 'select', 'insert', 'update' or 'delete':
** Function: validate_cg_update
** Description: Checks if cost group can be updated
** Output:
** x_return_status
** return status indicating success, error, unexpected error
** x_msg_count
** number of messages in message list
** x_msg_data
** if the number of messages in message list is 1, contains
** message text
** Input:
** p_cost_group_id
** cost group for which the check has to be made
**
** Returns:
** TRUE if cost group can be updated, else FALSE
**
** Please use return value to determine if cost group can be updated or not.
** Do not use x_return_status for this purpose as
** . x_return_status could be success and yet cost group not be updated
** . x_return_status is set to error when an error(such as SQL error)
** occurs.
** --------------------------------------------------------------------------
*/
g_pkg_name CONSTANT VARCHAR2(30) := 'INV_SUB_CG_UTIL';
function validate_cg_update (
x_return_status OUT NOCOPY VARCHAR2
, x_msg_count OUT NOCOPY NUMBER
, x_msg_data OUT NOCOPY VARCHAR2
, p_cost_group_id IN NUMBER) return boolean
IS
/*
-- cursor moq_cursor (v_cost_group_id number)
-- is
-- select count(*)
-- from MTL_ONHAND_QUANTITIES_DETAIL moq
-- where moq.cost_group_id = v_cost_group_id;
select count(*)
from mtl_material_transactions_temp mmtt
where mmtt.cost_group_id = v_cost_group_id;
, 'validate_cg_update'
);
end validate_cg_update;
** Function: validate_cg_delete
** Description: Checks if cost group can be delete
** Output:
** x_return_status
** return status indicating success, error, unexpected error
** x_msg_count
** number of messages in message list
** x_msg_data
** if the number of messages in message list is 1, contains
** message text
** Input:
** p_cost_group_id
** cost group for which the check has to be made
**
** Returns:
** TRUE if cost group can be deleted, else FALSE
**
** Please use return value to determine if cost group can be deleted or not.
** Do not use x_return_status for this purpose as
** . x_return_status could be success and yet cost group not be deleted
** . x_return_status is set to error when an error(such as SQL error)
** occurs.
** --------------------------------------------------------------------------
*/
function validate_cg_delete (
x_return_status OUT NOCOPY VARCHAR2
, x_msg_count OUT NOCOPY NUMBER
, x_msg_data OUT NOCOPY VARCHAR2
, p_cost_group_id IN NUMBER
, p_organization_id IN NUMBER) return boolean
is
l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
l_cannot_delete VARCHAR2(1) := 'N';
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM mtl_parameters mp
WHERE mp.default_cost_group_id = p_cost_group_id);
l_cannot_delete := 'N';
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM mtl_secondary_inventories msi
WHERE msi.default_cost_group_id = p_cost_group_id);
l_cannot_delete := 'N';
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM mtl_material_transactions_temp mmtt
WHERE
(mmtt.cost_group_id = p_cost_group_id
OR mmtt.transfer_cost_group_id = p_cost_group_id));
l_cannot_delete := 'N';
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM MTL_ONHAND_QUANTITIES_DETAIL moq
WHERE moq.cost_group_id = p_cost_group_id);
l_cannot_delete := 'N';
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM mtl_material_transactions mmt
WHERE
(mmt.cost_group_id = p_cost_group_id
OR mmt.transfer_cost_group_id = p_cost_group_id));
l_cannot_delete := 'N';
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM mtl_parameters mp
WHERE mp.default_cost_group_id = p_cost_group_id
AND mp.organization_id = p_organization_id);
l_cannot_delete := 'N';
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(select organization_id
from mtl_secondary_inventories msi
where msi.default_cost_group_id = p_cost_group_id
AND msi.organization_id = p_organization_id);
l_cannot_delete := 'N';
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM mtl_material_transactions_temp mmtt
WHERE
mmtt.organization_id = p_organization_id AND
(mmtt.cost_group_id = p_cost_group_id
OR mmtt.transfer_cost_group_id = p_cost_group_id));
l_cannot_delete := 'N';
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM MTL_ONHAND_QUANTITIES_DETAIL moq
WHERE moq.cost_group_id = p_cost_group_id
AND moq.organization_id = p_organization_id);
l_cannot_delete := 'N'; END;
IF l_cannot_delete = 'N' THEN
BEGIN
SELECT 'Y' INTO l_cannot_delete FROM dual
WHERE
exists
(SELECT organization_id
FROM mtl_material_transactions mmt
WHERE mmt.organization_id = p_organization_id AND
(mmt.cost_group_id = p_cost_group_id
OR mmt.transfer_cost_group_id = p_cost_group_id));
l_cannot_delete := 'N';
IF l_cannot_delete = 'Y' THEN
RETURN FALSE;
, 'validate_cg_update'
);
end validate_cg_delete;
** Procedure: update_sub_accounts
** Description: Updates a given subinventory with a given cost group's accounts
** Output:
** x_return_status
** return status indicating success, error, unexpected error
** x_msg_count
** number of messages in message list
** x_msg_data
** if the number of messages in message list is 1, contains
** message text
** Input:
** p_cost_group_id
** cost group whose accounts have to be used to update subinventory
** p_organization_id
** organization to which the to be subinventory belongs
** p_subinventory
** subinventory whose accounts have to be synchronized with those
** of cost group
**
** Returns:
** none
** --------------------------------------------------------------------------
*/
procedure update_sub_accounts (
x_return_status OUT NOCOPY VARCHAR2
, x_msg_count OUT NOCOPY NUMBER
, x_msg_data OUT NOCOPY VARCHAR2
, p_cost_group_id IN NUMBER
, p_organization_id IN NUMBER
, p_subinventory IN VARCHAR2)
is
l_material_account number;
update mtl_secondary_inventories
set
material_account = l_material_account
, material_overhead_account = l_material_overhead_account
, resource_account = l_resource_account
, overhead_account = l_overhead_account
, outside_processing_account = l_outside_processing_account
, expense_account = l_expense_account
, encumbrance_account = l_encumbrance_account
where organization_id = p_organization_id
and secondary_inventory_name = p_subinventory;
, 'update_sub_accounts'
);
end update_sub_accounts;
** Procedure: update_org_accounts
** Description: Updates a given organization with a given cost group's accounts
** Output:
** x_return_status
** return status indicating success, error, unexpected error
** x_msg_count
** number of messages in message list
** x_msg_data
** if the number of messages in message list is 1, contains
** message text
** Input:
** p_cost_group_id
** cost group whose accounts have to be used to update organization
** p_organization_id
** organization whose accounts have to be synchronized with those
** of cost group
**
** Returns:
** none
** --------------------------------------------------------------------------
*/
procedure update_org_accounts (
x_return_status OUT NOCOPY VARCHAR2
, x_msg_count OUT NOCOPY NUMBER
, x_msg_data OUT NOCOPY VARCHAR2
, p_cost_group_id IN NUMBER
, p_organization_id IN NUMBER)
is
l_material_account number;
update mtl_parameters
set
material_account = l_material_account
, material_overhead_account = l_material_overhead_account
, resource_account = l_resource_account
, overhead_account = l_overhead_account
, outside_processing_account = l_outside_processing_account
, expense_account = l_expense_account
, encumbrance_account = l_encumbrance_account
where organization_id = p_organization_id;
, 'update_org_accounts'
);
end update_org_accounts;
select organization_id, secondary_inventory_name
from mtl_secondary_inventories
where default_cost_group_id = p_cost_group_id;
select organization_id
from mtl_parameters
where default_cost_group_id = p_cost_group_id;
select nvl(default_cost_group_id,0)
into l_cost_group_id
from mtl_parameters
where organization_id = p_organization_id;
select nvl(default_cost_group_id,0)
into l_cost_group_id
from mtl_secondary_inventories
where organization_id = p_organization_id
and secondary_inventory_name = p_subinventory;
** Procedure: find_update_subs_accounts
** Description: For a given cost group, all subinventories that have it as a
** default cost group are found and their accounts are
** synchronized with those of the cost group
** Output:
** x_return_status
** return status indicating success, error, unexpected error
** x_msg_count
** number of messages in message list
** x_msg_data
** if the number of messages in message list is 1, contains
** message text
** Input:
** p_cost_group_id
** cost group whose accounts will be used to synchronize with
** accounts of subinventories that have this cost group as
** the default cost group
** Returns:
** none
** --------------------------------------------------------------------------
*/
procedure find_update_subs_accounts(
x_return_status OUT NOCOPY VARCHAR2
, x_msg_count OUT NOCOPY NUMBER
, x_msg_data OUT NOCOPY VARCHAR2
, p_cost_group_id IN NUMBER)
is
l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
inv_sub_cg_util.update_sub_accounts (
x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
, p_cost_group_id => p_cost_group_id
, p_organization_id => l_sub_tbl(i).organization_id
, p_subinventory => l_sub_tbl(i).subinventory);
, 'find_update_subs_accounts'
);
end find_update_subs_accounts;
** Procedure: find_update_orgs_accounts
** Description: For a given cost group, all organziations that have it as a
** default cost group are found and their accounts are
** synchronized with those of the cost group
** Output:
** x_return_status
** return status indicating success, error, unexpected error
** x_msg_count
** number of messages in message list
** x_msg_data
** if the number of messages in message list is 1, contains
** message text
** Input:
** p_cost_group_id
** cost group whose accounts will be used to synchronize with
** accounts of organziations that have this cost group as
** the default cost group
** Returns:
** none
** --------------------------------------------------------------------------
*/
procedure find_update_orgs_accounts(
x_return_status OUT NOCOPY VARCHAR2
, x_msg_count OUT NOCOPY NUMBER
, x_msg_data OUT NOCOPY VARCHAR2
, p_cost_group_id IN NUMBER)
is
l_return_status varchar2(1) := fnd_api.g_ret_sts_success;
inv_sub_cg_util.update_org_accounts (
x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
, p_cost_group_id => p_cost_group_id
, p_organization_id => l_org_tbl(i).organization_id);
, 'find_update_orgs_accounts'
);
end find_update_orgs_accounts;