select
null action_,
null status_,
null message_,
null modified_columns_,
:p_upload_type upload_type,
to_number(null) source_line_id,
to_number(null) source_header_id,
:p_trx_type transaction_type,
:p_trx_source source,
x.*
from
(
select
mp.organization_code organization,
msiv.concatenated_segments item,
ccg.cost_group cost_group,
:p_trx_date transaction_date,
msiv.description description,
cql.item_cost item_average_cost,
--
clcdv.level_type_dsp cost_element_level,
clcdv.cost_element,
--
to_number(null) new_average_cost,
to_number(null) percentage_change,
to_number(null) value_change,
--
cql.layer_quantity valued_quantity,
decode(:p_upload_type,'D',clcdv.item_cost,cql.item_cost) old_average_cost,
round(cql.layer_quantity * decode(:p_upload_type,'D',clcdv.item_cost,cql.item_cost),2) old_valuation,
--
to_number(null) adjusted_average_cost,
to_number(null) adjusted_valuation,
to_number(null) valuation_change,
--
null material_adj_account,
null material_overhead_adj_account,
null resource_adj_account,
null outside_processing_adj_account,
null overhead_adj_account,
:p_default_adj_account default_adj_account,
--
null reason,
null reference,
--
clcdv.cost_element_id,
clcdv.level_type,
0 upload_row
from
mtl_parameters mp,
mtl_system_items_vl msiv,
cst_quantity_layers cql,
cst_layer_cost_details_v clcdv,
cst_cost_groups ccg
where
mp.organization_id = msiv.organization_id and
mp.organization_id in (select oav.organization_id from org_access_view oav where oav.resp_application_id=fnd_global.resp_appl_id and oav.responsibility_id=fnd_global.resp_id) and
mp.primary_cost_method = 2 and
msiv.organization_id = cql.organization_id and
msiv.inventory_item_id = cql.inventory_item_id and
msiv.inventory_item_flag = 'Y' and
msiv.inventory_asset_flag = 'Y' and
msiv.costing_enabled_flag = 'Y' and
decode(:p_upload_type,'D',cql.layer_id,null) = clcdv.layer_id(+) and
(:p_upload_type = 'S' or clcdv.cost_element_id is not null) and
cql.cost_group_id = ccg.cost_group_id and
(
(ccg.cost_group_id = mp.default_cost_group_id) or
( nvl(ccg.cost_group_type,1) in (1,3) and
exists
(select
'EXISTS'
from
cst_cost_group_accounts ccga
where
ccga.cost_group_id = ccg.cost_group_id and
ccga.organization_id = mp.organization_id
)
)
) and
1=1
union
-- for new items with no costing layers take from the cst_item_costs/cst_item_cost_details
select
mp.organization_code organization,
msiv.concatenated_segments item,
ccg.cost_group cost_group,
:p_trx_date transaction_date,
msiv.description description,
cic.item_cost item_average_cost,
--
cicdv.level_type_dsp cost_element_level,
cicdv.cost_element,
--
to_number(null) new_average_cost,
to_number(null) percentage_change,
to_number(null) value_change,
--
0 valued_quantity,
decode(:p_upload_type,'D',cicdv.item_cost,cic.item_cost) old_average_cost,
0 old_valuation,
--
to_number(null) adjusted_average_cost,
to_number(null) adjusted_valuation,
to_number(null) valuation_change,
--
null material_adj_account,
null material_overhead_adj_account,
null resource_adj_account,
null outside_processing_adj_account,
null overhead_adj_account,
null default_adj_account,
--
null reason,
null reference,
--
cicdv.cost_element_id,
cicdv.level_type,
0 upload_row
from
mtl_parameters mp,
mtl_system_items_vl msiv,
cst_item_costs cic,
cst_item_cost_details_v cicdv,
cst_cost_groups ccg
where
mp.organization_id = msiv.organization_id and
mp.organization_id in (select oav.organization_id from org_access_view oav where oav.resp_application_id=fnd_global.resp_appl_id and oav.responsibility_id=fnd_global.resp_id) and
mp.primary_cost_method = 2 and
msiv.organization_id = cic.organization_id and
msiv.inventory_item_id = cic.inventory_item_id and
msiv.inventory_item_flag = 'Y' and
msiv.inventory_asset_flag = 'Y' and
msiv.costing_enabled_flag = 'Y' and
not exists (select null from cst_quantity_layers cql where cql.organization_id = msiv.organization_id and cql.inventory_item_id = msiv.inventory_item_id) and
mp.primary_cost_method = cic.cost_type_id and
decode(:p_upload_type,'D',cic.organization_id,null) = cicdv.organization_id(+) and
decode(:p_upload_type,'D',cic.inventory_item_id,null) = cicdv.inventory_item_id(+) and
decode(:p_upload_type,'D',cic.cost_type_id,null) = cicdv.cost_type_id(+) and
(:p_upload_type = 'S' or cicdv.cost_element_id is not null) and
mp.default_cost_group_id = ccg.cost_group_id and
1=1
) x |