120:
121: l_exists_sc_orgs := 0;
122: l_exists_ac_orgs := 0;
123:
124: -- Find out if there are any standard costing orgs
125: select nvl(max(1),0)
126: into l_exists_sc_orgs
127: from sys.dual
128: where exists (
125: select nvl(max(1),0)
126: into l_exists_sc_orgs
127: from sys.dual
128: where exists (
129: select 'There are standard costing orgs'
130: from mtl_parameters
131: where primary_cost_method = 1
132: );
133:
144: select FND_GLOBAL.USER_ID
145: into l_application_user_id
146: from sys.dual;
147:
148: -- Get the cost history for standard costing orgs from cst_elemental_costs
149: if (l_exists_sc_orgs = 1) then
150: eni_dbi_util_pkg.log('There are Standard Costing orgs, hence starting initial cost collection into stage table for them');
151:
152: insert /*+ append parallel(a) */ into eni_dbi_item_cost_stg a
146: from sys.dual;
147:
148: -- Get the cost history for standard costing orgs from cst_elemental_costs
149: if (l_exists_sc_orgs = 1) then
150: eni_dbi_util_pkg.log('There are Standard Costing orgs, hence starting initial cost collection into stage table for them');
151:
152: insert /*+ append parallel(a) */ into eni_dbi_item_cost_stg a
153: (effective_date,
154: inventory_item_id,
168: conversion_rate)
169: select effective_date,
170: inventory_item_id,
171: organization_id,
172: sum(standard_cost) item_cost,
173: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
174: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
175: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
176: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
169: select effective_date,
170: inventory_item_id,
171: organization_id,
172: sum(standard_cost) item_cost,
173: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
174: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
175: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
176: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
177: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
170: inventory_item_id,
171: organization_id,
172: sum(standard_cost) item_cost,
173: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
174: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
175: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
176: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
177: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
178: sysdate last_update_date,
171: organization_id,
172: sum(standard_cost) item_cost,
173: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
174: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
175: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
176: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
177: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
178: sysdate last_update_date,
179: l_application_user_id last_updated_by,
172: sum(standard_cost) item_cost,
173: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
174: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
175: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
176: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
177: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
178: sysdate last_update_date,
179: l_application_user_id last_updated_by,
180: sysdate creation_date,
173: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
174: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
175: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
176: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
177: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
178: sysdate last_update_date,
179: l_application_user_id last_updated_by,
180: sysdate creation_date,
181: l_application_user_id created_by,
188: cec.organization_id,
189: trunc(cec.last_update_date) effective_date,
190: gsob.currency_code,
191: cec.cost_element_id,
192: cec.standard_cost,
193: rank() over (partition by cec.inventory_item_id, cec.organization_id, trunc(cec.last_update_date),
194: gsob.currency_code order by cec.cost_update_id desc) r
195: from cst_elemental_costs cec,
196: hr_organization_information hoi,
206:
207:
208: end if;
209:
210: commit; -- commit the standard costing data into staging table.
211:
212:
213: -- Get the cost history for average/LIFO/FIFO costing orgs from mtl_cst_actual_cost_details.
214: if (l_exists_ac_orgs = 1) then
685: -- Running the actual incremental collection
686: l_exists_sc_orgs := 0;
687: l_exists_ac_orgs := 0;
688:
689: -- Find out if there are any standard costing orgs
690: select nvl(max(1),0)
691: into l_exists_sc_orgs
692: from sys.dual
693: where exists (
690: select nvl(max(1),0)
691: into l_exists_sc_orgs
692: from sys.dual
693: where exists (
694: select 'There are standard costing orgs'
695: from mtl_parameters
696: where primary_cost_method = 1
697: );
698:
705: from mtl_parameters
706: where primary_cost_method <> 1
707: );
708:
709: -- Get the cost history for standard costing orgs from cst_elemental_costs
710: if (l_exists_sc_orgs = 1) then
711: eni_dbi_util_pkg.log('There are Standard Costing orgs, hence starting incremental cost collection for them');
712:
713: -- Inserting the changed records into stage
707: );
708:
709: -- Get the cost history for standard costing orgs from cst_elemental_costs
710: if (l_exists_sc_orgs = 1) then
711: eni_dbi_util_pkg.log('There are Standard Costing orgs, hence starting incremental cost collection for them');
712:
713: -- Inserting the changed records into stage
714: /**
715: Bug: 4936377 If the last Processed cost id cannot be queried from bis_refresh_log table compute it
743: conversion_rate)
744: select effective_date,
745: inventory_item_id,
746: organization_id,
747: sum(standard_cost) item_cost,
748: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
749: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
750: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
751: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
744: select effective_date,
745: inventory_item_id,
746: organization_id,
747: sum(standard_cost) item_cost,
748: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
749: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
750: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
751: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
752: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
745: inventory_item_id,
746: organization_id,
747: sum(standard_cost) item_cost,
748: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
749: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
750: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
751: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
752: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
753: sysdate last_update_date,
746: organization_id,
747: sum(standard_cost) item_cost,
748: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
749: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
750: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
751: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
752: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
753: sysdate last_update_date,
754: l_application_user_id last_updated_by,
747: sum(standard_cost) item_cost,
748: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
749: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
750: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
751: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
752: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
753: sysdate last_update_date,
754: l_application_user_id last_updated_by,
755: sysdate creation_date,
748: nvl(sum(decode(cost_element_id, 1, standard_cost)), 0) material_cost,
749: nvl(sum(decode(cost_element_id, 2, standard_cost)), 0) material_overhead_cost,
750: nvl(sum(decode(cost_element_id, 3, standard_cost)), 0) resource_cost,
751: nvl(sum(decode(cost_element_id, 4, standard_cost)), 0) outside_processing_cost,
752: nvl(sum(decode(cost_element_id, 5, standard_cost)), 0) overhead_cost,
753: sysdate last_update_date,
754: l_application_user_id last_updated_by,
755: sysdate creation_date,
756: l_application_user_id created_by,
763: cec.organization_id,
764: trunc(cec.last_update_date) effective_date,
765: gsob.currency_code,
766: cec.cost_element_id,
767: cec.standard_cost,
768: rank() over (partition by cec.inventory_item_id, cec.organization_id, trunc(cec.last_update_date),
769: gsob.currency_code order by cec.cost_update_id desc) r
770: from cst_elemental_costs cec,
771: hr_organization_information hoi,
779: group by effective_date, inventory_item_id, organization_id, currency_code;
780:
781: end if;
782:
783: commit; -- commit the standard costing data into the staging.
784:
785: -- Get the cost changes for average/LIFO/FIFO costing orgs from mtl_cst_actual_cost_details.
786: if (l_exists_ac_orgs = 1) then
787: