DBA Data[Home] [Help]

APPS.CTO_UPDATE_CONFIGS_PK SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 82

This procedure is called by the Update Existing Configurations batch
progam. It does the following:
	1. Call procedures to populate bcol_upg based on the input params
	2. Delete sourcing for canned configs not to be processed
	3. Update bcol_upg with sequence numbers for batch processing
	4. Call procedure to update items and sourcing
***********************************************************************/
PROCEDURE Update_Configs
(
errbuf OUT NOCOPY varchar2,
retcode OUT NOCOPY varchar2,
p_item IN number,
p_dummy IN varchar2,
p_dummy2 IN varchar2,
p_category_set_id IN number, --bugfix3397123
p_dummy3 IN number, --bugfix3397123
p_cat_id IN number,
p_config_id IN number,
p_changed_src IN varchar2,
p_open_lines IN varchar2,
p_upgrade_mode In Number
) IS



/*
Redundant cursor

CURSOR c_seq(l_seq number) IS
select distinct sequence
from bom_cto_order_lines_upg
where sequence = l_seq;
Line: 130

 select distinct ato_line_id
 from    bom_cto_order_lines_upg
 where  status = 'CTO_SRC'
 and    line_id = ato_line_id;
Line: 146

WriteToLog('Begin Update Existing Configurations with Debug Level: '||gDebugLevel);
Line: 164

   update_atp_attributes(
                          p_item           => p_item,
                          p_cat_id         => p_cat_id,
                          p_config_id      => p_config_id,
                          x_return_status  => x_return_status,
                          x_msg_data       => x_msg_data,
                          x_msg_count      => x_msg_count);
Line: 172

   WriteToLog('Update Existing Configurations completed with SUCCESS');
Line: 182

delete from bom_cto_src_orgs_b
where line_id in (
	select bcolu.line_id
	from bom_cto_order_lines_upg bcolu
	where bcolu.config_item_id is not null
	and not exists (
		select 'exists'
		from oe_order_lines_all oel
		where oel.line_id = bcolu.line_id));
Line: 191

WriteToLog('Rows deleted from bcso_b::'|| sql%rowcount, 1);
Line: 194

delete from bom_cto_order_lines_upg;
Line: 195

WriteToLog('Rows deleted from bcol_upg::'|| sql%rowcount, 1);
Line: 198

select assignment_set_id
into l_cto_aset_id
from mrp_assignment_sets
where assignment_set_name = 'CTO Configuration Updates';
Line: 220

         INSERT INTO mrp_assignment_sets
	 (assignment_set_id ,
	  assignment_set_name,
	  description,
	  created_by,
	  last_updated_by,
	  creation_date,
	  last_update_date
	 )
	 VALUES
	 ( MRP_ASSIGNMENT_SETS_S.nextval,
	   'CTO Configuration Updates',
	   'Exclusively for use by CTO. Used during Upgrade Concurrent programs',
	   FND_GLOBAL.USER_ID,
	   FND_GLOBAL.USER_ID,
	   sysdate,
	   sysdate
	  )
	  returning assignment_set_id INTO l_cto_aset_id;
Line: 241

          WriteToLog('Assignment set name::'|| 'CTO Configuration Updates', 2);
Line: 250

delete from mrp_sr_assignments
where assignment_set_id = l_cto_aset_id;
Line: 253

WriteToLog('Rows deleted from cto assignment set::'|| sql%rowcount, 1);
Line: 280

	-- Delete sourcing for canned configurations not being upgraded
	-- (config_creation = 1 or 2) and not linked on open order lines
	-- Sourcing should not be deleted for pre-configured items in
	-- the match tables.
	--

	-- Modified by Renga Kannan on 06/06/06
	-- Fixed for bug 5263027
	-- Added a conidtion to check for open order with config items linked to the sales order

	l_stmt_num := 25;
Line: 291

	delete from mrp_sr_assignments
	where assignment_set_id = l_mrp_aset_id
	and inventory_item_id in
		(select config_item_id
		from bom_ato_configurations bac
		where not exists
			(select 'exists'
			from bom_cto_order_lines_upg bcolu
			where bcolu.config_item_id = bac.config_item_id)
		-- and not on open order lines
		and not exists
			(select 'exists'
			from oe_order_lines_all oel,
			bom_cto_order_lines bcol
			where bcol.config_item_id = bac.config_item_id
			and bcol.ato_line_id = oel.ato_line_id
			and nvl(oel.open_flag, 'N') = 'Y'
			and oel.item_type_code='CONFIG')
		-- and item is not pre-configured
		and not exists
			(select 'pc'
			from mtl_system_items msi
			where msi.inventory_item_id = bac.config_item_id
			and nvl(msi.auto_created_config_flag,'N') = 'N'));
Line: 316

	WriteToLog('Sourcing deleted::'||sql%rowcount, 2);
Line: 343

	-- Delete sourcing for canned configurations not being upgraded
	-- (config_creation = 1 or 2) and not on open order lines
	-- Sourcing should not be deleted for pre-configured items in the
	-- match tables.
	--
	l_stmt_num := 36;
Line: 354

        delete from mrp_sr_assignments
        where assignment_set_id = l_mrp_aset_id
          and inventory_item_id in
              (
               select config_item_id
                 from bom_ato_configurations bac,
                      mtl_item_categories mcat
                where bac.base_model_id = mcat.inventory_item_id
                  and mcat.category_id = p_cat_id
		  and not exists
                      (select 'exists'
                         from bom_cto_order_lines_upg bcolu
                        where bcolu.config_item_id = bac.config_item_id
                      )
                  and bac.config_item_id not in
                      (select nvl( bcol.config_item_id,-1)
                         from oe_order_lines_all oel,
                              bom_cto_order_lines bcol
                        where bcol.ato_line_id = oel.ato_line_id
			and   oel.item_type_code = 'CONFIG'
                          and open_flag = 'Y'
                      )
                  and not exists
                      (select 'pc'
                         from mtl_system_items msi
                        where msi.inventory_item_id = bac.config_item_id
                          and msi.auto_created_config_flag = 'N'
                      )
               );
Line: 385

	WriteToLog('Sourcing deleted::'||sql%rowcount, 2);
Line: 415

	-- Delete sourcing if this configuration is not being upgraded
	-- (config_creation = 1 or 2) and is not on open order lines.
	-- Sourcing should not be deleted if it is a pre-configured item.
	--

	delete from mrp_sr_assignments
	where assignment_set_id = l_mrp_aset_id
	and inventory_item_id = p_config_id
	-- not being upgraded
	and not exists
		(select 'exists'
		from bom_cto_order_lines_upg bcolu
		where bcolu.config_item_id = p_config_id)
	-- and not on open order lines
	and not exists           /* bug 3399310 sushant changed the query to identify config item exists */
		(select 'exists'
		from oe_order_lines_all oel,
		bom_cto_order_lines bcol
		where bcol.config_item_id = p_config_id
		and bcol.line_id = oel.ato_line_id
                and oel.item_type_code = 'CONFIG'
		and nvl(oel.open_flag, 'N') = 'Y')
	-- and item is not pre-configured
	and not exists
		(select 'pc'
		from mtl_system_items msi
		where msi.inventory_item_id = p_config_id
		and nvl(msi.auto_created_config_flag,'N') = 'N');
Line: 444

	WriteToLog('Sourcing deleted::'||sql%rowcount, 2);
Line: 451

select count(*)
into l_bcolu_count
from bom_cto_order_lines_upg;
Line: 480

select count(*)
into l_bcolu_count
from bom_cto_order_lines_upg
where status <>'ERROR';
Line: 517

	update bom_cto_order_lines_upg bcolu
	set bcolu.sequence = l_seq
	where bcolu.ato_line_id in
		(select ato_line_id
		from bom_cto_order_lines_upg bcolu2
		where bcolu2.ato_line_id = bcolu2.line_id
		and bcolu2.status IN ('UPG')
		and rownum < G_BATCH_SIZE + 1
		and bcolu2.sequence is null);
Line: 540

Cto_Update_Items_Pk.Update_Items_And_Sourcing(
			  p_changed_src     => p_changed_src
			, p_cat_id          => p_cat_id
			, p_upgrade_mode    => p_upgrade_mode
			, xReturnStatus     => l_return_status
			, xMsgCount         => l_msg_count
			, xMsgData          => l_msg_data);
Line: 549

	WriteToLog('ERROR: Update_items_and_sourcing returned unexpected error');
Line: 552

	WriteToLog('ERROR: Update_items_and_sourcing returned expected error');
Line: 555

	WriteToLog('Update_items_and_sourcing returned success', 3);
Line: 582

WriteToLog('update_configs: About to generate bom batch ID', 5);
Line: 587

   WriteToLog('update_configs: ' || 'Failed in set_bom_batch_id with unexp error.', 1);
Line: 598

select 'exists'
into l_exists
from bom_cto_order_lines_upg
where sequence = l_seq
and rownum = 1;
Line: 657

	delete from mtl_item_categories
	where category_id = p_cat_id;
Line: 660

	WriteToLog('Rows deleted from category::'||sql%rowcount, 2);
Line: 676

WriteToLog('Update Existing Configurations completed with SUCCESS');
Line: 683

	WriteToLog('ERROR: Exp error in CTO_Update_Configs_Pk.Update_Configs:: '|| l_stmt_num ||'::'||sqlerrm);
Line: 685

	WriteToLog('Update Existing Configurations completed with ERROR.', 1);
Line: 692

	WriteToLog('ERROR: Unexp error in CTO_Update_Configs_Pk.Update_Configs:: '|| l_stmt_num ||'::'||sqlerrm, 1);
Line: 694

	WriteToLog('Update Existing Configurations completed with ERROR');
Line: 700

	WriteToLog('ERROR: Others error in CTO_Update_Configs_Pk.Update_Configs:: '|| l_stmt_num ||'::'||sqlerrm, 1);
Line: 702

	WriteToLog('Update Existing Configurations completed with ERROR.', 1);
Line: 708

END update_configs;
Line: 726

select distinct bac.config_item_id config_id
from bom_ato_configurations bac,
mtl_system_items msi
where NOT EXISTS
	(select 'exists'
	from bom_cto_order_lines_upg bcolu
	where bcolu.config_item_id = bac.config_item_id)
and bac.base_model_id = msi.inventory_item_id
and bac.organization_id = msi.organization_id
and nvl(msi.config_orgs, '1') = '3';
Line: 744

select distinct bac.config_item_id config_id
from bom_ato_configurations bac,
mtl_system_items msi
-- item attribute is 3
where bac.base_model_id = msi.inventory_item_id
and bac.organization_id = msi.organization_id
and nvl(msi.config_orgs, '1') = '3'
-- and is top parent with attribute 3
and NOT EXISTS
	(select 'exists'
	from bom_ato_configurations bac2
	, mtl_system_items msi2
	where bac.config_item_id = bac2.component_item_id
	and bac2.base_model_id = msi2.inventory_item_id
	and bac2.organization_id = msi2.organization_id
	and nvl(msi2.config_orgs, '1') = '3')
-- and not already in bcol_upg
and NOT EXISTS
	(select 'exists'
	from bom_cto_order_lines_upg bcolu
	where bcolu.config_item_id = bac.config_item_id);
Line: 787

		WriteToLog('Match profile is No and you chose not to update existing configurations. No configurations will be updated.');
Line: 800

			-- select all open order lines having config items with attribute in (2,3)
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 1', 3);
Line: 806

			select count(line_id)
			into l_count
			from bom_cto_order_lines_upg;
Line: 812

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			, config_creation
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
                        , bcol2.PERFORM_MATCH                   --7201878
			--, 'N'		--PERFORM_MATCH
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'		--REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			, nvl(mtl.config_orgs, '1')
			--changed the where clause to use a subquery
			--bugfix 3841575
			from bom_cto_order_lines bcol2
			, mtl_system_items mtl
			-- select entire configuration
			where mtl.inventory_item_id =  bcol2.inventory_item_id
			and   mtl.organization_id = bcol2.ship_from_org_id
			and bcol2.ato_line_id in
			            (select distinct bcol1.ato_line_id
                                     from bom_cto_order_lines bcol1
                                     , oe_order_lines_all oel
				     , mtl_system_items msi
				    -- for configs whose models have attr=2,3
				    where bcol1.config_item_id is not null
				    and bcol1.inventory_item_id = msi.inventory_item_id
				    and bcol1.ship_from_org_id = msi.organization_id
				    and nvl(msi.config_orgs, '1') in ('2', '3')
				      -- and are on open order lines
				    and bcol1.line_id = oel.line_id
				    and nvl(oel.open_flag, 'N') = 'Y');
Line: 907

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 911

			-- select all open order lines having canned config items with attribute = 3
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 2', 3);
Line: 917

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			, config_creation
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
                        , bcol2.PERFORM_MATCH               --7201878
			--, 'Y'		--PERFORM_MATCH  /* Sushant Made changes for identifying matched items */
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'		--REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			, nvl(msi.config_orgs, '1')
			from bom_cto_order_lines bcol1
			, bom_cto_order_lines bcol2
			, bom_ato_configurations bac
			, oe_order_lines_all oel
			, mtl_system_items msi
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and exists in bcol
			and bac.config_item_id = bcol1.config_item_id
			-- on open order lines
			and bcol1.line_id = oel.line_id
			and nvl(oel.open_flag, 'N') = 'Y'
			and bcol2.ato_line_id = bcol1.ato_line_id;
Line: 1005

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1011

			-- select additional config items with attribute = 3 on closed order lines
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 3', 3);
Line: 1017

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			, config_creation
			)
			select distinct
			bcol.ATO_LINE_ID
			, bcol.BATCH_ID
			, bcol.BOM_ITEM_TYPE
			, bcol.COMPONENT_CODE
			, bcol.COMPONENT_SEQUENCE_ID
			, bcol.CONFIG_ITEM_ID
			, bcol.INVENTORY_ITEM_ID
			, bcol.ITEM_TYPE_CODE
			, bcol.LINE_ID
			, bcol.LINK_TO_LINE_ID
			, bcol.ORDERED_QUANTITY
			, bcol.ORDER_QUANTITY_UOM
			, bcol.PARENT_ATO_LINE_ID
                        , bcol.PERFORM_MATCH           --7201878
			--, 'Y'		--PERFORM_MATCH  /* Sushant made changes to identify matched items */
			, bcol.PLAN_LEVEL
			, bcol.SCHEDULE_SHIP_DATE
			, bcol.SHIP_FROM_ORG_ID
			, bcol.TOP_MODEL_LINE_ID
			, bcol.WIP_SUPPLY_TYPE
			, bcol.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol.CREATED_BY
			, bcol.LAST_UPDATE_LOGIN
			, bcol.REQUEST_ID
			, bcol.PROGRAM_APPLICATION_ID
			, 99		-- matched item on closed line
			, bcol.PROGRAM_UPDATE_DATE
			, bcol.OPTION_SPECIFIC
			, 'N'		--REUSE_CONFIG
			, bcol.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			, nvl(msi.config_orgs, '1')
			from bom_ato_configurations bac
			, bom_cto_order_lines bcol
			, mtl_system_items msi
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and not already in bcol_upg
			and NOT EXISTS
				(select 'exists'
				from bom_cto_order_lines_upg bcolu
				where bcolu.config_item_id = bac.config_item_id)
			-- select first ato_line_id in bcol
			and bcol.ato_line_id =
				(select bcol1.ato_line_id
				from bom_cto_order_lines bcol1
				where bcol1.config_item_id = bac.config_item_id
				-- pick up only if config is at top level
				and bcol1.line_id = bcol1.ato_line_id
				and rownum = 1)
			;
Line: 1111

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1114

			-- select all individual (not top level) config items in bac having item attribute = 3 and not in bcol_upg
			-- populate into bcol_upg from bcol or bac
			-- mark as UPG
			-- mark with program_id = 99 to indicate that it was populated from bac
			--
			WriteToLog('sql 3', 2);
Line: 1127

				select 'Y'
				into l_exists
				from bom_cto_order_lines_upg
				where config_item_id = v_bac.config_id
				and rownum = 1;
Line: 1160

			-- select all open order lines
			-- populate into bcol_upg
			-- mark as UPG
			-- TEST THIS!!
			--
			WriteToLog('sql 5', 3);
Line: 1167

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			, CONFIG_CREATION
			)
			select distinct
			bcol.ATO_LINE_ID
			, bcol.BATCH_ID
			, bcol.BOM_ITEM_TYPE
			, bcol.COMPONENT_CODE
			, bcol.COMPONENT_SEQUENCE_ID
			, bcol.CONFIG_ITEM_ID
			, bcol.INVENTORY_ITEM_ID
			, bcol.ITEM_TYPE_CODE
			, bcol.LINE_ID
			, bcol.LINK_TO_LINE_ID
			, bcol.ORDERED_QUANTITY
			, bcol.ORDER_QUANTITY_UOM
			, bcol.PARENT_ATO_LINE_ID
                        , bcol.PERFORM_MATCH              --7201878
			--, 'N'		--PERFORM_MATCH
			, bcol.PLAN_LEVEL
			, bcol.SCHEDULE_SHIP_DATE
			, bcol.SHIP_FROM_ORG_ID
			, bcol.TOP_MODEL_LINE_ID
			, bcol.WIP_SUPPLY_TYPE
			, bcol.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol.CREATED_BY
			, bcol.LAST_UPDATE_LOGIN
			, bcol.REQUEST_ID
			, bcol.PROGRAM_APPLICATION_ID
			, bcol.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol.OPTION_SPECIFIC
			, 'N'		--REUSE_CONFIG
			, bcol.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			, nvl(msi.CONFIG_ORGS, '1')
			from bom_cto_order_lines bcol
			, oe_order_lines_all oel
			, mtl_system_items msi
			-- select all configs on open order lines
			where bcol.ato_line_id = oel.ato_line_id
			and nvl(oel.open_flag, 'N') = 'Y'
			and bcol.inventory_item_id = msi.inventory_item_id
			and bcol.ship_from_org_id = msi.organization_id
                        and oel.item_type_code = 'CONFIG' ; /* added condition for bug 3599397 */
Line: 1250

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1254

			-- select all open order lines having canned config items with attribute = 3
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 6', 3);
Line: 1260

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			, CONFIG_CREATION
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
                        , bcol2.PERFORM_MATCH                 --7201878
			--, 'Y'		--PERFORM_MATCH   /* Sushant made changes to identify matched items */
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'		--REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			, nvl(msi.CONFIG_ORGS, '1')
			from bom_cto_order_lines bcol1
			, bom_cto_order_lines bcol2
			, bom_ato_configurations bac
			, oe_order_lines_all oel
			, mtl_system_items msi
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and exists in bcol
			and bac.config_item_id = bcol1.config_item_id
			-- on open order lines
			and bcol1.line_id = oel.line_id
			and nvl(oel.open_flag, 'N') = 'Y'
			and bcol2.ato_line_id = bcol1.ato_line_id
			;
Line: 1350

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1356

			-- select additional TOP LEVEL config items with attribute = 3 on closed order lines
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 7', 3);
Line: 1362

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			, CONFIG_CREATION
			)
			select distinct
			bcol.ATO_LINE_ID
			, bcol.BATCH_ID
			, bcol.BOM_ITEM_TYPE
			, bcol.COMPONENT_CODE
			, bcol.COMPONENT_SEQUENCE_ID
			, bcol.CONFIG_ITEM_ID
			, bcol.INVENTORY_ITEM_ID
			, bcol.ITEM_TYPE_CODE
			, bcol.LINE_ID
			, bcol.LINK_TO_LINE_ID
			, bcol.ORDERED_QUANTITY
			, bcol.ORDER_QUANTITY_UOM
			, bcol.PARENT_ATO_LINE_ID
                        , bcol.PERFORM_MATCH              --7201878
			--, 'N'		--PERFORM_MATCH  /* Sushant made changes to identify matched items */
			, bcol.PLAN_LEVEL
			, bcol.SCHEDULE_SHIP_DATE
			, bcol.SHIP_FROM_ORG_ID
			, bcol.TOP_MODEL_LINE_ID
			, bcol.WIP_SUPPLY_TYPE
			, bcol.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol.CREATED_BY
			, bcol.LAST_UPDATE_LOGIN
			, bcol.REQUEST_ID
			, bcol.PROGRAM_APPLICATION_ID
			, 99		-- matched item on closed line
			, bcol.PROGRAM_UPDATE_DATE
			, bcol.OPTION_SPECIFIC
			, 'N'		--REUSE_CONFIG
			, bcol.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			, nvl(msi.CONFIG_ORGS, '1')
			from bom_ato_configurations bac
			, bom_cto_order_lines bcol
			, mtl_system_items msi
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and is top parent with attribute 3
			and NOT EXISTS
				(select 'exists'
				from bom_ato_configurations bac2
				, mtl_system_items msi2
				where bac.config_item_id = bac2.component_item_id
				and bac2.base_model_id = msi2.inventory_item_id
				and bac2.organization_id = msi2.organization_id
				and nvl(msi2.config_orgs, '1') = '3')
			-- and not already in bcol_upg
			and NOT EXISTS
				(select 'exists'
				from bom_cto_order_lines_upg bcolu
				where bcolu.config_item_id = bac.config_item_id)
			-- select first ato_line_id in bcol
			and bcol.ato_line_id =
				(select bcol1.ato_line_id
				from bom_cto_order_lines bcol1
				where bcol1.config_item_id = bac.config_item_id
				-- pick up only if config is at top level
				and bcol1.line_id = bcol1.ato_line_id
				and rownum = 1)
			;
Line: 1466

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1469

			-- select all top level config items in bac having item attribute = 3 and not in bcol_upg
			-- populate into bcol_upg from bcol or bac
			-- mark as UPG
			-- mark with program_id = 99 to indicate that it was populated from bac
			--
			WriteToLog('sql 8', 3);
Line: 1479

				select 'exists'
				into l_exists
				from bom_cto_order_lines_upg bcolu
				where bcolu.config_item_id = v_bac_top.config_id
				and rownum = 1;
Line: 1554

select /*+ ORDERED */ distinct bac.config_item_id config_id --Bugfix 6617686 Added a hint
from mtl_item_categories mcat,  --Bugfix 6617686: Changed the order of tables
mtl_system_items msi,
bom_ato_configurations bac
where NOT EXISTS
	(select 'exists'
	from bom_cto_order_lines_upg bcolu
	where bcolu.config_item_id = bac.config_item_id)
and bac.base_model_id = msi.inventory_item_id
and bac.organization_id = msi.organization_id
and nvl(msi.config_orgs, '1') = '3'
-- and base model is in CTO category
and mcat.inventory_item_id = msi.inventory_item_id
and mcat.organization_id = msi.organization_id
and mcat.category_id = p_cat_id;
Line: 1578

select /*+ ORDERED*/ distinct bac.config_item_id config_id  --Bugfix 6617686 Added a hint
from mtl_item_categories mcat, --Bugfix 6617686 Changed the order of tables
mtl_system_items msi,
bom_ato_configurations bac
-- item attribute is 3
where bac.base_model_id = msi.inventory_item_id
and bac.organization_id = msi.organization_id
and nvl(msi.config_orgs, '1') = '3'
-- and base model is in CTO category
and mcat.inventory_item_id = msi.inventory_item_id
and mcat.organization_id = msi.organization_id
and mcat.category_id = p_cat_id
-- and is top parent with attribute 3
and NOT EXISTS
	(select 'exists'
	from bom_ato_configurations bac2
	, mtl_system_items msi2
	where bac.config_item_id = bac2.component_item_id
	and bac2.base_model_id = msi2.inventory_item_id
	and bac2.organization_id = msi2.organization_id
	and nvl(msi2.config_orgs, '1') = '3')
-- and not already in bcol_upg
and NOT EXISTS
	(select 'exists'
	from bom_cto_order_lines_upg bcolu
	where bcolu.config_item_id = bac.config_item_id);
Line: 1625

		WriteToLog('Match profile is No and you chose not to update existing configurations. No configurations will be updated.');
Line: 1639

			-- select all open order lines having config items in l_cat_id with attribute in (2,3)
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 1', 3);
Line: 1645

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, config_creation
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
                        , bcol2.PERFORM_MATCH           --7201878
			--, 'N'	--bcol2.PERFORM_MATCH
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'	--bcol2.REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol2.SEQUENCE
			, nvl(msi.config_orgs, '1')
			from bom_cto_order_lines bcol1
			, bom_cto_order_lines bcol2
			, oe_order_lines_all oel
			, mtl_system_items msi
			, mtl_item_categories mcat
			-- select entire configuration
			where bcol2.ato_line_id = bcol1.ato_line_id
			and bcol1.config_item_id is not null
			-- for configs whose models are in CTO category
			and mcat.inventory_item_id = bcol1.inventory_item_id
			and mcat.organization_id = bcol1.ship_from_org_id
			and mcat.category_id = p_cat_id
			-- for configs whose models have attr=2,3
			and bcol1.inventory_item_id = msi.inventory_item_id
			and bcol1.ship_from_org_id = msi.organization_id
			and nvl(msi.config_orgs, '1') in ('2', '3')
			-- and are on open order lines
			and bcol1.line_id = oel.ato_line_id /* changed line_id to ato_line_id */
			and nvl(oel.open_flag, 'N') = 'Y'
                        and oel.item_type_code = 'CONFIG' ; /* added check for config linked to oe */
Line: 1741

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1745

			-- select all open order lines having canned config items with attribute = 3
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 2', 3);
Line: 1751

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, config_creation
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
                        , bcol2.PERFORM_MATCH                   --7201878
			--, 'Y'	--bcol2.PERFORM_MATCH /* Sushant made changes to identify matched items */
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'	--bcol2.REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol2.SEQUENCE
			, nvl(msi.config_orgs, '1')
			from bom_cto_order_lines bcol1
			, bom_cto_order_lines bcol2
			, bom_ato_configurations bac
			, oe_order_lines_all oel
			, mtl_system_items msi
			, mtl_item_categories mcat
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and exists in bcol
			and bac.config_item_id = bcol1.config_item_id
			-- for configs whose models are in CTO category
			and mcat.inventory_item_id = bcol1.inventory_item_id
			and mcat.organization_id = bcol1.ship_from_org_id
			and mcat.category_id = p_cat_id
			-- on open order lines
			and bcol1.line_id = oel.ato_line_id /* changed line_id to ato_line_id */
			and nvl(oel.open_flag, 'N') = 'Y'
			and bcol2.ato_line_id = bcol1.ato_line_id
                        and oel.item_type_code = 'CONFIG' ;  /* added check for config linked to oe */
Line: 1847

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1853

			-- select additional config items with attribute = 3 on closed order lines
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 3', 3);
Line: 1859

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, config_creation
			)
			select /*+ ORDERED*/ distinct  --Bugfix 6617686 Added a hint
			bcol.ATO_LINE_ID
			, bcol.BATCH_ID
			, bcol.BOM_ITEM_TYPE
			, bcol.COMPONENT_CODE
			, bcol.COMPONENT_SEQUENCE_ID
			, bcol.CONFIG_ITEM_ID
			, bcol.INVENTORY_ITEM_ID
			, bcol.ITEM_TYPE_CODE
			, bcol.LINE_ID
			, bcol.LINK_TO_LINE_ID
			, bcol.ORDERED_QUANTITY
			, bcol.ORDER_QUANTITY_UOM
			, bcol.PARENT_ATO_LINE_ID
                        , bcol.PERFORM_MATCH                    --7201878
			--, 'N'	--bcol.PERFORM_MATCH
			, bcol.PLAN_LEVEL
			, bcol.SCHEDULE_SHIP_DATE
			, bcol.SHIP_FROM_ORG_ID
			, bcol.TOP_MODEL_LINE_ID
			, bcol.WIP_SUPPLY_TYPE
			, bcol.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol.CREATED_BY
			, bcol.LAST_UPDATE_LOGIN
			, bcol.REQUEST_ID
			, bcol.PROGRAM_APPLICATION_ID
			, 99		-- matched item on closed line
			, bcol.PROGRAM_UPDATE_DATE
			, bcol.OPTION_SPECIFIC
			, 'N'	--bcol.REUSE_CONFIG
			, bcol.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol.SEQUENCE
			, nvl(msi.config_orgs, '1')
			from mtl_item_categories mcat --Bugfix 6617686 Changed the order of tables
			, mtl_system_items msi
			, bom_ato_configurations bac
                        , bom_cto_order_lines bcol
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and base model is in CTO category
			and mcat.inventory_item_id = msi.inventory_item_id
			and mcat.organization_id = msi.organization_id
			and mcat.category_id = p_cat_id
			-- and not already in bcol_upg
			and NOT EXISTS
				(select 'exists'
				from bom_cto_order_lines_upg bcolu
				where bcolu.config_item_id = bac.config_item_id)
			-- select first ato_line_id in bcol
			and bcol.ato_line_id =
				(select bcol1.ato_line_id
				from bom_cto_order_lines bcol1
				where bcol1.config_item_id = bac.config_item_id
				-- pick up only if config is at top level
				and bcol1.line_id = bcol1.ato_line_id
				and rownum = 1)
			;
Line: 1960

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 1963

			-- select all individual (not top level) config items in bac having item attribute = 3 and not in bcol_upg
			-- populate into bcol_upg from bcol or bac
			-- mark as UPG
			-- mark with program_id = 99 to indicate that it was populated from bac
			--
			WriteToLog('sql 4', 3);
Line: 1976

				select 'Y'
				into l_exists
				from bom_cto_order_lines_upg
				where config_item_id = v_bac.config_id
				and rownum = 1;
Line: 2008

			-- select all open order lines
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 5', 3);
Line: 2014

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, CONFIG_CREATION
			)
			select distinct
			bcol.ATO_LINE_ID
			, bcol.BATCH_ID
			, bcol.BOM_ITEM_TYPE
			, bcol.COMPONENT_CODE
			, bcol.COMPONENT_SEQUENCE_ID
			, bcol.CONFIG_ITEM_ID
			, bcol.INVENTORY_ITEM_ID
			, bcol.ITEM_TYPE_CODE
			, bcol.LINE_ID
			, bcol.LINK_TO_LINE_ID
			, bcol.ORDERED_QUANTITY
			, bcol.ORDER_QUANTITY_UOM
			, bcol.PARENT_ATO_LINE_ID
                        , bcol.PERFORM_MATCH                    --7201878
			--, 'N'	--bcol.PERFORM_MATCH
			, bcol.PLAN_LEVEL
			, bcol.SCHEDULE_SHIP_DATE
			, bcol.SHIP_FROM_ORG_ID
			, bcol.TOP_MODEL_LINE_ID
			, bcol.WIP_SUPPLY_TYPE
			, bcol.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol.CREATED_BY
			, bcol.LAST_UPDATE_LOGIN
			, bcol.REQUEST_ID
			, bcol.PROGRAM_APPLICATION_ID
			, bcol.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol.OPTION_SPECIFIC
			, 'N'	--bcol.REUSE_CONFIG
			, bcol.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol.SEQUENCE
			, nvl(msi2.CONFIG_ORGS, '1')
			from bom_cto_order_lines bcol
			, oe_order_lines_all oel
			, mtl_system_items msi2
			-- select all configs on open order lines
			where bcol.ato_line_id = oel.ato_line_id
			and bcol.inventory_item_id = msi2.inventory_item_id
			and bcol.ship_from_org_id = msi2.organization_id
			and nvl(oel.open_flag, 'N') = 'Y'
			and oel.ato_line_id in -- bug 6617686 connect using oel rather than bcol to get better filtering
				(select /*+ leading(MCAT) */ distinct bcol2.ato_line_id --Bugfix 6617686 Added a hint
				from mtl_item_categories mcat --Bugfix 6617686 Changed the order of tables
				, mtl_system_items msi
				, bom_cto_order_lines bcol2
				where bcol2.config_item_id is not null
				and bcol2.inventory_item_id = msi.inventory_item_id
				and bcol2.ship_from_org_id = msi.organization_id
				-- and base model is in CTO category
				and mcat.inventory_item_id = msi.inventory_item_id
				and mcat.organization_id = msi.organization_id
				and mcat.category_id = p_cat_id)
                        and oel.item_type_code = 'CONFIG' ;/* original bug detected, added condition for bug 3599397 */
Line: 2111

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 2115

			-- select all open order lines having canned config items with attribute = 3 and assigned to CTO category
			-- populate into bcol_upg
			-- mark as UPG
			-- TEST THIS!!
			--
			WriteToLog('sql 6', 3);
Line: 2122

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, CONFIG_CREATION
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
                        , bcol2.PERFORM_MATCH                   --7201878
			--, 'Y'	--bcol2.PERFORM_MATCH  /* Sushant made changes to identify matched items */
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'	--bcol2.REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol2.SEQUENCE
			, nvl(msi.CONFIG_ORGS, '1')
			from bom_cto_order_lines bcol1
			, bom_cto_order_lines bcol2
			, bom_ato_configurations bac
			, oe_order_lines_all oel
			, mtl_system_items msi
			, mtl_item_categories mcat
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and exists in bcol
			and bac.config_item_id = bcol1.config_item_id
			-- on open order lines
			and bcol1.line_id = oel.line_id
			and nvl(oel.open_flag, 'N') = 'Y'
			and bcol2.ato_line_id = bcol1.ato_line_id
			-- and base model is in CTO category
			and mcat.inventory_item_id = msi.inventory_item_id
			and mcat.organization_id = msi.organization_id
			and mcat.category_id = p_cat_id;
Line: 2218

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 2224

			-- select additional TOP LEVEL config items with attribute = 3 on closed order lines
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 7', 3);
Line: 2230

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, CONFIG_CREATION
			)
			select /*+ leading(MCAT) */ distinct
			bcol.ATO_LINE_ID
			, bcol.BATCH_ID
			, bcol.BOM_ITEM_TYPE
			, bcol.COMPONENT_CODE
			, bcol.COMPONENT_SEQUENCE_ID
			, bcol.CONFIG_ITEM_ID
			, bcol.INVENTORY_ITEM_ID
			, bcol.ITEM_TYPE_CODE
			, bcol.LINE_ID
			, bcol.LINK_TO_LINE_ID
			, bcol.ORDERED_QUANTITY
			, bcol.ORDER_QUANTITY_UOM
			, bcol.PARENT_ATO_LINE_ID
                        , bcol.PERFORM_MATCH                    --7201878
			--, 'Y'	--bcol.PERFORM_MATCH /* Sushant made changes to identify matched items */
			, bcol.PLAN_LEVEL
			, bcol.SCHEDULE_SHIP_DATE
			, bcol.SHIP_FROM_ORG_ID
			, bcol.TOP_MODEL_LINE_ID
			, bcol.WIP_SUPPLY_TYPE
			, bcol.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol.CREATED_BY
			, bcol.LAST_UPDATE_LOGIN
			, bcol.REQUEST_ID
			, bcol.PROGRAM_APPLICATION_ID
			, 99		-- matched item on closed line
			, bcol.PROGRAM_UPDATE_DATE
			, bcol.OPTION_SPECIFIC
			, 'N'	--bcol.REUSE_CONFIG
			, bcol.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol.SEQUENCE
			, nvl(msi.CONFIG_ORGS, '1')
			from bom_ato_configurations bac
			, bom_cto_order_lines bcol
			, mtl_system_items msi
			, mtl_item_categories mcat
			-- base model has item attr = 3
			where bac.base_model_id = msi.inventory_item_id
			and bac.organization_id = msi.organization_id
			and nvl(msi.config_orgs, '1') = '3'
			-- and base model is in CTO category
			and mcat.inventory_item_id = msi.inventory_item_id
			and mcat.organization_id = msi.organization_id
			and mcat.category_id = p_cat_id
			-- and is top parent with attribute 3
			and NOT EXISTS
				(select 'exists'
				from bom_ato_configurations bac2
				, mtl_system_items msi2
				where bac.config_item_id = bac2.component_item_id
				and bac2.base_model_id = msi2.inventory_item_id
				and bac2.organization_id = msi2.organization_id
				and nvl(msi2.config_orgs, '1') = '3')
			-- and not already in bcol_upg
			and NOT EXISTS
				(select 'exists'
				from bom_cto_order_lines_upg bcolu
				where bcolu.config_item_id = bac.config_item_id)
			-- select first ato_line_id in bcol
			and bcol.ato_line_id =
				(select bcol1.ato_line_id
				from bom_cto_order_lines bcol1
				where bcol1.config_item_id = bac.config_item_id
				-- pick up only if config is at top level
				and bcol1.line_id = bcol1.ato_line_id
				and rownum = 1)
			;
Line: 2341

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 2344

			-- select all top level config items in bac having item attribute = 3 and not in bcol_upg
			-- populate into bcol_upg from bcol or bac
			-- mark as UPG
			-- mark with program_id = 99 to indicate that it was populated from bac
			--
			WriteToLog('sql 8', 3);
Line: 2354

				select 'exists'
				into l_exists
				from bom_cto_order_lines_upg bcolu
				where bcolu.config_item_id = v_bac_top.config_id
				and rownum = 1;
Line: 2446

		WriteToLog('Match profile is No and you chose not to update existing configurations. No configurations will be updated.');
Line: 2453

	select nvl(msi.config_orgs, '1')
	into l_attribute
	from mtl_system_items msi
	where msi.inventory_item_id =
		(select msi2.base_item_id
		from mtl_system_items msi2
		where msi2.inventory_item_id = p_config_id
		and rownum = 1)
	and rownum = 1;
Line: 2472

			-- select all open order lines having this config item
			-- populate into bcol_upg
			-- mark as UPG
			--
			WriteToLog('sql 1', 3);
Line: 2478

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, CONFIG_CREATION
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
			, bcol2.perform_match  -- Sushant Changed as part of bug 3472654  'N'
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'	--bcol2.REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol2.SEQUENCE
			, nvl(msi.config_orgs, '1')
			from bom_cto_order_lines bcol1
			, bom_cto_order_lines bcol2
			, oe_order_lines_all oel
			, mtl_system_items msi
			, oe_order_lines_all oel2 --bugfix 3371155
			-- select entire configuration
			where bcol2.ato_line_id = bcol1.ato_line_id
			-- to get item attribute
			and msi.inventory_item_id = bcol2.inventory_item_id
			and msi.organization_id = bcol2.ship_from_org_id
			-- for this config
			and bcol1.config_item_id = p_config_id
			-- and are on open order lines
			and bcol1.line_id = oel.line_id
			and nvl(oel.open_flag, 'N') = 'Y'
			--bugfix  3371155
			 and bcol1.ato_line_id = oel2.ato_line_id
                        and oel2.item_type_code = 'CONFIG'
			--end 3371155
			;
Line: 2573

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 2578

			-- select all open order lines having this canned config item, only if it has attribute = 3
			-- populate into bcol_upg
			-- mark as UPG
			--
			IF (l_attribute = 3) THEN
			WriteToLog('sql 2', 3);
Line: 2585

			insert into bom_cto_order_lines_upg
			(
			 ATO_LINE_ID
			, BATCH_ID
			, BOM_ITEM_TYPE
			, COMPONENT_CODE
			, COMPONENT_SEQUENCE_ID
			, CONFIG_ITEM_ID
			, INVENTORY_ITEM_ID
			, ITEM_TYPE_CODE
			, LINE_ID
			, LINK_TO_LINE_ID
			, ORDERED_QUANTITY
			, ORDER_QUANTITY_UOM
			, PARENT_ATO_LINE_ID
			, PERFORM_MATCH
			, PLAN_LEVEL
			, SCHEDULE_SHIP_DATE
			, SHIP_FROM_ORG_ID
			, TOP_MODEL_LINE_ID
			, WIP_SUPPLY_TYPE
			, HEADER_ID
			, LAST_UPDATE_DATE
			, LAST_UPDATED_BY
			, CREATION_DATE
			, CREATED_BY
			, LAST_UPDATE_LOGIN
			, REQUEST_ID
			, PROGRAM_APPLICATION_ID
			, PROGRAM_ID
			, PROGRAM_UPDATE_DATE
			, OPTION_SPECIFIC
			, REUSE_CONFIG
			, QTY_PER_PARENT_MODEL
			, STATUS
			--, SEQUENCE
			, CONFIG_CREATION
			)
			select distinct
			bcol2.ATO_LINE_ID
			, bcol2.BATCH_ID
			, bcol2.BOM_ITEM_TYPE
			, bcol2.COMPONENT_CODE
			, bcol2.COMPONENT_SEQUENCE_ID
			, bcol2.CONFIG_ITEM_ID
			, bcol2.INVENTORY_ITEM_ID
			, bcol2.ITEM_TYPE_CODE
			, bcol2.LINE_ID
			, bcol2.LINK_TO_LINE_ID
			, bcol2.ORDERED_QUANTITY
			, bcol2.ORDER_QUANTITY_UOM
			, bcol2.PARENT_ATO_LINE_ID
                        , bcol2.PERFORM_MATCH                   --7201878
			--, 'Y'	--bcol2.PERFORM_MATCH /* Sushant made change to identify matched items */
			, bcol2.PLAN_LEVEL
			, bcol2.SCHEDULE_SHIP_DATE
			, bcol2.SHIP_FROM_ORG_ID
			, bcol2.TOP_MODEL_LINE_ID
			, bcol2.WIP_SUPPLY_TYPE
			, bcol2.HEADER_ID
			, sysdate	--LAST_UPDATE_DATE
			, bcol2.LAST_UPDATED_BY
			, sysdate	--CREATION_DATE
			, bcol2.CREATED_BY
			, bcol2.LAST_UPDATE_LOGIN
			, bcol2.REQUEST_ID
			, bcol2.PROGRAM_APPLICATION_ID
			, bcol2.PROGRAM_ID
			, sysdate	--PROGRAM_UPDATE_DATE
			, bcol2.OPTION_SPECIFIC
			, 'N'	--bcol2.REUSE_CONFIG
			, bcol2.QTY_PER_PARENT_MODEL
			, 'UPG'		--STATUS
			--, bcol2.SEQUENCE
			, nvl(msi.config_orgs, '1')
			from bom_cto_order_lines bcol1
			, bom_cto_order_lines bcol2
			, bom_ato_configurations bac
			, oe_order_lines_all oel
			, mtl_system_items msi
			where bac.config_item_id = p_config_id
			-- and exists in bcol
			and bac.config_item_id = bcol1.config_item_id
			-- on open order lines
			and bcol1.line_id = oel.line_id
			and nvl(oel.open_flag, 'N') = 'Y'
			and bcol2.ato_line_id = bcol1.ato_line_id
			-- to get item attribute
			and msi.inventory_item_id = bcol2.inventory_item_id
			and msi.organization_id = bcol2.ship_from_org_id;
Line: 2676

			WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 2683

			-- select this config item on closed order lines, only if attribute = 3 and not already in bcol_upg
			-- populate into bcol_upg
			-- mark as UPG
			--
			IF (l_attribute = 3) THEN
				WriteToLog('sql 3', 3);
Line: 2690

				insert into bom_cto_order_lines_upg
				(
				 ATO_LINE_ID
				, BATCH_ID
				, BOM_ITEM_TYPE
				, COMPONENT_CODE
				, COMPONENT_SEQUENCE_ID
				, CONFIG_ITEM_ID
				, INVENTORY_ITEM_ID
				, ITEM_TYPE_CODE
				, LINE_ID
				, LINK_TO_LINE_ID
				, ORDERED_QUANTITY
				, ORDER_QUANTITY_UOM
				, PARENT_ATO_LINE_ID
				, PERFORM_MATCH
				, PLAN_LEVEL
				, SCHEDULE_SHIP_DATE
				, SHIP_FROM_ORG_ID
				, TOP_MODEL_LINE_ID
				, WIP_SUPPLY_TYPE
				, HEADER_ID
				, LAST_UPDATE_DATE
				, LAST_UPDATED_BY
				, CREATION_DATE
				, CREATED_BY
				, LAST_UPDATE_LOGIN
				, REQUEST_ID
				, PROGRAM_APPLICATION_ID
				, PROGRAM_ID
				, PROGRAM_UPDATE_DATE
				, OPTION_SPECIFIC
				, REUSE_CONFIG
				, QTY_PER_PARENT_MODEL
				, STATUS
				, CONFIG_CREATION
				)
				select distinct
				bcol.ATO_LINE_ID
				, bcol.BATCH_ID
				, bcol.BOM_ITEM_TYPE
				, bcol.COMPONENT_CODE
				, bcol.COMPONENT_SEQUENCE_ID
				, bcol.CONFIG_ITEM_ID
				, bcol.INVENTORY_ITEM_ID
				, bcol.ITEM_TYPE_CODE
				, bcol.LINE_ID
				, bcol.LINK_TO_LINE_ID
				, bcol.ORDERED_QUANTITY
				, bcol.ORDER_QUANTITY_UOM
				, bcol.PARENT_ATO_LINE_ID
                                , bcol.PERFORM_MATCH                    --7201878
				--, 'Y'	--bcol.PERFORM_MATCH  /* Sushant made changes to identify matched items */
				, bcol.PLAN_LEVEL
				, bcol.SCHEDULE_SHIP_DATE
				, bcol.SHIP_FROM_ORG_ID
				, bcol.TOP_MODEL_LINE_ID
				, bcol.WIP_SUPPLY_TYPE
				, bcol.HEADER_ID
				, sysdate	--LAST_UPDATE_DATE
				, bcol.LAST_UPDATED_BY
				, sysdate	--CREATION_DATE
				, bcol.CREATED_BY
				, bcol.LAST_UPDATE_LOGIN
				, bcol.REQUEST_ID
				, bcol.PROGRAM_APPLICATION_ID
				, 99		-- matched item on closed line
				, bcol.PROGRAM_UPDATE_DATE
				, bcol.OPTION_SPECIFIC
				, 'N'	--bcol.REUSE_CONFIG
				, bcol.QTY_PER_PARENT_MODEL
				, 'UPG'		--STATUS
				, nvl(msi.config_orgs, '1')
				from bom_ato_configurations bac
				, bom_cto_order_lines bcol
				, mtl_system_items msi
				where bac.config_item_id = p_config_id
				and NOT EXISTS
					(select 'exists'
					from bom_cto_order_lines_upg bcolu
					where bcolu.config_item_id = bac.config_item_id)
				-- select first ato_line_id in bcol
				and bcol.ato_line_id =
					(select bcol1.ato_line_id
					from bom_cto_order_lines bcol1
					where bcol1.config_item_id = bac.config_item_id
					-- pick up only if config is at top level
					and bcol1.line_id = bcol1.ato_line_id
					and rownum = 1)
				-- to get item attribute
				and msi.inventory_item_id = bcol.inventory_item_id
				and msi.organization_id = bcol.ship_from_org_id;
Line: 2783

				WriteToLog('Rows inserted::'|| to_char(sql%rowcount), 3);
Line: 2803

			select 'Y'
			into l_exists
			from bom_cto_order_lines_upg
			where config_item_id = p_config_id
			and rownum = 1;
Line: 2870

select
bom_cto_order_lines_s1.nextval,		-- line_id
substr(bac.component_code, (instr(bac.component_code, '-', -1)+1)),	-- inventory_item_id
bac.component_item_id,			-- header_id::storing comp_item_id here for intermediate processing
bac.component_code,			-- component_code
msi.bom_item_type,			-- bom_item_type
msi.primary_uom_code,			-- order_quantity_uom
bac.component_quantity,			-- ordered_quantity
bac.component_quantity,			-- per_quantity
sysdate,				-- schedule_ship_date
'N' , -- option_specific BUGFIX 3602292 defaulted this value to N as model will not have option_specific_sourced flag.
nvl(msi.config_orgs, '1'),		-- config_orgs
sysdate,				-- creation_date
nvl(Fnd_Global.USER_ID, -1),		-- created_by
sysdate,				-- last_update_date
nvl(Fnd_Global.USER_ID, -1),		-- last_updated_by
cto_update_configs_pk.bac_program_id,	-- program_id
'Y',					-- perform_match  /* Sushant made changes to identify matched items */
'N',					-- reuse_config
bac.organization_id
from bom_ato_configurations bac,
mtl_system_items msi
where bac.config_item_id = p_config_id
-- and bac.component_item_id <> bac.base_model_id -- not pick up top model
and msi.inventory_item_id = substr(bac.component_code, (instr(bac.component_code, '-', -1)+1))	-- bac.component_item_id
and msi.organization_id = bac.organization_id;
Line: 2915

	select base_model_id
	into l_base_model_id
	from bom_ato_configurations
	where config_item_id = p_config_id
	and rownum = 1;
Line: 2953

		t_bcol(l_index).last_update_date,
		t_bcol(l_index).last_updated_by,
		t_bcol(l_index).program_id,
		t_bcol(l_index).perform_match,
		t_bcol(l_index).reuse_config,
                t_bcol(l_index).ship_from_org_id;
Line: 3001

	select bom_cto_order_lines_s1.nextval
	into l_header_id
	from dual;
Line: 3065

	-- insert into bcol
	l_stmt_num := 120;
Line: 3071

		INSERT INTO bom_cto_order_lines_upg(
                     HEADER_ID ,
                     LINE_ID ,
                     LINK_TO_LINE_ID ,
                     ATO_LINE_ID ,
                     PARENT_ATO_LINE_ID ,
                     TOP_MODEL_LINE_ID ,
                     PLAN_LEVEL ,
                     WIP_SUPPLY_TYPE ,
                     PERFORM_MATCH ,
                     BOM_ITEM_TYPE ,
                     COMPONENT_CODE ,
                     COMPONENT_SEQUENCE_ID ,
                     CONFIG_ITEM_ID ,
                     INVENTORY_ITEM_ID ,
                     ITEM_TYPE_CODE ,
                     BATCH_ID ,
                     ORDERED_QUANTITY ,
                     ORDER_QUANTITY_UOM ,
                     SCHEDULE_SHIP_DATE ,
                     SHIP_FROM_ORG_ID ,
                     LAST_UPDATE_DATE ,
                     LAST_UPDATED_BY ,
                     CREATION_DATE ,
                     CREATED_BY ,
                     LAST_UPDATE_LOGIN ,
                     REQUEST_ID ,
                     PROGRAM_APPLICATION_ID ,
                     PROGRAM_ID ,
                     PROGRAM_UPDATE_DATE ,
                     QTY_PER_PARENT_MODEL,
                     OPTION_SPECIFIC,
                     REUSE_CONFIG,
		     STATUS,
		     SEQUENCE,
		     CONFIG_CREATION
		     )
		VALUES (
		     t_bcol(i).header_id,
                     t_bcol(i).line_id,
                     t_bcol(i).link_to_line_id,
                     t_bcol(i).ato_line_id,
                     t_bcol(i).parent_ato_line_id,
                     t_bcol(i).top_model_line_id,
                     t_bcol(i).plan_level,
                     t_bcol(i).wip_supply_type,
                     'Y',	-- perform_match BUGFIX 3567693
                     t_bcol(i).bom_item_type,
                     t_bcol(i).component_code,
                     t_bcol(i).component_sequence_id,
                     t_bcol(i).config_item_id,
                     t_bcol(i).inventory_item_id,
                     decode(t_bcol(i).line_id, t_bcol(i).ato_line_id, 'MODEL', decode(t_bcol(i).bom_item_type, '4', 'OPTION', 'CLASS')),
                     null,	-- batch_id
                     t_bcol(i).ordered_quantity,
                     t_bcol(i).order_quantity_uom,
                     t_bcol(i).schedule_ship_date,
                     t_bcol(i).ship_from_org_id,
                     t_bcol(i).last_update_date,
                     t_bcol(i).last_updated_by,
                     t_bcol(i).creation_date,
                     t_bcol(i).created_by,
                     t_bcol(i).last_update_login,
                     null,	-- request_id
                     null,	-- program_application_id
                     t_bcol(i).program_id,
                     null,	-- program_update_date
                     t_bcol(i).qty_per_parent_model,
                     t_bcol(i).option_specific,
                     'N',
		     'UPG',
		     null,
		     t_bcol(i).config_creation
		     );
Line: 3146

	WriteToLog('populate_bcolu_from_bac: Inserted ' || t_bcol(i).line_id);
Line: 3180

select
bom_cto_order_lines_s1.nextval,		-- line_id
substr(bac.component_code, (instr(bac.component_code, '-', -1)+1)),	-- inventory_item_id
bac.component_item_id,			-- header_id::storing comp_item_id here for intermediate processing
substr(bac.component_code, (instr(bac.component_code, '-', 1)+1)),	-- component_code
--bac.config_item_id,			-- config_item_id
msi.bom_item_type,			-- bom_item_type
msi.primary_uom_code,			-- order_quantity_uom
bac.component_quantity,			-- ordered_quantity
bac.component_quantity,			-- per_quantity
sysdate,				-- schedule_ship_date
nvl(to_char(msi.option_specific_sourced),'N'),		-- option_specific --bugfix3845686
nvl(msi.config_orgs, '1'),		-- config_orgs
sysdate,				-- creation_date
nvl(Fnd_Global.USER_ID, -1),		-- created_by
sysdate,				-- last_update_date
nvl(Fnd_Global.USER_ID, -1),		-- last_updated_by
cto_update_configs_pk.bac_program_id	-- program_id
from bom_ato_configurations bac,
mtl_system_items msi
where bac.config_item_id = l_curr_config_id
and bac.component_item_id <> bac.base_model_id --not pick up top model
and msi.inventory_item_id = bac.component_item_id
and msi.organization_id = bac.organization_id;
Line: 3235

	select nvl(msi.config_orgs, '1'), inventory_item_id
	into l_item_attr, l_child_model_id
	from mtl_system_items msi
	where msi.inventory_item_id = (select base_item_id --bugfix3845686
	                               from mtl_system_items
				       where inventory_item_id = t_bcol(l_parent_index).header_id
				       and rownum =1)
	--and msi.organization_id = t_bcol(l_parent_index).ship_from_org_id;
Line: 3252

		select substrb(concatenated_segments,1,50) name
		into l_child_model_name
		from mtl_system_items_kfv msi
		where msi.inventory_item_id = l_child_model_id
		and rownum=1;/* Fixed bug 3529482 */
Line: 3293

				t_bcol(l_index).last_update_date,
				t_bcol(l_index).last_updated_by,
				t_bcol(l_index).program_id;
Line: 3433

			v_raw_line_id.delete;
Line: 3473

                                select
				bic.wip_supply_type,
				bic.component_sequence_id
				into p_t_bcol(v_item).wip_supply_type,
				p_t_bcol(v_item).component_sequence_id
				from bom_bill_of_materials bbom,
				bom_inventory_components bic
				where bbom.bill_sequence_id =
					(select common_bill_sequence_id
					from bom_bill_of_materials
					where assembly_item_id = p_t_bcol(v_parent_item).inventory_item_id
					and alternate_bom_designator is null
					and rownum = 1)
				and bbom.common_bill_sequence_id = bic.bill_sequence_id
				and bic.component_item_id = p_t_bcol(v_item).inventory_item_id
				and rownum = 1;
Line: 3558

			v_raw_line_id.delete;
Line: 3587

	p_t_bcol.delete;
Line: 3621

select distinct substrb(concatenated_segments,1,50) name,msi.inventory_item_id
item_id
from bom_cto_order_lines_upg bcolu,
mtl_system_items_kfv msi
where bcolu.config_item_id is not null
and bcolu.config_item_id = msi.inventory_item_id
and bcolu.ship_from_org_id = msi.organization_id
and ((bcolu.config_creation = '3'
	and exists (select 'exists'
		from bom_cto_order_lines_upg bcolu1
		where bcolu1.config_item_id = bcolu.config_item_id
		and bcolu1.status = 'MRP_SRC'
		and rownum = 1))
or (bcolu.config_creation <> '3'
	and not exists (select 'exists'
		from bom_cto_order_lines_upg bcolu1
		where bcolu1.config_item_id = bcolu.config_item_id
		and bcolu1.status <> 'MRP_SRC')))
order by 1;  -- Modified by Renga for bug 3930047
Line: 3646

select distinct substrb(concatenated_segments,1,50) name,
                 msi.inventory_item_id item_id
from bom_cto_order_lines_upg bcolu,
mtl_system_items_kfv msi
where bcolu.config_item_id is not null
and bcolu.config_item_id = msi.inventory_item_id
and bcolu.ship_from_org_id = msi.organization_id
and not exists (select 'exists'
		from bom_cto_order_lines_upg bcolu1
		where bcolu1.config_item_id = bcolu.config_item_id
		and bcolu1.status = 'MRP_SRC')
order by 1;  -- Modified by Renga for bug 3930047
Line: 3665

select distinct substrb(concatenated_segments,1,50) name,
        msi.inventory_item_id item_id,
	oeh.order_number,
	decode(bcolu.status, 'MRP_SRC', 'was successfully processed', 'errored out') status
from bom_cto_order_lines_upg bcolu,
mtl_system_items_kfv msi,
oe_order_lines_all oel,
oe_order_headers_all oeh
where bcolu.config_item_id is not null
and bcolu.config_item_id = msi.inventory_item_id
and bcolu.ship_from_org_id = msi.organization_id
and config_creation <> '3'
and exists (select 'exists'
	from bom_cto_order_lines_upg bcolu1
	where bcolu1.config_item_id = bcolu.config_item_id
	and bcolu1.status = 'MRP_SRC')
and exists (select 'exists'
	from bom_cto_order_lines_upg bcolu1
	where bcolu1.config_item_id = bcolu.config_item_id
	and bcolu1.status <> 'MRP_SRC')
and oel.line_id = bcolu.ato_line_id
and oel.header_id = oeh.header_id
order by name, status;
Line: 3752

SELECT bom_item_type,
       wip_supply_type,
       config_creation,
       config_item_id,
       inventory_item_id,
       parent_ato_line_id,
       ato_line_id,
       line_id,
       ship_from_org_id
FROM   bom_cto_order_lines_upg
WHERE ato_line_id in ( SELECT DISTINCT bupg1.ato_line_id
                       FROM  bom_cto_order_lines_upg bupg1
		       WHERE bupg1.config_creation = 3);
Line: 3877

  UPDATE bom_cto_order_lines_upg
  SET status  = 'ERROR'
  WHERE ato_line_id = t_ato_line_id(j);
Line: 3882

  oe_debug_pub.add('Updated '||sql%rowcount||'lines with error status',1);
Line: 3890

	WriteToLog('ERROR: Unexp error in CTO_Update_Configs_Pk.Check_invalid_configurations:: '|| l_stmt_num ||'::'||sqlerrm, 1);
Line: 3892

	WriteToLog('Update Existing Configurations completed with ERROR');
Line: 3903

Procedure update_atp_attributes(
                          p_item          IN  Number,
                          p_cat_id        IN  Number,
                          p_config_id     IN  Number,
                          x_return_status OUT NOCOPY varchar2,
                          x_msg_data      OUT NOCOPY Varchar2,
                          x_msg_count     OUT NOCOPY Number) is
Begin
   WriteToLog('   Entering Update_atp_attributes procedure');
Line: 3916

      update mtl_system_items_b msic
      set    (atp_components_flag,atp_flag) = (select CTO_CONFIG_ITEM_PK.evaluate_atp_attributes(nvl(msim.atp_flag,'N'),nvl(msim.atp_components_flag,'N')),CTO_CONFIG_ITEM_PK.get_atp_flag
                                         from   mtl_system_items_b msim
                                         where  msim.inventory_item_id = msic.base_item_id
				          and    msim.organization_id   = msic.organization_id)

      where msic.base_item_id is not null
      and   'x'= (select 'x'
              from mtl_system_items_b msim1
              where msim1.inventory_item_id = msic.base_item_id
              and   msim1.organization_id   = msic.organization_id);
Line: 3930

      WriteToLog(' Number of records updated = '||sql%rowcount);
Line: 3934

      update mtl_system_items_b msic
      set    (atp_components_flag,atp_flag) = (select CTO_CONFIG_ITEM_PK.evaluate_atp_attributes(nvl(msim.atp_flag,'N'),nvl(msim.atp_components_flag,'N')),CTO_CONFIG_ITEM_PK.get_atp_flag
                                        from   mtl_system_items_b msim
                                        where  msim.inventory_item_id = msic.base_item_id
				        and    msim.organization_id   = msic.organization_id)
      where msic.inventory_item_id in (select msi.inventory_item_id
                                       from mtl_system_items_b msi,
				            mtl_item_categories mcat
				       where msi.base_item_id = mcat.inventory_item_id
				       and   mcat.category_id = p_cat_id)
     and exists (select 'x' from mtl_system_items_b msim
                 where  msim.inventory_item_id = msic.base_item_id
                 and    msim.organization_id   = msic.organization_id);
Line: 3948

      WriteToLog(' Number of records updated = '||sql%rowcount);
Line: 3952

     update mtl_system_items_b msic
     set    (atp_components_flag,atp_flag)  = (select CTO_CONFIG_ITEM_PK.evaluate_atp_attributes(msim.atp_flag,msim.atp_components_flag),CTO_CONFIG_ITEM_PK.get_atp_flag
                                        from   mtl_system_items_b msim
                                        where  msim.inventory_item_id = msic.base_item_id
				        and    msim.organization_id   = msic.organization_id)
     where  msic.inventory_item_id = p_config_id
     and    exists (select 'x' from mtl_system_items_b msim
                    where  msim.inventory_item_id = msic.base_item_id
                    and    msim.organization_id   = msic.organization_id);
Line: 3961

      WriteToLog(' Number of records updated = '||sql%rowcount);
Line: 3964

End Update_atp_attributes;