DBA Data[Home] [Help]

APPS.MSD_APPLY_TEMPLATE_DEMAND_PLAN SQL Statements

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

Line: 36

Procedure	Update_Formula_Names(p_new_dp_id in	number);
Line: 44

Procedure	Parse_Dimension_Select_List(p_new_dp_id	in number);
Line: 52

Procedure	update_ascp_related_data(p_new_dp_id in	number);
Line: 64

Procedure	validate_doc_dim_selections(p_new_dp_id	in number);
Line: 88

Procedure	update_parameter_dates(p_demand_plan_id number);
Line: 302

select demand_plan_id

from msd_demand_plans

where	plan_type	=	p_plan_type

and	template_flag	=	'Y'

and	default_template = 'Y';
Line: 364

		-- Update	the	Liability	Specific Columns

		update msd_demand_plans

		set	plan_start_date	=	p_plan_start_date,

		plan_end_date	=	p_plan_end_date,

		liab_plan_id = p_supply_plan_id,

		liab_plan_name = p_supply_plan_name

		where	demand_plan_id = p_new_dp_id;
Line: 380

		-- Update	Dates	of the input parameters

		-- set the start date	and	end	date	for	input	parameters having	time data

		update msd_dp_parameters

		set	start_date = p_plan_start_date,

		end_date = p_plan_end_date

		where	demand_plan_id = p_new_dp_id

		and	forecast_date_used is	not	null

		and	deleteable_flag	=	'N';
Line: 402

		update msd_dp_parameters

		set	parameter_name = p_supply_plan_name

		where	demand_plan_id = p_new_dp_id;
Line: 410

					-- set the supply	plan name	to supply	plan name	for	doc	dim	selection

		update msd_dp_doc_dim_selections

		set	supply_plan_name = p_supply_plan_name

		where	demand_plan_id = p_new_dp_id

		and	selection_type = 'I';
Line: 424

		update msd_dp_formula_parameters

		set	supply_plan_name = p_supply_plan_name

		where	demand_plan_id = p_new_dp_id

		and	parameter_type = 'I';
Line: 446

				update msd_dp_formulas mdf

				set	upload_formula_id	=	(select	formula_id from	msd_dp_formulas	mdf1

				where	mdf1.demand_plan_id	=	p_new_dp_id

				and	mdf1.formula_name	=	mdf.upload_formula_id)

				where	demand_plan_id = p_new_dp_id

				and	upload_formula_id	is not null;
Line: 508

Calls	refresh_document_dimensions, refresh_formulas, Parse_Dimension_Select_List,

Replace_formula_tokens,	Replace_dimension_tokens,	Validate_formula_parameters,

validate_formulas, validate_doc_dim_selections,	validate_doc_dimensions

and	validate_documents

********************************************************/



Procedure	create_seeded_definitions(p_demand_plan_id in	number,

p_errcode	in out nocopy	varchar2

)



is

cursor get_template_id is
select template_id
from msd_demand_plans
where demand_plan_id=p_demand_plan_id;
Line: 559

	-- parse the selection script	for	dimensions with	selection	type as	list

	-- Parse_Dimension_Select_List(p_demand_plan_id);	 commented out as	only one set of	ascp specific	measures needs to	be added to	a	doc
Line: 589

	-- validate	dimension	selections

	validate_doc_dim_selections(p_demand_plan_id);
Line: 643

select template_id

from msd_demand_plans

where	demand_plan_id = p_demand_plan_id;
Line: 653

select document_name,document_id

from msd_dp_seeded_documents

where	demand_plan_id = p_demand_plan_id;
Line: 663

select document_id

from msd_dp_seeded_documents

where	demand_plan_id = p_template_id

and	document_name	=	p_document_name;
Line: 675

select dimension_code

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_demand_plan_id

and	document_id	=	p_document_id;
Line: 687

select selection_script

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_template_id

and	document_id	=	p_document_id

and	dimension_code = p_dimension_code;
Line: 701

l_selection_script varchar2(4000);
Line: 706

select document_id
from msd_dp_seeded_documents
where demand_plan_id=p_demand_plan_id
and document_name = 'MSD_SD_EOL_LWF';
Line: 753

			-- get the selection script	for	the	corresponding	dimension	in template

			open c5(l_template_id, l_document_id,	c4_cur.dimension_code);
Line: 757

			fetch	c5 into	l_selection_script;
Line: 763

			-- update	the	selection	script for the dimension in	the	plan with	the	selection	script for the corresponding dimension in	template

			if c2_cur.document_id=waterfall_doc_id and  c4_cur.dimension_code = 'MEAS' then
					null;
Line: 769

					update msd_dp_seeded_doc_dimensions
					set	selection_script = l_selection_script
					where	demand_plan_id = p_demand_plan_id
					and	document_id	=	c2_cur.document_id
					and	dimension_code = c4_cur.dimension_code;
Line: 809

select template_id

from msd_demand_plans

where	demand_plan_id = p_demand_plan_id;
Line: 819

select formula_name,formula_id

from msd_dp_formulas

where	demand_plan_id = p_demand_plan_id;
Line: 829

select equation, custom_field1,	custom_field2, isby, numerator,	denominator

from msd_dp_formulas

where	demand_plan_id = p_template_id

and	formula_name = p_formula_name;
Line: 881

			-- update	equation,	custom_field1, isby, numerator and denominator for the formula in	plan with	the	corresponding	formula	in template

			update msd_dp_formulas

			set	equation = l_equation,

			custom_field1	=	l_custom_field1,

			custom_field2	=	l_custom_field2,

			isby = l_isby,

			numerator	=	l_numerator,

			denominator	=	l_denominator

			where	demand_plan_id = p_demand_plan_id

			and	formula_name = c2_cur.formula_name;
Line: 929

select scenario_id,	scenario_name, description

from msd_dp_scenarios_cs_v

where	demand_plan_id = p_new_dp_id;
Line: 943

		update msd_demand_plans

		set	template_flag	=	'N',

		default_template = 'N'

		where	demand_plan_id = p_new_dp_id;
Line: 963

			update msd_dp_scenarios

			set	scenario_name	=	fnd_message.get

			where	demand_plan_id = p_new_dp_id

			and	scenario_id	=	c1_cur.scenario_id;
Line: 977

			update msd_dp_scenarios

			set	description	=	fnd_message.get

			where	demand_plan_id = p_new_dp_id

			and	scenario_id	=	c1_cur.scenario_id;
Line: 991

			update msd_dp_scenarios_tl

			set	description	=	fnd_message.get

			where	demand_plan_id = p_new_dp_id

			and	scenario_id	=	c1_cur.scenario_id;
Line: 1020

select parameter_id
from msd_dp_parameters
where demand_plan_id=p_demand_plan_id
and stream_type='CALCULATED';
Line: 1026

select parameter_sequence,parameter_type,parameter_component,parameter_value,supply_plan_name
from msd_dp_formula_parameters
where demand_plan_id=p_demand_plan_id
and formula_id=p_parameter_id
order by parameter_sequence;
Line: 1033

select parameter_type,parameter_id
from msd_dp_parameters
where demand_plan_id=p_demand_plan_id;
Line: 1038

select parameter_id
from msd_dp_parameters
where demand_plan_id=p_demand_plan_id
and post_calculation is not null;
Line: 1057

		update msd_dp_parameters
		set equation = 	replace(equation,'%'||c2_rec.parameter_sequence||'%', l_parameter_value)
		where	demand_plan_id = p_demand_plan_id
		and	parameter_id = c1_rec.parameter_id;
Line: 1069

				update msd_dp_parameters
				set post_calculation=replace(post_calculation,c3_rec.parameter_type,c3_rec.parameter_id)
				where demand_plan_id=p_demand_plan_id
				and parameter_id=c4_rec.parameter_id;
Line: 1093

Procedure	update_parameter_dates(p_demand_plan_id number)
is

cursor c1 is
select plan_type
from msd_demand_plans
where demand_plan_id=p_demand_plan_id;
Line: 1110

				update msd_dp_parameters
				set start_date=msd_common_utilities.get_bucket_start_date(sysdate,1,6,'GREGORIAN'),
				end_date=msd_common_utilities.get_bucket_end_date(sysdate,1,6,'GREGORIAN')
				where parameter_type in ('MSD_ON_HAND')
				and demand_plan_id=p_demand_plan_id;
Line: 1116

				update msd_dp_parameters
				set start_date=msd_common_utilities.get_bucket_start_date(sysdate,1,6,'GREGORIAN'),
				end_date=msd_common_utilities.get_bucket_end_date(sysdate,24,6,'GREGORIAN')
				where parameter_type in ('MSD_GROSS_REQ_EXCESS_HORIZON','MSD_INTRANSIT','MSD_ONORDER',
														'MSD_GROSS_REQ_OBS_DATE','MSD_TOTAL_SUPPLY','MSD_ORDER_FORECAST',
														'MSD_FORECAST_BASIS_LIAB','MSD_AUTHORIZATION','MSD_SUPPLY_COMMIT',
														'MSD_SHORTAGE','MSD_FORECAST_LIABILITY','MSD_ESTIMATED_FORECAST_LIAB',
														'MSD_SIM_END_ITEM_DEMAND','MSD_ESTIMATED_GROSS_REQ')
				and demand_plan_id=p_demand_plan_id;
Line: 1129

end update_parameter_dates;
Line: 1149

select plan_type

from msd_demand_plans

where	demand_plan_id = p_new_dp_id;
Line: 1179

			-- insert	ASCP specific	data
			update_ascp_related_data(p_new_dp_id);
Line: 1188

			-- Update the start and end dates for the parameters
			update_parameter_dates(p_new_dp_id);
Line: 1191

			/*update msd_dp_parameters set allo_agg_basis_stream_id = (select parameter_id
																															 from msd_dp_parameters
																															 where demand_plan_id=p_new_dp_id
																															 and parameter_type='MSD_FORECAST_BASIS_LIAB')
			where demand_plan_id=p_new_dp_id
			and parameter_type='MSD_SIM_END_ITEM_DEMAND';			*/
Line: 1199

			update msd_dp_parameters
			set dependent_demand_desc = fnd_message.get
			where demand_plan_id=p_new_dp_id
			and parameter_type='MSD_SIM_END_ITEM_DEMAND';
Line: 1219

select parameter_id
from msd_dp_parameters
where demand_plan_id=p_new_dp_id
and parameter_type=p_parameter_type;
Line: 1225

select scenario_id
from msd_dp_scenarios
where demand_plan_id=p_new_dp_id;
Line: 1230

select associate_parameter
from msd_dp_scenarios
where demand_plan_id=p_new_dp_id
and scenario_id=p_scenario_id;
Line: 1254

		update msd_dp_scenarios
		set associate_parameter=p_parameter_id
		where demand_plan_id=p_new_dp_id
		and scenario_id=c2_rec.scenario_id;
Line: 1284

select plan_type

from msd_demand_plans

where	demand_plan_id = p_new_dp_id;
Line: 1320

	update msd_dp_parameters

	set	start_date = msd_common_utilities.get_bucket_start_date(sysdate,-18,6,'GREGORIAN'),

	end_date = msd_common_utilities.get_bucket_end_date(sysdate,1,6,'GREGORIAN')

	where	demand_plan_id = p_new_dp_id

	and	(supply_plan_flag	<> 'Y'

	or supply_plan_flag	is null);
Line: 1338

	update msd_dp_scenarios

	set	history_start_date = msd_common_utilities.get_bucket_start_date(sysdate,-18,6,'GREGORIAN'),

	history_end_date = msd_common_utilities.get_bucket_end_date(sysdate,1,6,'GREGORIAN'),

	horizon_start_date = msd_common_utilities.get_bucket_start_date(sysdate,2,6,'GREGORIAN'),

	horizon_end_date = msd_common_utilities.get_bucket_end_date(sysdate,19,6,'GREGORIAN')

	where	demand_plan_id = p_new_dp_id;
Line: 1352

	-- insert	ASCP specific	data

	update_ascp_related_data(p_new_dp_id);
Line: 1384

select liab_plan_name, plan_type,	organization_id, sr_instance_id

from msd_demand_plans

where	demand_plan_id = p_new_dp_id;
Line: 1424

		 --	insert default manufacturing calendar	for	PDS	base liability plans

	if l_org_id	<> -1	then



	insert into	msd_dp_calendars

	(

	DEMAND_PLAN_ID

	,CALENDAR_TYPE

	,CALENDAR_CODE

	,CREATION_DATE

	,CREATED_BY

	,LAST_UPDATE_DATE

	,LAST_UPDATED_BY

	,LAST_UPDATE_LOGIN

	,REQUEST_ID

	,PROGRAM_APPLICATION_ID

	,PROGRAM_ID

	,PROGRAM_UPDATE_DATE

	,DELETEABLE_FLAG

	,ENABLE_NONSEED_FLAG

	)

	values

	(

	p_new_dp_id

	,2

	,MSD_COMMON_UTILITIES_LB.get_default_mfg_cal ( l_org_id,l_instance_id)

	,SYSDATE

	,fnd_global.user_id

	,SYSDATE

	,fnd_global.user_id

	,fnd_global.login_id

	,NULL

	,NULL

	,NULL

	,SYSDATE

	,null

	,'Y'

	);
Line: 1502

	update msd_demand_plans

	set	m_min_tim_lvl_id = 1

	where	demand_plan_id = p_new_dp_id;
Line: 1526

Calls	Update_Formula_Names.

********************************************************/



Procedure	common_all_post_process(p_new_dp_id	in number)

is



cursor c2	is

select parameter_id, price_list_name

from msd_dp_parameters

where	demand_plan_id = p_new_dp_id

and	price_list_name	is not null;
Line: 1552

select scenario_id,	price_list_name

from msd_dp_scenarios

where	demand_plan_id = p_new_dp_id

and	price_list_name	is not null;
Line: 1564

select dp_price_list_id, price_list_name

from msd_dp_price_lists

where	demand_plan_id = p_new_dp_id;
Line: 1584

		update msd_dp_parameters

		set	price_list_name	=	fnd_message.get_string('MSD',c2_cur.price_list_name)

		where	demand_plan_id = p_new_dp_id

		and	parameter_id = c2_cur.parameter_id;
Line: 1606

		update msd_dp_scenarios

		set	price_list_name	=	fnd_message.get_string('MSD',c3_cur.price_list_name)

		where	demand_plan_id = p_new_dp_id

		and	scenario_id	=	c3_cur.scenario_id;
Line: 1628

		update msd_dp_price_lists

		set	price_list_name	=	fnd_message.get_string('MSD',c4_cur.price_list_name)

		where	demand_plan_id = p_new_dp_id

		and	dp_price_list_id = c4_cur.dp_price_list_id;
Line: 1646

		Update_Formula_Names(p_new_dp_id);
Line: 1666

Procedure	Update_Formula_Names(p_new_dp_id in	number)

is



cursor c1	is

select formula_name, formula_desc, formula_id

from msd_dp_formulas

where	demand_plan_id = p_new_dp_id

order	by creation_sequence;
Line: 1686

select document_id,	description

from msd_dp_seeded_documents

where	demand_plan_id = p_new_dp_id;
Line: 1708

		-- update	the	description	seeded as	message	with message text

		update msd_dp_formulas

		--set	formula_desc = fnd_message.get

		set	formula_desc = fnd_message.get_string('MSD',c1_cur.formula_desc)

		where	formula_id = c1_cur.formula_id

		and	demand_plan_id = p_new_dp_id;
Line: 1734

		-- update	the	description	seeded as	message	with message text

		update msd_dp_seeded_documents

		--set	description	=	fnd_message.get

		set	description	=	fnd_message.get_string('MSD',c2_cur.description)

		where	document_id	=	c2_cur.document_id

		and	demand_plan_id = p_new_dp_id;
Line: 1756

END	Update_Formula_Names;
Line: 1778

select formula_id

from msd_dp_formulas

where	demand_plan_id = p_new_dp_id

order	by creation_sequence;
Line: 1790

select where_used, parameter_sequence, parameter_type, parameter_component,	parameter_value, supply_plan_name

from msd_dp_formula_parameters

where	demand_plan_id = p_new_dp_id

and	formula_id = p_formula_id

and	enabled_flag = 'Y'

order	by parameter_sequence;
Line: 1846

			-- update	the	names	with IDS

			update msd_dp_formulas

			set	custom_field1	=	replace(custom_field1,'%'||c2_cur.parameter_sequence||'%', l_parameter_value),

			custom_field2	=	replace(custom_field2,'%'||c2_cur.parameter_sequence||'%', l_parameter_value),

			equation = replace(equation,'%'||c2_cur.parameter_sequence||'%', l_parameter_value)

			where	demand_plan_id = p_new_dp_id

			and	formula_id = c1_cur.formula_id;
Line: 1882

This Procedure parses	the	select list	for	dimensions with	selection	type as	List.	e.g. measures	.

The	list contains	values seperated by	'\n'

Called by	create_seeded_definitions

NO MORE	USED

********************************************************/



Procedure	Parse_Dimension_Select_List(p_new_dp_id	in number)

is



cursor c1	is

select document_id,	dimension_code,	selection_sequence

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	(dimension_code, document_id)	in

(select	dimension_code,	document_id	from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_new_dp_id

and	selection_type = 'L')

order	by document_id,dimension_code,selection_sequence;
Line: 1930

		update msd_dp_seeded_doc_dimensions

		set	selection_script = ''

		where	demand_plan_id = p_new_dp_id

		and	selection_type = 'L';
Line: 1944

		update msd_dp_seeded_doc_dimensions

		set	selection_script = selection_script||'%'||c1_cur.selection_sequence||'%\n'

		where	demand_plan_id = p_new_dp_id

		and	document_id	=	c1_cur.document_id

		and	dimension_code = c1_cur.dimension_code

		and	selection_type = 'L';
Line: 1970

END	Parse_Dimension_Select_List;
Line: 1976

This Procedure replaces	the	tokens in	selection	script with	values of	document selections.

Called by	create_seeded_definitions.

********************************************************/



Procedure	Replace_dimension_tokens(p_new_dp_id in	number)

is



cursor c1	is

select document_id,	dimension_code

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_new_dp_id

order	by sequence_number;
Line: 2004

select selection_sequence, selection_type, selection_component,	selection_value, supply_plan_name

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	document_id	=	p_document_id

and	dimension_code = p_dimension_code

and	enabled_flag = 'Y'

order	by selection_sequence;
Line: 2020

l_selection_value	varchar2(4000);
Line: 2052

			if c2_cur.selection_type = 'I' then

				l_parameter_id :=	get_parameter_id(p_new_dp_id,c2_cur.selection_value, c2_cur.supply_plan_name,	c2_cur.selection_component);
Line: 2058

					l_selection_value	:= 'V.'||c2_cur.selection_component||l_parameter_id;
Line: 2062

					l_selection_value	:= null;
Line: 2066

			elsif	c2_cur.selection_type	=	'F'	then

				l_formula_id :=	get_formula_id(p_new_dp_id,c2_cur.selection_value, c2_cur.supply_plan_name);
Line: 2072

					l_selection_value	:= 'SYSF'||l_formula_id;
Line: 2076

					l_selection_value	:= null;
Line: 2080

			elsif	c2_cur.selection_type	=	'H'	then

				l_hierarchy_id :=	get_hierarchy_id(p_new_dp_id,c2_cur.selection_value);
Line: 2086

					l_selection_value	:= 'H'||c2_cur.selection_value;
Line: 2090

					l_selection_value	:= null;
Line: 2094

			elsif	c2_cur.selection_type	=	'L'	then

				l_level_id :=	get_level_id(p_new_dp_id,c2_cur.selection_value);
Line: 2100

					l_selection_value	:= 'L'||c2_cur.selection_value;
Line: 2104

					l_selection_value	:= null;
Line: 2108

			elsif	c2_cur.selection_type	=	'D'	then

				l_dimension_code :=	get_dimension_code(p_new_dp_id,c2_cur.selection_value);
Line: 2112

				l_selection_value	:= l_dimension_code;
Line: 2114

			elsif	c2_cur.selection_type	=	'DS' then

				l_dimension_script :=	get_dimension_script(p_new_dp_id,c2_cur.selection_component, c2_cur.selection_value);
Line: 2118

				l_selection_value	:= l_dimension_script;
Line: 2122

				l_selection_value	:= c2_cur.selection_value;
Line: 2128

			update msd_dp_seeded_doc_dimensions

			set	selection_script = replace(selection_script,'%'||c2_cur.selection_sequence||'%', l_selection_value)

			where	demand_plan_id = p_new_dp_id

			and	document_id	=	c1_cur.document_id

			and	dimension_code = c1_cur.dimension_code;
Line: 2142

		/*update msd_dp_seeded_doc_dimensions
		set enabled_flag = decode(nvl(selection_script,'NOT_POSS'), 'NOT_POSS', 'N', enabled_flag)
		where document_id	=	c1_cur.document_id
  	and	dimension_code = c1_cur.dimension_code
  	and demand_plan_id=p_new_dp_id
  	and dimension_code = 'MEAS';*/
Line: 2170

Procedure	update_ascp_related_data(p_new_dp_id in	number)

is



cursor c1	is

select demand_plan_name

from msd_demand_plans

where	demand_plan_id = p_new_dp_id;
Line: 2188

select distinct	supply_plan_id,	supply_plan_name									-- Bug 4729854

from msd_dp_supply_plans

where	demand_plan_name	=	p_demand_plan_name;
Line: 2198

select count(*)

from msd_dp_supply_plans

where	demand_plan_name	=	p_demand_plan_name;
Line: 2212

select plan_type
from msd_demand_plans
where demand_plan_id=p_new_dp_id;
Line: 2241

			select max(supply_plan_id) into l_liab_plan_id from msd_dp_supply_plans where demand_plan_name	=	l_demand_plan_name;
Line: 2242

			update msd_demand_plans set liab_plan_id=l_liab_plan_id where demand_plan_id=p_new_dp_id;
Line: 2245

	-- for each	suuply plan	selected in	Template window

	for	c2_cur in	c2(l_demand_plan_name) loop



		if p_plan_type='EOL' then
				add_ascp_scenario_for_eol(p_new_dp_id, c2_cur.supply_plan_id,	c2_cur.supply_plan_name);
Line: 2294

		-- delete	data as	not	required after this

		delete from	msd_dp_supply_plans

		where	demand_plan_name = l_demand_plan_name;
Line: 2312

END	update_ascp_related_data;
Line: 2352

select distinct	formula_id

from msd_dp_formula_parameters

where	demand_plan_id = p_new_dp_id

and	mandatory_flag = 'Y'

and	enabled_flag = 'N';
Line: 2370

		update msd_dp_formulas

		set	valid_flag = 'Y'

		where	demand_plan_id = p_new_dp_id;
Line: 2382

		update msd_dp_formulas

		set	valid_flag = 'N'

		where	demand_plan_id = p_new_dp_id

		and	formula_id = c1_cur.formula_id;
Line: 2398

Procedure	validate_doc_dim_selections(p_new_dp_id	in number)

is



cursor c1	is

select plan_type

from msd_demand_plans

where	demand_plan_id = p_new_dp_id;
Line: 2416

select distinct	selection_value, dimension_code

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	selection_type = 'L';
Line: 2428

select distinct	selection_value, dimension_code

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	selection_type = 'H';
Line: 2440

select level_id

from msd_dp_scenario_output_levels

where	demand_plan_id = p_new_dp_id

and	level_id in

(select	level_id from	msd_levels

where	dimension_code = p_dimension_code

and	nvl(plan_type,'DP')	=	decode(p_plan_type,null,'DP','SOP','DP','EOL','DP',p_plan_type))

and	rownum < 2;
Line: 2460

select hierarchy_id

from msd_dp_hierarchies

where	demand_plan_id = p_new_dp_id

and	hierarchy_id in

(select	hierarchy_id from	msd_hierarchies

where	dimension_code = p_dimension_code

and	nvl(plan_type,'DP')	=	decode(p_plan_type,null,'DP','SOP','DP','EOL','DP',p_plan_type))

and	rownum < 2;
Line: 2510

		select count(*)	into l_count

		from msd_levels

		where	level_id = c2_cur.selection_value

		and	nvl(plan_type,'DP')	=	decode(l_plan_type,null,'DP','SOP','DP','EOL','DP',l_plan_type);
Line: 2542

					-- disable the selection

		update msd_dp_doc_dim_selections

					set	enabled_flag = 'N'

		where	demand_plan_id = p_new_dp_id

		and	selection_type = 'L'

		and	selection_value	=	c2_cur.selection_value

		and	dimension_code =	c2_cur.dimension_code;
Line: 2564

		update msd_dp_doc_dim_selections

					set	selection_value	=	l_level_id

		where	demand_plan_id = p_new_dp_id

		and	selection_type = 'L'

		and	selection_value	=	c2_cur.selection_value

			and	dimension_code =	c2_cur.dimension_code;
Line: 2602

		select count(*)	into l_count

		from msd_hierarchies

		where	hierarchy_id = c3_cur.selection_value

		and	nvl(plan_type,'DP')	=	decode(l_plan_type,null,'DP','SOP','DP','EOL','DP',l_plan_type);
Line: 2634

					-- disable the selection

		update msd_dp_doc_dim_selections

					set	enabled_flag = 'N'

		where	demand_plan_id = p_new_dp_id

		and	selection_type = 'H'

		and	selection_value	=	c3_cur.selection_value

		and	dimension_code =	c3_cur.dimension_code;
Line: 2656

		update msd_dp_doc_dim_selections

					set	selection_value	=	l_hierarchy_id

		where	demand_plan_id = p_new_dp_id

		and	selection_type = 'H'

		and	selection_value	=	c3_cur.selection_value

		and	dimension_code =	c3_cur.dimension_code;
Line: 2688

END	validate_doc_dim_selections;
Line: 2694

This Procedure checks	if any of	mandatory	selections for the dimension is	disabled and enables the dimensions.

Called by	create_seeded_definitions.

********************************************************/



Procedure	validate_doc_dimensions(p_new_dp_id	in number)

is



cursor c1	is

select distinct	document_id, dimension_code

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	mandatory_flag = 'Y'

and	enabled_flag = 'N'

and	dimension_code <>	'MEAS'

order	by document_id,	dimension_code;
Line: 2728

select distinct	document_id
from msd_dp_doc_dim_selections mdds,
msd_dp_parameters mdp
where	mdds.demand_plan_id = p_new_dp_id
and mdp.demand_plan_id=p_new_dp_id
and mdp.parameter_type=mdds.selection_value
and nvl(mdp.parameter_name,'ABCD')=nvl(mdds.supply_plan_name,'ABCD')
and	dimension_code = 'MEAS';
Line: 2745

		update msd_dp_seeded_doc_dimensions

		set	enabled_flag = 'Y'

		where	(document_id,	dimension_code)

		in

		/*------Fix	for	bug	4550732--------*/

		(select	document_id, dimension_code	from msd_dp_doc_dim_selections where demand_plan_id=p_new_dp_id)

		and	dimension_code <>	'MEAS';
Line: 2765

		update msd_dp_seeded_doc_dimensions	dpdim

		set	enabled_flag = decode(dpdim.selection_type,	'S', 'Y',	'N')

		where	demand_plan_id = p_new_dp_id

		and	dimension_code = 'MEAS'
		and document_id <> (select document_id from msd_dp_seeded_documents where demand_plan_id=p_new_dp_id and
																								document_name='MSD_EOL_WHEREUSED_RE');
Line: 2781

		-- disable dimensions	except measure which have	any	of the mandatory selection disabled

		update msd_dp_seeded_doc_dimensions

		set	enabled_flag = 'N'

		where	demand_plan_id = p_new_dp_id

		and	document_id	=	c1_cur.document_id

		and	dimension_code = c1_cur.dimension_code;
Line: 2805

		update msd_dp_seeded_doc_dimensions

		set	enabled_flag = 'Y'

		where	demand_plan_id = p_new_dp_id

		and	document_id	=	c2_cur.document_id

		and	dimension_code = 'MEAS';
Line: 2842

select distinct	document_id

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_new_dp_id

and	mandatory_flag = 'Y'

and	enabled_flag = 'N';
Line: 2860

		update msd_dp_seeded_documents

		set	valid_flag = 'Y'

		where	demand_plan_id = p_new_dp_id;
Line: 2874

		update msd_dp_seeded_documents

		set	valid_flag = 'N'

		where	demand_plan_id = p_new_dp_id

		and	document_id	=	c1_cur.document_id;
Line: 2896

Called from	form whenever	user deletes a dimension.

********************************************************/



procedure	remove_dimension(

p_demand_plan_id in	number,

p_dimension_code in	varchar2,

p_dp_dimension_code	in varchar2)



is



BEGIN

savepoint	sp;
Line: 2924

	update msd_dp_seeded_doc_dimensions

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	dimension_code = p_dp_dimension_code;
Line: 2934

	-- disable all dimension selections	which	use	related	hierarchies	and	levels

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	((selection_type = 'H'

	and	selection_value	in

	(select	distinct hierarchy_id	from msd_hierarchies

	where	dimension_code = p_dp_dimension_code))

	or (selection_type = 'L'

	and	selection_value	in

	(select	distinct level_id	from msd_levels

	where	dimension_code = p_dp_dimension_code)));
Line: 2962

	update msd_dp_formula_parameters

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	parameter_type = 'D'

	and	parameter_value	=	p_dp_dimension_code;
Line: 2992

Called from	form whenever	user deletes an	input	parameter.

********************************************************/



procedure	remove_parameter(

p_demand_plan_id in	number,

p_parameter_id in	number)



is



cursor c1	is

select parameter_type, parameter_name

from msd_dp_parameters

where	demand_plan_id = p_demand_plan_id

and	parameter_id = p_parameter_id;
Line: 3036

	-- disable doc dim selections

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	selection_value	=	l_parameter_type

	and	nvl(supply_plan_name,'~!#$%^&*') = nvl(l_parameter_name,'~!#$%^&*')

	and	selection_type = 'I';
Line: 3054

	update msd_dp_formula_parameters

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	parameter_type = 'I'

	and	nvl(supply_plan_name,'~!#$%^&*') = nvl(l_parameter_name,'~!#$%^&*')

	and	parameter_value	=	l_parameter_type;
Line: 3086

Called from	form whenever	user deletes a scenario.

FOR	FUTURE USE

********************************************************/



procedure	remove_scenario(

p_demand_plan_id in	number,

p_scenario_id	in number)



is



cursor c1	is

select supply_plan_name, forecast_based_on,	parameter_name

from msd_dp_scenarios

where	demand_plan_id = p_demand_plan_id

and	scenario_id	=	p_scenario_id;
Line: 3142

	update msd_dp_formula_parameters

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	parameter_component	=	'SN'

	and	parameter_value	=	l_forecast_based_on

	and	nvl(supply_plan_name,'123456789')	=	nvl(l_parameter_name,'123456789');
Line: 3156

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	selection_component	=	'SN'

	and	selection_value	=	l_forecast_based_on

	and	nvl(supply_plan_name,'123456789')	=	nvl(l_parameter_name,'123456789');
Line: 3174

		delete from	msd_dp_parameters

		where	demand_plan_id = p_demand_plan_id

		and	parameter_name = l_supply_plan_name;
Line: 3224

Called from	form whenever	user deletes a scenario	output level.

********************************************************/



procedure	remove_scenario_output_lvl(

p_demand_plan_id in	number,

p_scenario_id	in number,

p_level_id in	number)



is



cursor c1	is

select enable_nonseed_flag

from msd_dp_scenarios

where	demand_plan_id = p_demand_plan_id

and	scenario_id	=	p_scenario_id;
Line: 3280

	-- disable doc dim selections

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	selection_type = 'L'

	and	selection_value	=	p_level_id

	and	enabled_flag = 'Y';
Line: 3318

Called from	form whenever	user deletes a scenario	event.

FOR	FUTURE USE

********************************************************/



procedure	remove_event(

p_demand_plan_id in	number,

p_dp_event_id	in number)



is

BEGIN

	null;
Line: 3368

Called from	form whenever	user deletes a calendar.

FOR	FUTURE USE

********************************************************/



procedure	remove_calendar(

p_demand_plan_id in	number,

p_calendar_type	in varchar2,

p_calendar_code	in varchar2)



is



BEGIN

	null;
Line: 3402

Called from	form whenever	user deletes a hierarchy.

********************************************************/



procedure	remove_hierarchy(

p_demand_plan_id in	number,

p_dp_dimension_code	in varchar2,

p_hierarchy_id in	number)

is

BEGIN

savepoint	sp;
Line: 3424

	-- disable doc dim selections

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	selection_type = 'H'

	and	selection_value	=	p_hierarchy_id;
Line: 3440

	update msd_dp_formula_parameters

	set	enabled_flag = 'N'

	where	demand_plan_id = p_demand_plan_id

	and	parameter_type = 'H'

	and	parameter_value	=	p_hierarchy_id;
Line: 3496

	update msd_dp_seeded_doc_dimensions

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_Demand_plan_id

	and	dimension_code = p_dp_dimension_code

	and	enabled_flag = 'N';
Line: 3508

	-- enable	document selections	that use related hierarchies and levels

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_Demand_plan_id

	and	((selection_type = 'H'

	and	selection_value	in

	(select	distinct hierarchy_id	from msd_hierarchies

	where	dimension_code = p_dp_dimension_code))

	or (selection_type = 'L'

	and	selection_value	in

	(select	distinct level_id	from msd_levels

	where	dimension_code = p_dp_dimension_code)));
Line: 3536

	update msd_dp_formula_parameters

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_Demand_plan_id

	and	parameter_type = 'D'

	and	parameter_value	=	p_dp_dimension_code

	and	enabled_flag = 'N';
Line: 3590

	-- enable	doc	dim	selections

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_Demand_plan_id	 and selection_type	=	'I'

	and	selection_value	=	p_parameter_type

	and	nvl(supply_plan_name,'~!#$%^&*') = nvl(p_parameter_name,'~!#$%^&*')

	and	enabled_flag = 'N';
Line: 3608

	update msd_dp_formula_parameters

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_Demand_plan_id

	and	parameter_type = 'I'

	and	parameter_value	=	p_parameter_type

	and	nvl(supply_plan_name,'~!#$%^&*') = nvl(p_parameter_name,'~!#$%^&*')

	and	enabled_flag = 'N';
Line: 3662

select supply_plan_name, forecast_based_on,	parameter_name

from msd_dp_scenarios

where	demand_plan_id = p_demand_plan_id

and	scenario_name	=	p_scenario_name;
Line: 3694

	update msd_dp_formula_parameters

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_demand_plan_id

	and	parameter_component	=	'SN'

	and	parameter_value	=	l_forecast_based_on

	and	nvl(supply_plan_name,'123456789')	=	nvl(l_parameter_name,'123456789');
Line: 3708

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_demand_plan_id

	and	selection_component	=	'SN'

	and	selection_value	=	l_forecast_based_on

	and	nvl(supply_plan_name,'123456789')	=	nvl(l_parameter_name,'123456789');
Line: 3840

/*----Bug	4550732----If	a	dimension	is added first time, it	will be	inserted into	seeded dimensions----*/





cursor c1(p_document_id	in number)is

select max(sequence_number)+1

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_demand_plan_id

and	document_id	=	p_document_id

and	axis = 'Z';
Line: 3862

select distinct	document_id

from msd_dp_seeded_documents

where	demand_plan_id = p_demand_plan_id;
Line: 3888

	-- enable	doc	dim	selections

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_demand_plan_id

	and	selection_type = 'H'

	and	selection_value	=	p_hierarchy_id

	and	enabled_flag = 'N';
Line: 3904

 /*----Bug 4550732----If a dimension is	added	first	time,	it will	be inserted	into seeded	dimensions----*/



l_dimension_code:=p_dp_dimension_code;
Line: 3912

select count(*)	into l_count

	from msd_dp_seeded_doc_dimensions

	where	demand_plan_id = p_demand_plan_id

	and	dimension_code = l_dimension_code;
Line: 3922

	select count(*) into l_coll_dim
	from msd_dp_dimensions
	where demand_plan_id=p_demand_plan_id
	and dimension_code = l_dimension_code
	and dp_dimension_code=l_dimension_code;
Line: 3956

			insert into	msd_dp_seeded_doc_dimensions

			(

			DEMAND_PLAN_ID

			,DOCUMENT_ID

			,DIMENSION_CODE

			,SEQUENCE_NUMBER

			,AXIS

			,HIERARCHY_ID

			,SELECTION_TYPE

			,SELECTION_SCRIPT

			,ENABLED_FLAG

			,MANDATORY_FLAG

			,LAST_UPDATED_BY

			,CREATION_DATE

			,CREATED_BY

			,LAST_UPDATE_LOGIN

			,REQUEST_ID

			,PROGRAM_APPLICATION_ID

			,PROGRAM_ID

			,PROGRAM_UPDATE_DATE

			,LAST_UPDATE_DATE

			)

				VALUES

				(

	p_demand_plan_id

	,c2_cur.document_id

				,l_dimension_code

				,l_sequence_number

				,'Z'

				,p_hierarchy_id

	,'S'

	,'limit	'||l_dimension_code||' to	'||l_dimension_code||'.L.REL eq	1'

	,'Y'

	,'N'

				,fnd_global.user_id

				,SYSDATE

				,fnd_global.user_id

				,fnd_global.login_id

				,NULL

				,NULL

				,NULL

				,SYSDATE

				,SYSDATE

	);
Line: 4128

select enable_nonseed_flag

from msd_dp_scenarios

where	demand_plan_id = p_demand_plan_id

and	scenario_id	=	p_scenario_id;
Line: 4140

select dimension_code

from msd_levels

where	level_id = p_level_id;
Line: 4150

select distinct	hierarchy_id

from msd_dp_hierarchies

where	demand_plan_id = p_demand_plan_id

and	dp_dimension_code	=	p_dimension_code;
Line: 4162

select max(sequence_number)+1

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_demand_plan_id

and	document_id	=	p_document_id

and	axis = 'Z';
Line: 4176

select distinct	document_id

from msd_dp_seeded_documents

where	demand_plan_id = p_demand_plan_id;
Line: 4222

	-- enable	doc	dim	selections

	update msd_dp_doc_dim_selections

	set	enabled_flag = 'Y'

	where	demand_plan_id = p_demand_plan_id

	and	selection_type = 'L'

	and	selection_value	=	p_level_id

	and	enabled_flag = 'N';
Line: 4240

	select count(*)	into l_count

	from msd_dp_seeded_doc_dimensions

	where	demand_plan_id = p_demand_plan_id

	and	dimension_code = l_dimension_code;
Line: 4290

			insert into	msd_dp_seeded_doc_dimensions

			(

			DEMAND_PLAN_ID

			,DOCUMENT_ID

			,DIMENSION_CODE

			,SEQUENCE_NUMBER

			,AXIS

			,HIERARCHY_ID

			,SELECTION_TYPE

			,SELECTION_SCRIPT

			,ENABLED_FLAG

			,MANDATORY_FLAG

			,LAST_UPDATED_BY

			,CREATION_DATE

			,CREATED_BY

			,LAST_UPDATE_LOGIN

			,REQUEST_ID

			,PROGRAM_APPLICATION_ID

			,PROGRAM_ID

			,PROGRAM_UPDATE_DATE

			,LAST_UPDATE_DATE

			)

				VALUES

				(

	p_demand_plan_id

	,c5_cur.document_id

				,l_dimension_code

				,l_sequence_number

				,'Z'

				,l_hierarchy_id

	,'S'

	,'limit	'||l_dimension_code||' to	'||l_dimension_code||'.L.REL eq	1'

	,'Y'

	,'N'

				,fnd_global.user_id

				,SYSDATE

				,fnd_global.user_id

				,fnd_global.login_id

				,NULL

				,NULL

				,NULL

				,SYSDATE

				,SYSDATE

	);
Line: 4438

select enable_nonseed_flag

from msd_dp_scenarios

where	demand_plan_id = p_demand_plan_id

and	scenario_id	=	p_scenario_id;
Line: 4450

select distinct	document_id

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_demand_plan_id

and	dimension_code = 'TIM'

and	upper(selection_script)	like 'CALL SL.LIMIT.ROLLTIM(%'||p_old_output_period_type_id||')';
Line: 4464

select selection_value,	selection_sequence

from msd_dp_doc_dim_selections

where	demand_plan_id = p_demand_plan_id

and	dimension_code = 'TIM'

and	selection_sequence in	(1,2)

and	document_id	=	p_document_id;
Line: 4486

l_new_selection_value	number;
Line: 4536

			if c3_cur.selection_sequence = 1 then

				l_start_date :=	msd_common_utilities.get_bucket_start_date(sysdate,c3_cur.selection_value,p_old_output_period_type_id,l_calendar_code);
Line: 4540

	l_new_selection_value	:= msd_common_utilities.get_age_in_buckets(l_start_date,sysdate,p_output_period_type_id,l_calendar_code);
Line: 4544

			elsif	c3_cur.selection_sequence	=	2	then

				l_end_date :=	msd_common_utilities.get_bucket_end_date(sysdate,c3_cur.selection_value,p_old_output_period_type_id,l_calendar_code);
Line: 4548

	l_new_selection_value	:= msd_common_utilities.get_age_in_buckets(sysdate,l_end_date,p_output_period_type_id,l_calendar_code);
Line: 4554

			-- update	with new values

			update msd_dp_doc_dim_selections

			set	selection_value	=	l_new_selection_value*sign(c3_cur.selection_value)

			where	demand_plan_id = p_demand_plan_id

			and	document_id	=	c2_cur.document_id

			and	dimension_code = 'TIM'

			and	selection_type = 'TL'

			and	selection_value	=	c3_cur.selection_value

			and	selection_sequence = c3_cur.selection_sequence;
Line: 4582

	-- update	the	selection	value	with new data

	update msd_dp_doc_dim_selections

	set	selection_value	=	p_output_period_type_id

	where	demand_plan_id = p_demand_plan_id

	and	selection_type = 'TL'

	and	selection_value	=	p_old_output_period_type_id;
Line: 4644

select enable_nonseed_flag

from msd_dp_hierarchies

where	demand_plan_id = p_demand_plan_id

and	hierarchy_id = p_old_hierarchy_id;
Line: 4680

	update msd_dp_doc_dim_selections

	set	selection_value	=	p_hierarchy_id

	where	demand_plan_id = p_demand_plan_id

	and	selection_type = 'H'

	and	selection_value	=	p_old_hierarchy_id;
Line: 4732

select enable_nonseed_flag

from msd_dp_scenario_output_levels

where	demand_plan_id = p_demand_plan_id

and	scenario_id	=	p_scenario_id

and	level_id = p_old_level_id;
Line: 4774

	update msd_dp_doc_dim_selections

	set	selection_value	=	p_level_id

	where	demand_plan_id = p_demand_plan_id

	and	selection_type = 'L'

	and	selection_value	=	p_old_level_id;
Line: 4828

select enable_nonseed_flag

from msd_dp_scenarios

where	demand_plan_id = p_demand_plan_id

and	scenario_id	=	p_scenario_id;
Line: 4876

			-- disable the doc dim selections

			update msd_dp_doc_dim_selections

			set	enabled_flag = 'N'

			where	demand_plan_id = p_demand_plan_id

			and	selection_component	=	'SN'

			and	selection_value	=	p_old_stream_type;
Line: 4892

			update msd_dp_formula_parameters

			set	enabled_flag = 'N'

			where	demand_plan_id = p_demand_plan_id

			and	parameter_component	=	'SN'

			and	parameter_value	=	p_old_stream_type;
Line: 4910

			-- change	the	doc	dim	selections

			update msd_dp_doc_dim_selections

			set	selection_value	=	p_stream_type

			where	demand_plan_id = p_demand_plan_id

			and	selection_component	=	'SN'

			and	selection_value	=	p_old_stream_type;
Line: 4926

			update msd_dp_formula_parameters

			set	parameter_value	=	p_stream_type

			where	demand_plan_id = p_demand_plan_id

			and	parameter_component	=	'SN'

			and	parameter_value	=	p_old_stream_type;
Line: 4948

			-- enable	the	doc	dim	selections

			update msd_dp_doc_dim_selections

			set	enabled_flag = 'Y'

			where	demand_plan_id = p_demand_plan_id

			and	selection_component	=	'SN'

			and	selection_value	=	p_old_stream_type;
Line: 4964

			update msd_dp_formula_parameters

			set	enabled_flag = 'Y'

			where	demand_plan_id = p_demand_plan_id

			and	parameter_component	=	'SN'

			and	parameter_value	=	p_old_stream_type;
Line: 5020

select plan_type
from msd_demand_plans
where demand_plan_id=p_new_dp_id;
Line: 5034

select template_id

from msd_demand_plans

where	demand_plan_id=p_new_dp_id;
Line: 5051

				update msd_demand_plans
				set liab_plan_id=p_supply_plan_id
				where demand_plan_id=p_new_dp_id;
Line: 5107

Called from	update_ascp_related_data

********************************************************/



Procedure	add_ascp_scenario(p_new_dp_id	in number,p_supply_plan_id in	number,	p_supply_plan_name in	varchar2)	-- Bug 4729854

is



cursor c1	is

select count(*)	from

msd_dp_scenarios

where	demand_plan_id = p_new_dp_id

and	supply_plan_flag = 'Y';
Line: 5133

select scenario_name,	description, demand_plan_id, scenario_id

		from msd_dp_scenarios

		where	supply_plan_flag = 'Y'

		and	demand_plan_id =

		(select	demand_plan_id

		from msd_demand_plans

		where	plan_type	=	(select plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id)

		and	template_flag	=	'Y'

		and	default_template = 'Y'

		);
Line: 5215

select msd_dp_scenarios_s.nextval	into l_scenario_id from	dual;
Line: 5219

	insert into	msd_dp_scenarios

	(demand_plan_id

	 ,scenario_id

	 ,scenario_name

	 ,description

	 ,output_period_type

	 ,horizon_start_date

	 ,horizon_end_date

	 ,forecast_date_used

	 ,forecast_based_on

	 ,last_update_date

	 ,last_updated_by

	 ,creation_date

	 ,created_by

	 ,last_update_login

	 ,request_id

	 ,program_application_id

	 ,program_id

	 ,program_update_date

	 ,attribute_category

	 ,attribute1

	 ,attribute2

	 ,attribute3

	 ,attribute4

	 ,attribute5

	 ,attribute6

	 ,attribute7

	 ,attribute8

	 ,attribute9

	 ,attribute10

	 ,attribute11

	 ,attribute12

	 ,attribute13

	 ,attribute14

	 ,attribute15

	 ,scenario_type

	 ,status

	 ,history_start_date

	 ,history_end_date

	 ,publish_flag

	 ,enable_flag

	 ,price_list_name

	 ,last_revision

	 ,parameter_name

	 ,consume_flag

	 ,error_type

	 ,supply_plan_id

	 ,deleteable_flag

	 ,supply_plan_flag

	 ,supply_plan_name

	 ,dmd_priority_scenario_id 									 --	Bug	4710963

	 ,scenario_designator

	 ,associate_parameter

	 ,sc_type)

	 (select

		p_new_dp_id

	 ,l_scenario_id

	 ,l_name

	 ,l_description

	 ,output_period_type

	 ,decode(p_type.plan_type, 'SOP', msd_common_utilities.get_bucket_start_date(sysdate,2,6,'GREGORIAN'), null)

	 ,decode(p_type.plan_type, 'SOP', msd_common_utilities.get_bucket_end_date(sysdate,19,6,'GREGORIAN'), null)

	 ,forecast_date_used

	 ,forecast_based_on

	 ,SYSDATE

	 ,fnd_global.user_id

	 ,SYSDATE

	 ,fnd_global.user_id

	 ,fnd_global.login_id

	 ,NULL

	 ,NULL

	 ,NULL

	 ,SYSDATE

	 ,attribute_category

	 ,attribute1

	 ,attribute2

	 ,attribute3

	 ,attribute4

	 ,attribute5

	 ,attribute6

	 ,attribute7

	 ,attribute8

	 ,attribute9

	 ,attribute10

	 ,attribute11

	 ,attribute12

	 ,attribute13

	 ,attribute14

	 ,attribute15

	 ,scenario_type

	 ,status

	 ,decode(p_type.plan_type, 'SOP', msd_common_utilities.get_bucket_start_date(sysdate,-18,6,'GREGORIAN'), null)

	 ,decode(p_type.plan_type, 'SOP', msd_common_utilities.get_bucket_end_date(sysdate,1,6,'GREGORIAN'), null)

	 ,publish_flag

	 ,enable_flag

	 ,price_list_name

	 ,last_revision

	 ,parameter_name

	 ,consume_flag

	 ,error_type

	 ,p_supply_plan_id

	 ,deleteable_flag

	 ,supply_plan_flag

	 ,p_supply_plan_name																					 --	Bug	4729854

	 ,dmd_priority_scenario_id																		 --	Bug	4710963

	 ,scenario_designator

	 ,associate_parameter

	 ,sc_type

		from msd_dp_scenarios,

		(select nvl(plan_type,'DP')  plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id) p_type

		where	scenario_id	=	c2_cur.scenario_id

		and	demand_plan_id = c2_cur.demand_plan_id);
Line: 5447

 insert	into msd_dp_scenarios_tl

				 ( demand_plan_id

					 ,scenario_id

					 ,description

					 ,language

					 ,source_lang

					 ,creation_date

					 ,created_by

					 ,last_update_date

					 ,last_updated_by

					 ,last_update_login

					 ,request_id

					 ,program_application_id

					 ,program_id

					 ,program_update_date

		 )

	select

						p_new_dp_id

					 ,l_scenario_id

					 ,l_description

					 ,USERENV('LANG')

					 ,USERENV('LANG')

					 ,SYSDATE

					 ,fnd_global.user_id

					 ,SYSDATE

					 ,fnd_global.user_id

					 ,fnd_global.login_id

					 ,NULL

					 ,NULL

					 ,NULL

					 ,SYSDATE

		from dual;
Line: 5515

		insert into	msd_dp_scenario_events

		(

		demand_plan_id

		,scenario_id

		,event_id

		,last_update_date

		,last_updated_by

		,creation_date

		,created_by

		,last_update_login

		,request_id

		,program_application_id

		,program_id

		,program_update_date

		,event_association_priority)

		(select

		p_new_dp_id

		,l_scenario_id

		,event_id

		,last_update_date

		,last_updated_by

		,creation_date

		,created_by

		,last_update_login

		,request_id

		,program_application_id

		,program_id

		,program_update_date

		,event_association_priority

		from msd_dp_scenario_events

		where	scenario_id	=	c2_cur.scenario_id

		and	demand_plan_id = c2_cur.demand_plan_id);
Line: 5583

insert into	msd_dp_scenario_output_levels

		(

		 demand_plan_id

		 ,scenario_id

		 ,level_id

		 ,last_update_date

		 ,last_updated_by

		 ,creation_date

		 ,created_by

		 ,last_update_login

		 ,request_id

		 ,program_application_id

		 ,program_id

		 ,program_update_date)

		 (select

		 p_new_dp_id

		 ,l_scenario_id

		 ,level_id

		 ,SYSDATE

		 ,fnd_global.user_id

		 ,SYSDATE

		 ,fnd_global.user_id

		 ,fnd_global.login_id

		 ,NULL

		 ,NULL

		 ,NULL

		 ,SYSDATE

		 from	msd_dp_scenario_output_levels

		where	scenario_id	=	c2_cur.scenario_id

		and	demand_plan_id = c2_cur.demand_plan_id);
Line: 5663

Called from	update_ascp_related_data,	attach_supply_plan.

********************************************************/



Procedure	add_ascp_input_parameter(p_new_dp_id in	number,p_supply_plan_id	in number,p_supply_plan_name in	varchar2,

																	 p_old_supply_plan_id	in number	default	null,	p_old_supply_plan_name in	varchar2 default null)		-- Bug 4729854

is

BEGIN





if p_old_supply_plan_id	is not null	then



		-- change	the	parameters if	change in	ascp plan	attahced

		if p_supply_plan_id	is not null	then



			update msd_dp_parameters

			set	parameter_name = p_supply_plan_name,					 --	Bug	4729854

			--Bug	4549059

			capacity_usage_ratio = decode(parameter_type,'MSD_SUPPLY_PLANS',p_supply_plan_name,
			                                             'MSD_SIM_END_ITEM_DEMAND',p_supply_plan_name,
			                                             capacity_usage_ratio)		-- Bug 4729854

			where	demand_plan_id = p_new_dp_id

			and	parameter_name = p_old_supply_plan_name;					-- Bug 4729854
Line: 5707

		-- delete	if ascp	plan is	detached

		else

			delete from	msd_dp_parameters

			where	demand_plan_id = p_new_dp_id

			and	parameter_name = p_old_supply_plan_name;				 --	Bug	4729854
Line: 5727

		insert into	msd_dp_parameters

		(

		demand_plan_id

		,parameter_id

		,parameter_type

		,parameter_name

		,start_date

		,end_date

		,output_scenario_id

		,input_scenario_id

		,input_demand_plan_id

		,forecast_date_used

		,forecast_based_on

		,quantity_used

		,amount_used

		,forecast_used

		,period_type

		,fact_type

		,view_name

		,last_update_date

		,last_updated_by

		,creation_date

		,created_by

		,last_update_login

		,request_id

		,program_application_id

		,program_id

		,program_update_date

		,revision

		,allo_agg_basis_stream_id

		,number_of_period

		,exclude_from_rolling_cycle

		,scn_build_refresh_num

		,rounding_flag

		,deleteable_flag

		,capacity_usage_ratio

		,supply_plan_flag
		, equation
		,stream_type
		,calculated_order
		,post_calculation
		,price_list_name)

		(select

		p_new_dp_id

		,msd_dp_parameters_s.nextval

		,parameter_type

		,p_supply_plan_name																			-- Bug 4729854

		,decode(p_type.plan_type, 'SOP', get_supply_plan_start_date(p_supply_plan_id), null)

		,decode(p_type.plan_type, 'SOP', get_supply_plan_end_date(p_supply_plan_id), null)

		,output_scenario_id

		,input_scenario_id

		,input_demand_plan_id

		,forecast_date_used

		,forecast_based_on

		,quantity_used

		,amount_used

		,forecast_used

		,period_type

		,fact_type

		,view_name

		,SYSDATE

		,fnd_global.user_id

		,SYSDATE

		,fnd_global.user_id

		,fnd_global.login_id

		,NULL

		,NULL

		,NULL

		,SYSDATE

		,revision

		,allo_agg_basis_stream_id

		,number_of_period

		,exclude_from_rolling_cycle

		,scn_build_refresh_num

		,rounding_flag

		,deleteable_flag

		,decode(p_type.plan_type, 'SOP', decode(parameter_type,'MSD_SUPPLY_PLANS',p_supply_plan_name,capacity_usage_ratio)
														, 'EOL', decode(parameter_type,'MSD_SIM_END_ITEM_DEMAND',p_supply_plan_name,capacity_usage_ratio))	 --	Bug	4729854

		,supply_plan_flag
		,equation
		,stream_type
		,calculated_order
		,post_calculation
		,price_list_name

		from msd_dp_parameters,

		(select nvl(plan_type,'DP') plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id) p_type

		where	supply_plan_flag = 'Y'

		and nvl(stream_type,'ABCD') not in ('ARCHIVED','ARCHIVED_TIM')

		and	demand_plan_id	=

		(select	demand_plan_id

		from msd_demand_plans

		where	plan_type	=	p_type.plan_type

		and	template_flag	=	'Y'

		and	default_template = 'Y'

		));
Line: 5920

Called from	update_ascp_related_data,	attach_supply_plan.

********************************************************/



Procedure	add_ascp_formula(p_new_dp_id in	number,p_supply_plan_id	in number,p_supply_plan_name in	varchar2,

													 p_old_supply_plan_id	in number	default	null,p_old_supply_plan_name	in varchar2	default	null)		-- Bug 4729854

is



l_formula_id number;
Line: 5940

select

	 formula_id

	,creation_sequence

	,formula_name

	,formula_desc

	,custom_type

	,equation

	,custom_field1

	,custom_field2

	,custom_subtype

	,custom_addtlcalc

	,isby

	,valid_flag

	,numerator

	,denominator

	,supply_plan_flag

	,p_supply_plan_name														-- Bug 4729854

	,FORMAT																		 /*	ADDED	NEW	COLUMN FOR THE BUG#4373422	*/

	,START_PERIOD															 /*	ADDED	NEW	COLUMN FOR THE BUG#4744717	*/

	from msd_dp_formulas

	where	demand_plan_id	=

		(select	demand_plan_id

		from msd_demand_plans

		where	plan_type	=	(select plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id)

		and	template_flag	=	'Y'

		and	default_template = 'Y'

		)

	and	supply_plan_flag = 'Y';
Line: 5998

select plan_type
from msd_demand_plans
where demand_plan_id=p_new_dp_id;
Line: 6021

			update msd_dp_formulas

			set	supply_plan_name = p_supply_plan_name				 --	Bug	4729854

			where	demand_plan_id = p_new_dp_id

			and	supply_plan_name = p_old_supply_plan_name;		-- Bug 4729854
Line: 6031

			update msd_dp_formula_parameters

			set	supply_plan_name = p_supply_plan_name						 --	Bug	4729854

			where	demand_plan_id = p_new_dp_id

			and	supply_plan_name = p_old_supply_plan_name;			 --	Bug	4729854
Line: 6041

		-- delete	the	formula	if ascp	plan is	detached

		else



			delete from	msd_dp_formulas

			where	demand_plan_id = p_new_dp_id

			and	supply_plan_name = p_old_supply_plan_name;				 --	Bug	4729854
Line: 6055

			delete from	msd_dp_formula_parameters

			where	demand_plan_id = p_new_dp_id

			and	supply_plan_name = p_old_supply_plan_name;				 --	Bug	4729854
Line: 6075

	select msd_dp_parameters_s.nextval into	l_formula_id from	dual;
Line: 6079

	insert into	msd_dp_formulas

	(

	demand_plan_id

	,formula_id

	,creation_sequence

	,formula_name

	,formula_desc

	,custom_type

	,equation

	,custom_field1

	,custom_field2

	,custom_subtype

	,custom_addtlcalc

	,isby

	,valid_flag

	,numerator

	,denominator

	,supply_plan_flag

	,supply_plan_name

	,last_update_date

	,FORMAT							 /*----NEW COLUMN	ADDED	FOR	THE	BUG# 4373422-----*/

	,START_PERIOD				 /*	ADDED	NEW	COLUMN FOR THE BUG#4744717	*/

	,last_updated_by

	,creation_date

	,created_by

	,last_update_login

	,request_id

	,program_application_id

	,program_id

	,program_update_date

	)

	values

	(

	 p_new_dp_id

	,l_formula_id

	,c1_cur.creation_sequence

	,c1_cur.formula_name

	,c1_cur.formula_desc

	,c1_cur.custom_type

	,c1_cur.equation

	,c1_cur.custom_field1

	,c1_cur.custom_field2

	,c1_cur.custom_subtype

	,c1_cur.custom_addtlcalc

	,c1_cur.isby

	,c1_cur.valid_flag

	,c1_cur.numerator

	,c1_cur.denominator

	,c1_cur.supply_plan_flag

	,p_supply_plan_name												-- Bug 4729854

	,SYSDATE

	,c1_cur.FORMAT							/*----NEW	COLUMN ADDED FOR THE BUG#	4373422-----*/

	,c1_cur.START_PERIOD				/* ADDED NEW COLUMN	FOR	THE	BUG#4744717	 */

	,fnd_global.user_id

	,SYSDATE

	,fnd_global.user_id

	,fnd_global.login_id

	,NULL

	,NULL

	,NULL

	,SYSDATE);
Line: 6203

	insert into	msd_dp_formula_parameters

	(

	demand_plan_id

	,formula_id

	,where_used

	,parameter_sequence

	,enabled_flag

	,mandatory_flag

	,parameter_type

	,parameter_component

	,parameter_value

	,supply_plan_flag

	,supply_plan_name

	,last_update_date

	,last_updated_by

	,creation_date

	,created_by

	,last_update_login

	,request_id

	,program_application_id

	,program_id

	,program_update_date

	)

	(select

	p_new_dp_id

	,l_formula_id

	,where_used

	,parameter_sequence

	,enabled_flag

	,mandatory_flag

	,parameter_type

	,parameter_component

	,parameter_value

	,supply_plan_flag

	,decode(supply_plan_flag,'Y',p_supply_plan_name,null)								-- Bug 4729854

	,SYSDATE

	,fnd_global.user_id

	,SYSDATE

	,fnd_global.user_id

	,fnd_global.login_id

	,NULL

	,NULL

	,NULL

	,SYSDATE

	from msd_dp_formula_parameters

	where	demand_plan_id	=

		(select	demand_plan_id

		from msd_demand_plans

		where	plan_type	=	(select plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id)

		and	template_flag	=	'Y'

		and	default_template = 'Y'

		)

	and	formula_id = c1_cur.formula_id);
Line: 6316

	insert into	msd_dp_formula_parameters

	(

	demand_plan_id

	,formula_id

	,where_used

	,parameter_sequence

	,enabled_flag

	,mandatory_flag

	,parameter_type

	,parameter_component

	,parameter_value

	,supply_plan_flag

	,supply_plan_name

	,last_update_date

	,last_updated_by

	,creation_date

	,created_by

	,last_update_login

	,request_id

	,program_application_id

	,program_id

	,program_update_date

	)

	(select

	p_new_dp_id

	,mdp1.parameter_id

	,mdfp.where_used

	,mdfp.parameter_sequence

	,mdfp.enabled_flag

	,mdfp.mandatory_flag

	,mdfp.parameter_type

	,mdfp.parameter_component

	,mdfp.parameter_value

	,mdfp.supply_plan_flag

	,decode(mdfp.supply_plan_flag,'Y',p_supply_plan_name,null)								-- Bug 4729854

	,SYSDATE

	,fnd_global.user_id

	,SYSDATE

	,fnd_global.user_id

	,fnd_global.login_id

	,NULL

	,NULL

	,NULL

	,SYSDATE

	from msd_dp_formula_parameters mdfp,
	msd_dp_parameters mdp,
	msd_dp_parameters mdp1

	where	mdfp.demand_plan_id	=

		(select	demand_plan_id

		from msd_demand_plans

		where	plan_type	=	(select plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id)

		and	template_flag	=	'Y'

		and	default_template = 'Y')
		and mdp.demand_plan_id=mdfp.demand_plan_id
		and mdp.parameter_id=mdfp.formula_id
		and mdp1.demand_plan_id=p_new_dp_id
		and mdp1.parameter_type=mdp.parameter_type);
Line: 6432

 * This	procedure	'update_formula_names' should	always be	called whenever	a

 * supply	plan is	attached to	a	scenario.

 * Note: This	procedure	'update_formula_names' will	not	be called	whenever a

 * supply	plan attached	to a scenario	is changed/deleted.

 */

 --	if not g_call	then

 update_formula_names(p_new_dp_id);
Line: 6460

Called from	update_ascp_related_data,	attach_supply_plan.

********************************************************/



Procedure	add_ascp_measure(p_new_dp_id in	number,p_supply_plan_id	in number,p_supply_plan_name in	varchar2,

														p_old_supply_plan_id in	number default null,p_old_supply_plan_name in	varchar2 default null) --	Bug	4729854

is



cursor c1	is

select msd.document_id,	msd.document_name

from msd_dp_seeded_documents msd

where	msd.demand_plan_id = p_new_dp_id;
Line: 6486

select document_id

from msd_dp_seeded_documents

where	document_name	=	p_document_name

and	demand_plan_id =

(select	demand_plan_id

from msd_demand_plans

where	plan_type	=	(select plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id)

and	template_flag	=	'Y'

and	default_template = 'Y');
Line: 6508

select count(*)

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	supply_plan_flag = 'Y';
Line: 6520

select distinct	document_id, dimension_code

from msd_dp_seeded_doc_dimensions

where	demand_plan_id = p_new_dp_id

order	by document_id,	dimension_code;
Line: 6532

select selection_sequence

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	supply_plan_name = p_old_supply_plan_name					-- Bug 4729854

and	document_id	=	p_document_id

and	dimension_code = p_dimension_code

order	by selection_sequence;
Line: 6548

cursor c6(p_document_id	in number, p_dimension_code	in varchar2, p_selection_sequence	in number)	is

select supply_plan_name, min(selection_sequence)

from msd_dp_doc_dim_selections

where	demand_plan_id = p_new_dp_id

and	supply_plan_name is	not	null

and	supply_plan_name <>	p_old_supply_plan_name			 --	Bug	4729854

and	document_id	=	p_document_id

and	dimension_code = p_dimension_code

and	selection_sequence > p_selection_sequence

group	by supply_plan_name

order	by min(selection_sequence);
Line: 6574

l_max_selection_sequence number;
Line: 6582

l_selection_sequence	number;
Line: 6586

l_selection_count	number;
Line: 6602

			update msd_dp_doc_dim_selections

			set	supply_plan_name = p_supply_plan_name						-- Bug 4729854

			where	demand_plan_id = p_new_dp_id

			and	supply_plan_name = p_old_supply_plan_name;			-- Bug 4729854
Line: 6612

		-- delete	the	measure	if ascp	plan is	detached and update	any	other	ascp specific	measure	to be	first	measure	if this	was	the	first	measure

		else





			-- for each	document,	dimension	in plan

			for	c4_cur in	c4 loop



				l_selection_count	:= 0;
Line: 6630

				-- for each	selection	sequence for the detached	plan

				for	c5_cur in	c5(c4_cur.document_id, c4_cur.dimension_code)	loop



				-- get the next	supply plan	name if	any	and	difference in	selection	sequences	for	the	document and dimension.

	-- do	this only	once for a document	and	dimension

	if l_selection_count = 0 then

				open c6(c4_cur.document_id,	c4_cur.dimension_code,c5_cur.selection_sequence);
Line: 6644

	fetch	c6 into	l_supply_plan_name,	l_selection_sequence;
Line: 6650

	l_seq_diff :=	l_selection_sequence - c5_cur.selection_sequence;
Line: 6656

	-- delete	the	selection	first

				delete from	msd_dp_doc_dim_selections

	where	demand_plan_id = p_new_dp_id

	and	supply_plan_name = p_old_supply_plan_name							 --	Bug	4729854

	and	selection_sequence = c5_cur.selection_sequence

	and	document_id	=	c4_cur.document_id

	and	dimension_code = c4_cur.dimension_code;
Line: 6672

				-- set the selection sequence	of the next	ascp measure to	the	selection	sequence of	the	measure	being	deleted	and	increase by	1000 to	avoid	uinque constraint	violation

				update msd_dp_doc_dim_selections

	set	selection_sequence = c5_cur.selection_sequence

	where	demand_plan_id = p_new_dp_id

	and	supply_plan_name = l_supply_plan_name

	and	selection_sequence = l_seq_diff	+	c5_cur.selection_sequence

	and	document_id	=	c4_cur.document_id

	and	dimension_code = c4_cur.dimension_code;
Line: 6690

				l_selection_count	:= l_selection_count +1;
Line: 6718

	-- increase	selection	sequence if	not	first	first	plan attached

	if l_count > 0 then



	-- for each	document for the plan

	for	c1_cur in	c1 loop



	-- get the document	id of	the	same documnet	in template

	open c2(c1_cur.document_name);
Line: 6740

	select max(selection_sequence) into	l_max_selection_sequence from	msd_dp_doc_dim_selections

	where	demand_plan_id = p_new_dp_id;
Line: 6748

	insert into	msd_dp_doc_dim_selections

	(

	demand_plan_id

	,document_id

	,dimension_code

	,enabled_flag

	,mandatory_flag

	,selection_sequence

	,selection_type

	,selection_component

	,selection_value

	,supply_plan_flag

	,supply_plan_name

	,last_update_date

	,last_updated_by

	,creation_date

	,created_by

	,last_update_login

	,request_id

	,program_application_id

	,program_id

	,program_update_date

	)

	(select

	 p_new_dp_id

	,c1_cur.document_id

	,dimension_code

	,enabled_flag

	,mandatory_flag

	,l_max_selection_sequence	+	selection_sequence

	,selection_type

	,selection_component

	,selection_value

	,supply_plan_flag

	,p_supply_plan_name											 --	Bug	4729854

	,SYSDATE

	,fnd_global.user_id

	,SYSDATE

	,fnd_global.user_id

	,fnd_global.login_id

	,NULL

	,NULL

	,NULL

	,SYSDATE

	from msd_dp_doc_dim_selections

	where	supply_plan_flag = 'Y'

	and	demand_plan_id =

	 (select demand_plan_id

		from msd_demand_plans

		where	plan_type	=	(select plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id)

		and	template_flag	=	'Y'

		and	default_template = 'Y'

		)

		and	document_id	=	l_document_id);
Line: 6862

	-- use seeded	selection	sequence if	first	plan attached

	else /*	l_count	>0 */



	-- for each	document for the plan

	for	c1_cur in	c1 loop





	-- get the document	id of	the	same documnet	in template

	open c2(c1_cur.document_name);
Line: 6888

	insert into	msd_dp_doc_dim_selections

	(

	demand_plan_id

	,document_id

	,dimension_code

	,enabled_flag

	,mandatory_flag

	,selection_sequence

	,selection_type

	,selection_component

	,selection_value

	,supply_plan_flag

	,supply_plan_name

	,last_update_date

	,last_updated_by

	,creation_date

	,created_by

	,last_update_login

	,request_id

	,program_application_id

	,program_id

	,program_update_date

	)

	(select

	 p_new_dp_id

	,c1_cur.document_id

	,dimension_code

	,enabled_flag

	,mandatory_flag

	,selection_sequence

	,selection_type

	,selection_component

	,selection_value

	,supply_plan_flag

	,p_supply_plan_name							 --	Bug	4729854

	,SYSDATE

	,fnd_global.user_id

	,SYSDATE

	,fnd_global.user_id

	,fnd_global.login_id

	,NULL

	,NULL

	,NULL

	,SYSDATE

	from msd_dp_doc_dim_selections

	where	supply_plan_flag = 'Y'

	and	demand_plan_id =

	 (select demand_plan_id

		from msd_demand_plans

		where	plan_type	=	(select plan_type from msd_demand_plans where demand_plan_id=p_new_dp_id)

		and	template_flag	=	'Y'

		and	default_template = 'Y'

		)

		and	document_id	=	l_document_id);
Line: 7030

	select fnd_profile.value('MSC_LIABILITY_CALC_LEVEL') into	l_level	from dual;
Line: 7034

	update msd_dp_doc_dim_selections

	set	selection_value	=	nvl(fnd_profile.value('MSC_LIABILITY_CALC_LEVEL'),1)

	where	demand_plan_id = p_demand_plan_id

	and	document_id	in

	(select	document_id

	from msd_dp_seeded_documents

	where	demand_plan_id = p_demand_plan_id

	and	document_name	in ('MSD_LB_DETAILED_REPORT','MSD_LB_SUMMARY_REPORT'))

	and	dimension_code = 'PRD'

	and	selection_type = 'L'

	and	selection_value	in ('1','2');
Line: 7092

select compile_designator

	from msc_plans

	where	plan_id	=	p_supply_plan_id;
Line: 7148

select curr_start_date

	from msc_plans

	where	plan_id	=	p_supply_plan_id;
Line: 7216

select curr_cutoff_date

	from msc_plans

	where	plan_id	=	p_supply_plan_id;
Line: 7282

select parameter_id

from msd_dp_parameters

where	demand_plan_id = p_demand_plan_id

and	parameter_type = p_parameter_type

and	nvl(parameter_name,'123456789')	=	nvl(p_parameter_name,'123456789');
Line: 7296

select scenario_id

from msd_dp_scenarios

where	demand_plan_id = p_demand_plan_id

and	forecast_based_on	=	p_parameter_type

and	nvl(parameter_name,'123456789')	=	nvl(p_parameter_name,'123456789');
Line: 7372

select formula_id

from msd_dp_formulas

where	demand_plan_id = p_demand_plan_id

and	formula_name = p_formula_name

and	nvl(supply_plan_name,'123456789')	=	nvl(p_supply_plan_name,'123456789');
Line: 7426

select calendar_code

from msd_dp_calendars

where	demand_plan_id = p_demand_plan_id

and	calendar_type	=	decode(p_old_output_period_type_id,1,2,2,2,3,3,4,3,5,3,6,1,7,1,8,1,10,4,11,4,12,4,13,4);
Line: 7472

select min(mdh.hierarchy_id)

from msd_dp_dimensions mdd,

	msd_dp_hierarchies mdh,

	msd_hierarchies	mh

where	mdd.dimension_code =

	(select	dimension_code

	 from	msd_hierarchies

	 where hierarchy_id	=	p_hierarchy_id)	and

	 mdh.dp_dimension_code=mdd.dp_dimension_code and

	 mdh.demand_plan_id=p_demand_plan_id and

	 mdd.demand_plan_id=p_demand_plan_id and

	 mdd.dimension_code=mh.dimension_code	and

	 mh.hierarchy_id=mdh.hierarchy_id;
Line: 7502

select count(mdh.hierarchy_id)

from msd_dp_hierarchies	mdh

where

mdh.demand_plan_id=p_demand_plan_id	and

mdh.hierarchy_id=p_hierarchy_id;
Line: 7568

select min(ml.level_id)

from msd_dp_dimensions mdd,

	msd_dp_hierarchies mdh,

	msd_hierarchies	mh,

	msd_hierarchy_levels mhl,

	msd_levels ml

where	mdd.dimension_code =

	(select	dimension_code

	 from	msd_hierarchies

	 where hierarchy_id	=	mh.hierarchy_id) and

	 mdh.dp_dimension_code=mdd.dp_dimension_code and

	 mdh.demand_plan_id=p_level_id and

	 mdd.demand_plan_id=p_level_id and

	 mdd.dimension_code=mh.dimension_code	and

	 mh.hierarchy_id=mdh.hierarchy_id	and

	 mhl.hierarchy_id=mh.hierarchy_id	and

	 (mhl.level_id=ml.level_id or	mhl.parent_level_id=ml.level_id) and

	 ml.level_type_code	=	(select	distinct level_type_code from	msd_levels where level_id=p_level_id);
Line: 7608

select count(mdh.hierarchy_id)

from msd_dp_hierarchies	mdh,

msd_hierarchy_levels mhl

where

mdh.demand_plan_id=p_demand_plan_id	and

mhl.hierarchy_id=mdh.hierarchy_id	and

(mhl.level_id=p_level_id or	mhl.parent_level_id=p_level_id);
Line: 7678

select count(*)

from msd_dp_dimensions

where	dimension_code=p_dimension_code	and

demand_plan_id=p_demand_plan_id;
Line: 7734

select count(*)

from msd_dp_dimensions

where	dimension_code=p_dimension_code	and

demand_plan_id=p_demand_plan_id;
Line: 7780

select count(*)	from
msd_dp_scenarios
where	demand_plan_id = p_new_dp_id
and	supply_plan_flag = 'Y'
and associate_parameter is not null;
Line: 7787

select scenario_name,	description, demand_plan_id, scenario_id
		from msd_dp_scenarios
		where	supply_plan_flag = 'Y'
		and	demand_plan_id =
		(select	demand_plan_id
		from msd_demand_plans
		where	plan_type	=	'EOL'
		and	template_flag	=	'Y'
		and	default_template = 'Y'
		);
Line: 7812

			update msd_dp_scenarios set supply_plan_name=p_supply_plan_name, supply_plan_id=p_supply_plan_id
			where demand_plan_id=p_new_dp_id
			and supply_plan_flag='Y'
			and associate_parameter is not null
			and supply_plan_id<>p_supply_plan_id;
Line: 7820

					select msd_dp_scenarios_s.nextval	into l_scenario_id from	dual;
Line: 7826

	 				insert into	msd_dp_scenarios
					( demand_plan_id
					  ,scenario_id
					  ,scenario_name
					  ,description
					  ,output_period_type
					  ,horizon_start_date
					  ,horizon_end_date
					  ,forecast_date_used
					  ,forecast_based_on
					  ,last_update_date
					  ,last_updated_by
					  ,creation_date
					  ,created_by
					  ,last_update_login
					  ,request_id
					  ,program_application_id
					  ,program_id
					  ,program_update_date
					  ,attribute_category
					  ,attribute1
					  ,attribute2
					  ,attribute3
					  ,attribute4
					  ,attribute5
					  ,attribute6
					  ,attribute7
					  ,attribute8
					  ,attribute9
					  ,attribute10
					  ,attribute11
					  ,attribute12
					  ,attribute13
					  ,attribute14
					  ,attribute15
					  ,scenario_type
					  ,status
					  ,history_start_date
					  ,history_end_date
					  ,publish_flag
					  ,enable_flag
					  ,price_list_name
					  ,last_revision
					  ,parameter_name
					  ,consume_flag
					  ,error_type
					  ,supply_plan_id
					  ,deleteable_flag
					  ,supply_plan_flag
					  ,supply_plan_name
					  ,dmd_priority_scenario_id 									 --	Bug	4710963
					  ,associate_parameter
					  ,sc_type)
					  (select
						p_new_dp_id
					  ,l_scenario_id
					  ,l_name
					  ,l_description
					  ,output_period_type
					  ,null
					  ,null
					  ,forecast_date_used
					  ,forecast_based_on
					  ,SYSDATE
					  ,fnd_global.user_id
					  ,SYSDATE
					  ,fnd_global.user_id
					  ,fnd_global.login_id
					  ,NULL
					  ,NULL
					  ,NULL
					  ,SYSDATE
					  ,attribute_category
					  ,attribute1
					  ,attribute2
					  ,attribute3
					  ,attribute4
					  ,attribute5
					  ,attribute6
					  ,attribute7
					  ,attribute8
					  ,attribute9
					  ,attribute10
					  ,attribute11
					  ,attribute12
					  ,attribute13
					  ,attribute14
					  ,attribute15
					  ,scenario_type
					  ,status
					  ,null
					  ,null
					  ,publish_flag
					  ,enable_flag
					  ,price_list_name
					  ,last_revision
					  ,parameter_name
					  ,consume_flag
					  ,error_type
					  ,p_supply_plan_id
					  ,deleteable_flag
					  ,supply_plan_flag
					  ,p_supply_plan_name																					 --	Bug	4729854
					  ,dmd_priority_scenario_id																		 --	Bug	4710963
					  ,associate_parameter
					  ,sc_type
						from msd_dp_scenarios
						where	scenario_id	=	c2_rec.scenario_id
						and	demand_plan_id = c2_rec.demand_plan_id);
Line: 7936

						insert	into msd_dp_scenarios_tl
				 ( demand_plan_id
					 ,scenario_id
					 ,description
					 ,language
					 ,source_lang
					 ,creation_date
					 ,created_by
					 ,last_update_date
					 ,last_updated_by
					 ,last_update_login
					 ,request_id
					 ,program_application_id
					 ,program_id
					 ,program_update_date
		 )
	select
						p_new_dp_id
					 ,l_scenario_id
					 ,l_description
					 ,USERENV('LANG')
					 ,USERENV('LANG')
					 ,SYSDATE
					 ,fnd_global.user_id
					 ,SYSDATE
					 ,fnd_global.user_id
					 ,fnd_global.login_id
					 ,NULL
					 ,NULL
					 ,NULL
					 ,SYSDATE
		from dual;
Line: 7970

		insert into	msd_dp_scenario_events
		(
		demand_plan_id
		,scenario_id
		,event_id
		,last_update_date
		,last_updated_by
		,creation_date
		,created_by
		,last_update_login
		,request_id
		,program_application_id
		,program_id
		,program_update_date
		,event_association_priority)
		(select
		p_new_dp_id
		,l_scenario_id
		,event_id
		,last_update_date
		,last_updated_by
		,creation_date
		,created_by
		,last_update_login
		,request_id
		,program_application_id
		,program_id
		,program_update_date
		,event_association_priority
		from msd_dp_scenario_events
		where	scenario_id	=	c2_rec.scenario_id
		and	demand_plan_id = c2_rec.demand_plan_id);
Line: 8003

insert into	msd_dp_scenario_output_levels
		(
		 demand_plan_id
		 ,scenario_id
		 ,level_id
		 ,last_update_date
		 ,last_updated_by
		 ,creation_date
		 ,created_by
		 ,last_update_login
		 ,request_id
		 ,program_application_id
		 ,program_id
		 ,program_update_date)
		 (select
		 p_new_dp_id
		 ,l_scenario_id
		 ,level_id
		 ,SYSDATE
		 ,fnd_global.user_id
		 ,SYSDATE
		 ,fnd_global.user_id
		 ,fnd_global.login_id
		 ,NULL
		 ,NULL
		 ,NULL
		 ,SYSDATE
		 from	msd_dp_scenario_output_levels
		where	scenario_id	=	c2_rec.scenario_id
		and	demand_plan_id = c2_rec.demand_plan_id);