DBA Data[Home] [Help]

APPS.MSD_TRANSLATE_FACT_DATA SQL Statements

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

Line: 35

                        p_delete_flag       IN  VARCHAR2,
                        p_collect_ISO       IN  NUMBER   DEFAULT SYS_NO,             /* Bug# 4615390 ISO, Bug# 4865396 */
                        p_order_type_flag   IN  NUMBER   DEFAULT C_ALL,              /* Bug# 4747555*/
                        p_order_type_ids    IN  VARCHAR2 DEFAULT NULL) IS


v_instance_id    varchar2(40);
Line: 59

	-	   to identify whether we need to insert the
	-	   data into the staging tables or the
	-	   fact tables.
	-	3. Check for the Data Duplication, we should
	-	   use the shipped_date for this
 fact data.
	-	4. Insert the Data accordingly into the
	-	   Staging or the Fact table based on the
	-	   MSD_SR_SHIPMENT_DATA_V.
	-	5. Commit
	****************************************************/


        retcode :=0;
Line: 92

	   /* Physically delete existing data before inserting new rows*/
           v_sql_stmt := 'DELETE FROM msd_st_shipment_data '||
                        ' WHERE  instance = ''' || p_instance_id || '''' ;
Line: 97

           if p_delete_flag = 'Y' then
               EXECUTE IMMEDIATE v_sql_stmt
               USING nvl(p_from_date, C_FROM_DATE),
                     nvl(p_to_date, C_TO_DATE);
Line: 112

           /* DWK  Added sr_original_item_pk to insert stmt */
           /* Bug# 4615390 ISO , added ORDER_SOURCE_ID to the insert stmt */
           v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		' (instance, inv_org, item, customer, sales_channel, '||
		'sales_rep, ship_to_loc, user_defined1, user_defined2, '||
		'sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		'sr_sales_rep_pk, sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
		'booked_date, requested_date, promised_date, shipped_date, ' ||
		'scheduled_ship_date, scheduled_arrival_date, amount, qty_shipped, creation_date, created_by, ' ||
		'last_update_date, last_updated_by, last_update_login, '||
                'sr_original_item_pk, sr_parent_item_pk, sr_demand_class_pk, ORDER_SOURCE_ID ) '||
	        'SELECT '''||p_instance_id ||
        	''', inv_org, item, customer, sales_channel, sales_rep, '||
        	'ship_to_loc, user_defined1, user_defined2, '||
		'nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
		'nvl(sr_sales_rep_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
		'booked_date,'||
        	'requested_date, promised_date, shipped_date, scheduled_ship_date, scheduled_arrival_date, amount, '||
        	'qty_shipped, sysdate, '|| FND_GLOBAL.USER_ID ||
		', sysdate, '|| FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||
                ', to_char(sr_original_item_pk), to_char(sr_parent_item_pk), to_char(sr_demand_class_pk) ' ||
                ', ORDER_SOURCE_ID ' ||
		'FROM ' || p_source_table ||' where 1 = 1';
Line: 155

           /* Mark delete for overlapping rows and  Update its last_refresh_num */

           v_sql_stmt := ' UPDATE msd_shipment_data ' ||
			 ' SET	last_refresh_num = ' || p_new_refresh_num ||
			 ', Action_code = ' || '''D''' ||
			 ' WHERE Action_code = ''I'' and instance = '||p_instance_id || v_date_range;
Line: 167

           /* DWK  Added sr_original_item_pk to insert stmt */
           /* Bug# 4615390 ISO , added ORDER_SOURCE_ID to the insert stmt */
           v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		' (instance, inv_org, item, customer, sales_channel, '||
		'sales_rep, ship_to_loc, user_defined1, user_defined2, '||
		'sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		'sr_sales_rep_pk, sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
		'booked_date, requested_date, promised_date, shipped_date, ' ||
		'scheduled_ship_date, scheduled_arrival_date, amount, ' ||
                'qty_shipped, creation_date, created_by, ' ||
		'last_update_date, last_updated_by, last_update_login, '||
                'last_refresh_num, created_by_refresh_num, action_code, '||
                'sr_original_item_pk, sr_parent_item_pk, sr_demand_class_pk, ORDER_SOURCE_ID ) '||
	        'SELECT '''||p_instance_id ||
        	''', inv_org, item, customer, sales_channel, sales_rep, '||
        	'ship_to_loc, user_defined1, user_defined2, '||
		'nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
		'nvl(sr_sales_rep_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
		'booked_date,'||
        	'requested_date, promised_date, shipped_date,  ' ||
                'scheduled_ship_date, scheduled_arrival_date, ' ||
        	'amount, qty_shipped, sysdate, '|| FND_GLOBAL.USER_ID ||
		', sysdate, '|| FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||
                ', '|| p_new_refresh_num || ', ' || p_new_refresh_num || ', '|| '''I''' ||
                ', to_char(sr_original_item_pk), to_char(sr_parent_item_pk), to_char(sr_demand_class_pk) ' ||
                ', ORDER_SOURCE_ID ' ||
		'FROM ' || p_source_table ||' where 1 = 1';
Line: 204

           /* DWK. if the source is from staging table, then we shouldn't insert instance = '0'
              rows into fact table*/
           if (p_source_table = MSD_COMMON_UTILITIES.SHIPMENT_STAGING_TABLE) then
              v_sql_stmt := v_sql_stmt || ' and nvl(instance,''888'') <> '||'''0''';
Line: 220

            select 1 into v_ref_num
              from msd_cs_data_headers
             where cs_definition_id in (select cs_definition_id
            from msd_cs_definitions
            where name = 'MSD_SHIPMENT_HISTORY');
Line: 226

            update msd_cs_data_headers
            set last_refresh_num = p_new_refresh_num
            where cs_definition_id in (select cs_definition_id
            from msd_cs_definitions
            where name in ('MSD_SHIPMENT_HISTORY','MSD_SHIPMENT_ORIG_HISTORY'));
Line: 267

                        p_delete_flag       IN  VARCHAR2,
                        p_collect_ISO       IN  NUMBER   DEFAULT SYS_NO,             /* Bug# 4615390 ISO, Bug# 4865396 */
                        p_order_type_flag   IN  NUMBER   DEFAULT C_ALL,              /* Bug# 4747555*/
                        p_order_type_ids    IN  VARCHAR2 DEFAULT NULL) IS


v_instance_id    varchar2(40);
Line: 291

	-	   to identify whether we need to insert the
	-	   data into the staging tables or the
	-	   fact tables.
	-	3. Check for the Data Duplication, we should
	-	   use the shipped_date for this fact data.
	-	4. Insert the Data accordingly into the
	-	   Staging or the Fact table based on the
	-	   MSD_SR_BOOKING_DATA_V.
	-	5. Commit
	****************************************************/

	retcode :=0;
Line: 321

	   /* Physically delete existing data before inserting new rows*/
           v_sql_stmt := 'DELETE FROM msd_st_booking_data '||
                        ' WHERE  instance = ''' || p_instance_id || '''' ;
Line: 326

           if p_delete_flag = 'Y' then
               EXECUTE IMMEDIATE v_sql_stmt
               USING nvl(p_from_date, C_FROM_DATE ),
                     nvl(p_to_date, C_TO_DATE );
Line: 341

           /* DWK  Added sr_original_item_pk to insert stmt */
           /* Bug# 4615390 ISO , added ORDER_SOURCE_ID to the insert stmt */
           v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		' (instance, inv_org, item, customer, sales_channel, '||
		'sales_rep, ship_to_loc, user_defined1, user_defined2, '||
		'sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		'sr_sales_rep_pk, sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
		'booked_date, requested_date, promised_date, '||
		'scheduled_date, scheduled_arrival_date, ' ||
		'amount, qty_ordered, creation_date, created_by, ' ||
		'last_update_date, last_updated_by, last_update_login, '||
                'sr_original_item_pk, sr_parent_item_pk, sr_demand_class_pk, ORDER_SOURCE_ID) '||
	        'SELECT '''||p_instance_id ||
        	''', inv_org, item, customer, sales_channel, sales_rep, '||
        	'ship_to_loc, user_defined1, user_defined2, '||
                'nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
                'nvl(sr_sales_rep_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
		'booked_date,'||
        	'requested_date, promised_date, scheduled_ship_date, scheduled_arrival_date , '||
        	'amount, qty_ordered, sysdate, '|| FND_GLOBAL.USER_ID ||
		', sysdate, '|| FND_GLOBAL.USER_ID || ', '|| FND_GLOBAL.USER_ID ||
                ', to_char(sr_original_item_pk), ' ||
                '  to_char(sr_parent_item_pk), to_char(sr_demand_class_pk), ORDER_SOURCE_ID ' ||
		'from ' || p_source_table ||' where 1 = 1';
Line: 386

           /* Mark delete for overlapping rows and  Update its last_refresh_num */

           v_sql_stmt := ' UPDATE msd_booking_data ' ||
			 ' SET	last_refresh_num = ' || p_new_refresh_num ||
			 ', Action_code = ' || '''D''' ||
			 ' WHERE Action_code = ''I'' and instance = '||p_instance_id || v_date_range;
Line: 397

           /* Bug# 4615390 ISO , added ORDER_SOURCE_ID to the insert stmt */
           v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		' (instance, inv_org, item, customer, sales_channel, '||
		'sales_rep, ship_to_loc, user_defined1, user_defined2, '||
		'sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		'sr_sales_rep_pk, sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
		'booked_date, requested_date, promised_date, '||
		'scheduled_date, scheduled_arrival_date, ' ||
		'amount, qty_ordered, creation_date, created_by, ' ||
		'last_update_date, last_updated_by, last_update_login, '||
                'last_refresh_num, created_by_refresh_num, action_code, '||
                'sr_original_item_pk, sr_parent_item_pk, sr_demand_class_pk, ORDER_SOURCE_ID ) '||
	        'SELECT '''||p_instance_id ||
        	''', inv_org, item, customer, sales_channel, sales_rep, '||
        	'ship_to_loc, user_defined1, user_defined2, '||
                'nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
                'nvl(sr_sales_rep_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                'nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
		'booked_date,'||
        	'requested_date, promised_date, scheduled_date, scheduled_arrival_date, '||
        	'amount, qty_ordered, sysdate, '|| FND_GLOBAL.USER_ID ||
		', sysdate, '|| FND_GLOBAL.USER_ID || ', '|| FND_GLOBAL.USER_ID ||
                ', '|| p_new_refresh_num || ', ' || p_new_refresh_num || ', '|| '''I''' ||
                ', to_char(sr_original_item_pk), to_char(sr_parent_item_pk), to_char(sr_demand_class_pk) ' ||
                ', ORDER_SOURCE_ID ' ||
		'from ' || p_source_table ||' where 1 = 1';
Line: 432

           /* DWK. if the source is from staging table, then we shouldn't insert instance = '0'
              rows into fact table*/
           if (p_source_table = MSD_COMMON_UTILITIES.BOOKING_STAGING_TABLE) then
              v_sql_stmt := v_sql_stmt || ' and nvl(instance,''888'') <> '||'''0''';
Line: 448

            select 1 into v_ref_num
              from msd_cs_data_headers
             where cs_definition_id in (select cs_definition_id
            from msd_cs_definitions
            where name = 'MSD_BOOKING_HISTORY');
Line: 454

            update msd_cs_data_headers
            set last_refresh_num = p_new_refresh_num
            where cs_definition_id in (select cs_definition_id
            from msd_cs_definitions
            where name in ('MSD_BOOKING_HISTORY','MSD_BOOKING_ORIG_HISTORY'));
Line: 497

/* Cursor for delete */
/* Changed for bug # 3752937. Only those records should be deleted which are in staging */
CURSOR c_delete IS
SELECT from_uom_class, to_uom_class,
from_uom_code, to_uom_code,
base_uom_flag, sr_item_pk
FROM msd_uom_conversions
WHERE instance = p_instance_id
INTERSECT
SELECT from_uom_class, to_uom_class,
from_uom_code, to_uom_code,
base_uom_flag, sr_item_pk
FROM msd_st_uom_conversions
WHERE instance = p_instance_id;
Line: 512

/* Cursor for insert */
CURSOR c_insert IS
SELECT from_uom_class, to_uom_class,
from_uom_code, to_uom_code,
base_uom_flag, conversion_rate, sr_item_pk, item
FROM msd_st_uom_conversions
WHERE instance = p_instance_id and
      nvl(instance,-999) <> 0
MINUS
SELECT from_uom_class, to_uom_class,
from_uom_code, to_uom_code,
base_uom_flag, conversion_rate, sr_item_pk, item
FROM msd_uom_conversions
WHERE instance = p_instance_id and
      nvl(instance,-999) <> 0;
Line: 551

        -          to identify whether we need to insert the
        -          data into the staging tables or the
        -          fact tables.
        -       3. Do a complete refresh for this instance,
        -	   hence delete all the underlying values.
        -       4. Insert the Data accordingly into the
        -          Staging or the Fact table based on the
        -          MSD_SR_UOM_CONVERSION_V
        -       5. Commit
        ****************************************************/

	v_instance_id := p_instance_id;
Line: 566

             DELETE FROM msd_st_uom_conversions
             WHERE  instance = p_instance_id;
Line: 569

             v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		  ' ( INSTANCE, SR_ITEM_PK, ITEM, FROM_UOM_CLASS, TO_UOM_CLASS, ' ||
		  '   FROM_UOM_CODE, TO_UOM_CODE, BASE_UOM_FLAG, ' ||
		  '   CONVERSION_RATE, CREATION_DATE, CREATED_BY, ' ||
		  '   LAST_UPDATE_DATE, LAST_UPDATED_BY, LAST_UPDATE_LOGIN )'||
		  ' SELECT  ' || NVL(v_instance_id, 'INSTANCE') || ', ' ||
		  '   decode(SR_ITEM_PK, ''0'', null, SR_ITEM_PK), ITEM, FROM_UOM_CLASS, TO_UOM_CLASS, ' ||
		  '   FROM_UOM_CODE, TO_UOM_CODE, BASE_UOM_FLAG, ' ||
		  '   CONVERSION_RATE, sysdate, '|| FND_GLOBAL.USER_ID ||
                  ', sysdate, '|| FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||'  ' ||
		  ' from ' || p_source_table || ' where 1 = 1';
Line: 583

            OPEN c_delete;
Line: 584

            FETCH c_delete BULK COLLECT INTO a_from_uom_class, a_to_uom_class, a_from_uom_code,
                                             a_to_uom_code, a_base_uom_flag, a_sr_item_pk;
Line: 586

            CLOSE c_delete;
Line: 589

                  DELETE FROM msd_uom_conversions
                  WHERE instance = p_instance_id and
                        nvl(sr_item_pk,'NULL') = nvl(a_sr_item_pk(i), 'NULL') and
                        from_uom_class = a_from_uom_class(i) and
                        to_uom_class   = a_to_uom_class(i) and
                        from_uom_code = a_from_uom_code(i) and
                        to_uom_code = a_to_uom_code(i) and
                        base_uom_flag = a_base_uom_flag(i);
Line: 599

            OPEN c_insert;
Line: 600

            FETCH c_insert BULK COLLECT INTO a_from_uom_class, a_to_uom_class, a_from_uom_code,
                                             a_to_uom_code, a_base_uom_flag, a_conversion_rate,
                                             a_sr_item_pk, a_item;
Line: 603

            CLOSE c_insert;
Line: 607

                   INSERT INTO msd_uom_conversions(
                              INSTANCE, SR_ITEM_PK, ITEM, FROM_UOM_CLASS, TO_UOM_CLASS,
		              FROM_UOM_CODE, TO_UOM_CODE, BASE_UOM_FLAG,
		              CONVERSION_RATE, CREATION_DATE, CREATED_BY,
		              LAST_UPDATE_DATE, LAST_UPDATED_BY, LAST_UPDATE_LOGIN,
                              last_refresh_num, created_by_refresh_num, action_code)
                   VALUES ( p_instance_id, a_sr_item_pk(i), a_item(i),
                            a_from_uom_class(i), a_to_uom_class(i),
                            a_from_uom_code(i), a_to_uom_code(i), a_base_uom_flag(i),
                            a_conversion_rate(i), sysdate, FND_GLOBAL.USER_ID,
                            sysdate, FND_GLOBAL.USER_ID, FND_GLOBAL.USER_ID,
                            p_new_refresh_num, p_new_refresh_num, 'I');
Line: 656

        -          to identify whether we need to insert the
        -          data into the staging tables or the
        -          fact tables.
        -       3. Do a complete refresh for this instance,
        -          hence delete all the underlying values.
        -       4. Insert the Data accordingly into the
        -          Staging or the Fact table based on the
        -          MSD_SR_CURRENCY_CONVERSION_V
        -       5. Commit
        ****************************************************/

	retcode :=0;
Line: 669

		v_sql_stmt := 'DELETE FROM ' || p_dest_table ||
				' where 1 = 1';
Line: 672

		/* DWK. If dest_table is staging table, then we shouldn't delete
		   instance = '0' row */
		IF (p_dest_table = MSD_COMMON_UTILITIES.CURRENCY_STAGING_TABLE) THEN
		   v_sql_stmt := v_sql_stmt || ' and nvl(instance, ''888'')  <> '||'''0''';
Line: 692

                v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		  ' ( FROM_CURRENCY, TO_CURRENCY, ' ||
		  '   CONVERSION_DATE, CONVERSION_RATE, ' ||
		  '   CREATION_DATE, CREATED_BY, LAST_UPDATE_DATE, ' ||
		  '   LAST_UPDATED_BY, LAST_UPDATE_LOGIN )'||
		  ' SELECT ' ||
		  ' FROM_CURRENCY, TO_CURRENCY, ' ||
		  '   CONVERSION_DATE, CONVERSION_RATE, ' ||
		  '   sysdate, '|| FND_GLOBAL.USER_ID || ', sysdate, ' ||
		  FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||'  ' ||
		  'from ' || p_source_table || ' where 1 = 1';
Line: 711

  /* DWK. if the source is from staging table, then we shouldn't insert instance = '0'
     rows into fact table*/

	if p_source_table = MSD_COMMON_UTILITIES.CURRENCY_STAGING_TABLE then
		v_sql_stmt := v_sql_stmt || ' and nvl(instance, ''888'') <> '||'''0''';
Line: 727

	--insert into msd_test values(v_sql_stmt) ;
Line: 767

        -          to identify whether we need to insert the
        -          data into the staging tables or the
        -          fact tables.
        -       3. Check for the Data Duplication, we should
        -          use the ship_date  for this fact.
        -       4. Insert the Data accordingly into the
        -          Staging or the Fact table based on the
        -          MSD_SR_OPPORTUNITIES_DATA_V
        -       5. Commit
        ****************************************************/

		v_sql_stmt := 'DELETE FROM ' || p_dest_table ||
			      ' where instance = ''' || p_instance_id || '''' ;
Line: 793

                v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		  ' (instance, lead_number, interest_type, primary_interest_code, ' ||
		  '  secondary_interest_code, item, inv_org, quantity, amount, '||
		  '  customer, ship_to_loc, sales_channel, sales_rep, '||
		  '  user_defined1, user_defined2, ship_date, win_probability, '||
		  'sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		  'sr_sales_rep_pk, sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
		  '  status, creation_date, created_by, last_update_date, '||
		  '  last_updated_by, last_update_login ) '||
	        'select '''||p_instance_id ||
        	  ''', lead_number, interest_type, primary_interest_code, ' ||
		  '  secondary_interest_code, item, inv_org, quantity, amount, '||
		  '  customer, ship_to_loc, sales_channel, sales_rep, '||
		  '  user_defined1, user_defined2, nvl(ship_date, sysdate), win_probability, '||
                  'nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
                  'nvl(sr_sales_rep_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
		  '  status, sysdate, '|| FND_GLOBAL.USER_ID || ', sysdate, ' ||
                  FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||'  ' ||
		'from ' || p_source_table || ' where 1 = 1';
Line: 821

	 /* DWK. if the source is from staging table, then we shouldn't insert instance = '0'
	rows into fact table*/

	if p_source_table = MSD_COMMON_UTILITIES.OPPORTUNITY_STAGING_TABLE then
		v_sql_stmt := v_sql_stmt || ' and nvl(instance,''888'') <> '||'''0''';
Line: 868

        -          to identify whether we need to insert the
        -          data into the staging tables or the
        -          fact tables.
        -       3. Check for the Data Duplication, we should
        -          use the from_date, to_date and period_name
	-          for this fact.
        -       4. Insert the Data accordingly into the
        -          Staging or the Fact table based on the
        -          MSD_SR_SALES_FCST_V
        -       5. Commit
        ****************************************************/


	retcode :=0;
Line: 885

		v_sql_stmt := 'DELETE FROM ' || p_dest_table ||
		  ' where instance = ''' || p_instance_id ||'''' ;
Line: 915

                v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		  ' (instance, forecast_designator, inv_org, interest_type, ' ||
		  '  PRIMARY_INTEREST_CODE, SECONDARY_INTEREST_CODE, item, ' ||
		  '  CUSTOMER, SALES_CHANNEL, SALES_REP, SALES_GROUP, SHIP_TO_LOC, ' ||
		  '  USER_DEFINED1, USER_DEFINED2, PERIOD_NAME, PERIOD_START_DATE, ' ||
		  '  PERIOD_END_DATE, FORECAST_AMOUNT, UPSIDE_AMOUNT, QUOTA_AMOUNT, ' ||
		  'sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		  'sr_sales_rep_pk, sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
		  '  creation_date, created_by, last_update_date, '||
		  '  last_updated_by, last_update_login ) '||
	        'select '''||p_instance_id ||
                  ''', NULL, inv_org, interest_type, ' ||
                  '  PRIMARY_INTEREST_CODE, SECONDARY_INTEREST_CODE, item, ' ||
                  '  CUSTOMER, SALES_CHANNEL, SALES_REP, SALES_GROUP, SHIP_TO_LOC, ' ||
                  '  USER_DEFINED1, USER_DEFINED2, PERIOD_NAME, nvl(PERIOD_START_DATE, sysdate), ' ||
                  '  nvl(PERIOD_END_DATE, sysdate), FORECAST_AMOUNT, UPSIDE_AMOUNT, QUOTA_AMOUNT, ' ||
                  'nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
                  'nvl(sr_sales_rep_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
		  '  sysdate, '|| FND_GLOBAL.USER_ID || ', sysdate, ' ||
                  FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||'  ' ||
		  ' from ' || p_source_table || ' where 1 = 1';
Line: 968

		 /* DWK. if the source is from staging table, then we shouldn't insert instance = '0'
		rows into fact table*/

		IF p_source_table = MSD_COMMON_UTILITIES.SALES_FCST_STAGING_TABLE then
			v_sql_stmt := v_sql_stmt || ' and nvl(instance,''888'') <> '||'''0''';
Line: 1003

                        p_delete_flag       IN  VARCHAR2) IS

v_instance_id    varchar2(40);
Line: 1013

SELECT cs_definition_id
  FROM msd_cs_definitions
 WHERE name = p_cs_name;
Line: 1024

        -          to identify whether we need to insert the
        -          data into the staging tables or the
        -          fact tables.
        -       3. Check for the Data Duplication, we should
        -          use the forecast_designator for this fact.
        -       4. Insert the Data accordingly into the
        -          Staging or the Fact table based on the
        -          MSD_SR_MFG_FCST_V
        -       5. Commit
        ****************************************************/


	retcode :=0;
Line: 1044

            v_sql_stmt := ' DELETE FROM ' || p_dest_table ||
                          ' where instance =  ''' || p_instance_id || '''' ||
                          ' and forecast_designator = nvl(:p_fcst_desg, forecast_designator) ' ;
Line: 1050

           if p_delete_flag = 'Y' then
              EXECUTE IMMEDIATE v_sql_stmt USING p_fcst_desg ;
Line: 1057

           v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		  ' (instance, forecast_designator, prd_level_id, ITEM, INV_ORG, CUSTOMER, ' ||
		  '  SALES_CHANNEL, SHIP_TO_LOC, USER_DEFINED1, USER_DEFINED2, ' ||
		  '   BUCKET_TYPE, FORECAST_DATE, RATE_END_DATE, ' ||
		  '   ORIGINAL_QUANTITY, CURRENT_QUANTITY, ' ||
		  'sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		  'sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
		  '  creation_date, created_by, last_update_date, '||
		  '  last_updated_by, last_update_login, sr_demand_class_pk ) '||
	          'SELECT '''||p_instance_id ||
                  ''', forecast_designator, prd_level_id, ITEM, INV_ORG, CUSTOMER, ' ||
                  '  SALES_CHANNEL, SHIP_TO_LOC, USER_DEFINED1, USER_DEFINED2, ' ||
                  v_bucket_sql ||
                  '  FORECAST_DATE, RATE_END_DATE, ' ||
                  '   ORIGINAL_QUANTITY, CURRENT_QUANTITY, ' ||
                  'nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
                  'nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                  'nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
		  '  sysdate, '|| FND_GLOBAL.USER_ID || ', sysdate, ' ||
                   FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||',  ' ||
                  'to_char(sr_demand_class_pk) ' ||
		  ' FROM ' || p_source_table ||
                  ' WHERE  forecast_designator = nvl(:p_fcst_desg, forecast_designator) ';
Line: 1087

           v_sql_stmt := ' UPDATE msd_mfg_forecast ' ||
			 ' SET	last_refresh_num = ' || p_new_refresh_num ||
			 ', Action_code = ' || '''D''' ||
 			 ' WHERE Action_code = ''I'' and instance = ' ||
                            p_instance_id || ' and forecast_designator = ' ||
                          ' nvl(:p_fcst_desg, forecast_designator) ' ;
Line: 1095

           /* Delete Cs Data Headers */
           delete from msd_cs_data_headers
           where cs_definition_id = x_cs_id
           and instance = p_instance_id
           and cs_name = p_fcst_desg;
Line: 1102

           v_sql_stmt := 'INSERT INTO ' || p_dest_table ||
		  ' ( instance, forecast_designator, prd_level_id, ITEM, INV_ORG, CUSTOMER, ' ||
		  '   SALES_CHANNEL, SHIP_TO_LOC, USER_DEFINED1, USER_DEFINED2, ' ||
		  '   BUCKET_TYPE, FORECAST_DATE, RATE_END_DATE, ' ||
		  '   ORIGINAL_QUANTITY, CURRENT_QUANTITY, ' ||
		  '   sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk, '||
		  '   sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk, '||
                  '   last_refresh_num, created_by_refresh_num, action_code, '||
		  '   creation_date, created_by, last_update_date, '||
		  '   last_updated_by, last_update_login, sr_demand_class_pk ) '||
	          'SELECT '''||p_instance_id ||
                  ''', forecast_designator, prd_level_id, ITEM, INV_ORG, CUSTOMER, ' ||
                  '  SALES_CHANNEL, SHIP_TO_LOC, USER_DEFINED1, USER_DEFINED2, ' ||
                  '  bucket_type, FORECAST_DATE, RATE_END_DATE, ' ||
                  '  ORIGINAL_QUANTITY, CURRENT_QUANTITY, ' ||
                  '  nvl(sr_inv_org_pk, msd_sr_util.get_null_pk), ' ||
                  '  nvl(sr_item_pk, msd_sr_util.get_null_pk), ' ||
                  '  nvl(sr_customer_pk, msd_sr_util.get_null_pk), ' ||
                  '  nvl(sr_sales_channel_pk,  msd_sr_util.get_null_pk), '||
                  '  nvl(sr_ship_to_loc_pk, msd_sr_util.get_null_pk), ' ||
                  '  nvl(sr_user_defined1_pk, msd_sr_util.get_null_pk), ' ||
                  '  nvl(sr_user_defined2_pk, msd_sr_util.get_null_pk), '||
                     p_new_refresh_num || ', ' || p_new_refresh_num || ', '|| '''I''' ||
		  ', sysdate, '|| FND_GLOBAL.USER_ID || ', sysdate, ' ||
                     FND_GLOBAL.USER_ID ||', '|| FND_GLOBAL.USER_ID ||',  ' ||
                  '  to_char(sr_demand_class_pk) ' ||
		  ' FROM ' || p_source_table ||
		  ' WHERE  forecast_designator = nvl(:p_fcst_desg, forecast_designator) ';
Line: 1131

                 /* DWK. if the source is from staging table, then we shouldn't insert instance = '0'
		    rows into fact table*/
                 IF p_source_table = MSD_COMMON_UTILITIES.MFG_FCST_STAGING_TABLE then
                    v_sql_stmt := v_sql_stmt || ' and nvl(instance,''888'') <> '||'''0''';
Line: 1142

         INSERT INTO msd_cs_data_headers (
	   	CS_DATA_HEADER_ID,
         	INSTANCE,
		CS_DEFINITION_ID,
		CS_NAME,
		LAST_UPDATE_DATE,
		LAST_UPDATED_BY,
		CREATION_DATE,
		CREATED_BY,
    		LAST_UPDATE_LOGIN,
                LAST_REFRESH_NUM
	   )
       VALUES (	msd_cs_data_headers_s.nextval,
		p_instance_id,
		x_cs_id,
		p_fcst_desg,
		sysdate,
		fnd_global.user_id,
		sysdate,
		fnd_global.user_id,
		fnd_global.login_id,
                p_new_refresh_num
     	);
Line: 1198

        -          to identify whether we need to insert the
        -          data into the staging tables or the
        -          fact tables.
        -       3. Check for the Data Duplication, we should
        -          use the shipped_date for this fact data.
        -       4. Insert the Data accordingly into the
        -          Staging or the Fact table based on the
        -          MSD_SR_PRICE_LIST_V.
        -       5. Commit
        ****************************************************/

        retcode :=0;
Line: 1213

            v_sql_stmt := 'DELETE FROM ' || p_dest_table  ||
                          ' where  instance = ''' || p_instance_id || '''' ||
                          ' and price_list_name  like nvl(:p_price_list, price_list_name) ';
Line: 1219

                'INSERT INTO ' || p_dest_table ||
                ' (          INSTANCE,                                 ' ||
                '            ORGANIZATION_LVL_ID, SR_ORGANIZATION_LVL_PK, ' ||
                '            PRODUCT_LVL_ID,      SR_PRODUCT_LVL_PK,      ' ||
                '            SALESCHANNEL_LVL_ID, SR_SALESCHANNEL_LVL_PK, ' ||
                '            SALES_REP_LVL_ID,    SR_SALES_REP_LVL_PK,    ' ||
                '            GEOGRAPHY_LVL_ID,    SR_GEOGRAPHY_LVL_PK,    ' ||
                '            USER_DEFINED1_LVL_ID,SR_USER_DEFINED1_LVL_PK,' ||
                '            USER_DEFINED2_LVL_ID,SR_USER_DEFINED2_LVL_PK,' ||
                '            DEMAND_CLASS_LVL_ID, SR_DEMAND_CLASS_LVL_PK,' ||
                '            PRICE_LIST_NAME, START_DATE, END_DATE,    ' ||
                '            PRICE, PRIORITY,                          ' ||
                '            PRIMARY_UOM_FLAG, PRICE_LIST_UOM,         ' ||
                '            CREATION_DATE, CREATED_BY,                ' ||
                '            LAST_UPDATE_DATE, LAST_UPDATED_BY, LAST_UPDATE_LOGIN)  ' ||
                'SELECT ''' || p_instance_id ||
                ''',         nvl(ORGANIZATION_LVL_ID, 29) , nvl(SR_ORGANIZATION_LVL_PK,msd_sr_util.get_all_org_pk), ' ||
                '            nvl(PRODUCT_LVL_ID, 28) ,      nvl(SR_PRODUCT_LVL_PK,msd_sr_util.get_all_prd_pk),      ' ||
                '            nvl(SALESCHANNEL_LVL_ID, 33) ,  nvl(SR_SALESCHANNEL_LVL_PK,msd_sr_util.get_all_scs_pk), ' ||
                '            nvl(SALES_REP_LVL_ID, 32) ,    nvl(SR_SALES_REP_LVL_PK,msd_sr_util.get_all_rep_pk),    ' ||
                '            nvl(GEOGRAPHY_LVL_ID, 30) ,     nvl(SR_GEOGRAPHY_LVL_PK,msd_sr_util.get_all_geo_pk),    ' ||
                '            USER_DEFINED1_LVL_ID,nvl(SR_USER_DEFINED1_LVL_PK,msd_sr_util.get_null_pk),' ||
                '            USER_DEFINED2_LVL_ID,nvl(SR_USER_DEFINED2_LVL_PK,msd_sr_util.get_null_pk),' ||
                '            nvl(DEMAND_CLASS_LVL_ID, 40),  nvl(SR_DEMAND_CLASS_LVL_PK,msd_sr_util.get_null_pk),' ||
                '            PRICE_LIST_NAME, START_DATE, END_DATE,    ' ||
                '            PRICE, PRIORITY,                          ' ||
                '            PRIMARY_UOM_FLAG, PRICE_LIST_UOM,         ' ||
                '            SYSDATE,'|| FND_GLOBAL.USER_ID || ', '      ||
                '            SYSDATE,'|| FND_GLOBAL.USER_ID || ', '|| FND_GLOBAL.USER_ID ||' '||
                'FROM ' || p_source_table || '   ' ||
                'WHERE PRICE_LIST_NAME  like NVL(:p_price_list, PRICE_LIST_NAME) ';
Line: 1253

               UPDATE msd_price_list
               SET  Action_code = 'D', last_refresh_num =  p_new_refresh_num
               WHERE Action_code = 'I' and instance = p_instance_id and
                     price_list_name like p_price_list;
Line: 1258

               UPDATE msd_price_list
               SET  Action_code = 'D', last_refresh_num =  p_new_refresh_num
               WHERE Action_code = 'I' and instance = p_instance_id;
Line: 1265

                'INSERT INTO ' || p_dest_table ||
                ' (          INSTANCE,                                 ' ||
                '            ORGANIZATION_LVL_ID, SR_ORGANIZATION_LVL_PK, ' ||
                '            PRODUCT_LVL_ID,      SR_PRODUCT_LVL_PK,      ' ||
                '            SALESCHANNEL_LVL_ID, SR_SALESCHANNEL_LVL_PK, ' ||
                '            SALES_REP_LVL_ID,    SR_SALES_REP_LVL_PK,    ' ||
                '            GEOGRAPHY_LVL_ID,    SR_GEOGRAPHY_LVL_PK,    ' ||
                '            USER_DEFINED1_LVL_ID,SR_USER_DEFINED1_LVL_PK,' ||
                '            USER_DEFINED2_LVL_ID,SR_USER_DEFINED2_LVL_PK,' ||
                '            DEMAND_CLASS_LVL_ID, SR_DEMAND_CLASS_LVL_PK,' ||
                '            PRICE_LIST_NAME, START_DATE, END_DATE,    ' ||
                '            PRICE, PRIORITY,                          ' ||
                '            last_refresh_num, created_by_refresh_num, action_code, '||
                '            CREATION_DATE, CREATED_BY,                ' ||
                '            LAST_UPDATE_DATE, LAST_UPDATED_BY, LAST_UPDATE_LOGIN)  ' ||
                'SELECT ''' || p_instance_id ||
                ''',         nvl(ORGANIZATION_LVL_ID, 29) , nvl(SR_ORGANIZATION_LVL_PK,msd_sr_util.get_all_org_pk), ' ||
                '            nvl(PRODUCT_LVL_ID, 28) ,      nvl(SR_PRODUCT_LVL_PK,msd_sr_util.get_all_prd_pk),      ' ||
                '            nvl(SALESCHANNEL_LVL_ID, 33) , nvl(SR_SALESCHANNEL_LVL_PK,msd_sr_util.get_all_scs_pk), ' ||
                '            nvl(SALES_REP_LVL_ID, 32) ,    nvl(SR_SALES_REP_LVL_PK,msd_sr_util.get_all_rep_pk),    ' ||
                '            nvl(GEOGRAPHY_LVL_ID, 30) ,    nvl(SR_GEOGRAPHY_LVL_PK,msd_sr_util.get_all_geo_pk),    ' ||
                '            USER_DEFINED1_LVL_ID,nvl(SR_USER_DEFINED1_LVL_PK,msd_sr_util.get_null_pk),' ||
                '            USER_DEFINED2_LVL_ID,nvl(SR_USER_DEFINED2_LVL_PK,msd_sr_util.get_null_pk),' ||
                '            nvl(DEMAND_CLASS_LVL_ID, 40) , nvl(SR_DEMAND_CLASS_LVL_PK,msd_sr_util.get_all_geo_pk), ' ||
                '            PRICE_LIST_NAME, START_DATE, END_DATE,    ' ||
                '            PRICE, PRIORITY,                          ' ||
                             p_new_refresh_num || ', ' || p_new_refresh_num || ', '|| '''I''' || ', ' ||
                '            SYSDATE,'|| FND_GLOBAL.USER_ID || ', '      ||
                '            SYSDATE,'|| FND_GLOBAL.USER_ID || ', '|| FND_GLOBAL.USER_ID ||' '||
                'FROM ' || p_source_table || '   ' ||
                'WHERE PRICE_LIST_NAME  like NVL(:p_price_list, PRICE_LIST_NAME) ';
Line: 1296

                /* DWK. if the source is from staging table, then we shouldn't insert instance = '0'
		rows into fact table*/
                IF p_source_table = MSD_COMMON_UTILITIES.PRICING_STAGING_TABLE then
                   v_sql_stmt := v_sql_stmt || ' and nvl(instance,''888'') <> '||'''0''';
Line: 1323

   dates according to the calendar. We split raw entity by inserting all the sub
   entities into msd_mfg_forecast talbe and delete the original raw entity from
   that table.  When we insert sub entities into msd_mfg_forecast table, we join
   this table with msd_st_time table and only select days which is in between
   forecast_date and rate_end_date of individual raw entity.  This INSERT
   statement contains 3 SELECT statement according to raw entities bucket_type.
   We connect the results with UNION.  Only one SELECT statement will be
   executed due to different bucket_type condition.
   Once we insert all sub entity, we delte all raw entities, and delete
   all calendar dates we populated at the beginning.

   1) mfg_post_process will UPDATE the following rows
   -----------------------------------------------------------
   BUCKET_TYPE       ACTION
   -----------------------------------------------------------
   DAY               NONE
   WEEK              YES only if rate_end_date is NULL
   MONTH             YES only if rate_end_date is NULL

   2) mfg_post_process will EXPLODE the following rows
   -----------------------------------------------------------
   BUCKET_TYPE       ACTION
   -----------------------------------------------------------
   DAY               YES only if rate_end_date IS NOT NULL and
                                 rate_end_date <> forecast_date.
   WEEK              YES only if rate_end_date IS NOT NULL.
   MONTH             YES only if rate_end_date IS NOT NULL.

   3) mfg_post_process will DELETE the following rows
   -----------------------------------------------------------
   BUCKET_TYPE       ACTION
   -----------------------------------------------------------
   DAY               YES rate_end_date IS NOT NULL and
                         rate_end_date <> forecast_date
   WEEK              YES rate_end_date IS NOT NULL
   MONTH             YES rate_end_date IS NOT NULL
*/
PROCEDURE mfg_post_process( errbuf              OUT NOCOPY VARCHAR2,
                            retcode             OUT NOCOPY VARCHAR2,
			    p_instance          IN  VARCHAR2,
			    p_designator        IN  VARCHAR2,
                            p_new_refresh_num   IN  NUMBER) IS
   p_min_date    DATE;
Line: 1413

   select month_end_date from msd_st_time
   where instance = '-999' and day <= p_temp_end_date
   order by day desc;
Line: 1419

   /* Select min and max date for the forecast_date
      and rate_end_date. This will reduce the number of
      dates populate_calendar_dates will populate */

   SELECT min(forecast_date), max( nvl(rate_end_date, forecast_date)) INTO p_min_date, p_max_date
   FROM msd_mfg_forecast
   WHERE instance = p_instance AND
         created_by_refresh_num = p_new_refresh_num AND
         forecast_designator = nvl(p_designator,forecast_designator);
Line: 1429

/************************** Update forecast_date *********************************/

   /* First, Update forecast_date to bucket_end_date only if, it has NULL
      for rate_end_date.  Since we are not exploding any rows with NULL
      value in rate_end_date, we have to update forecast_date separately */

   /* First check if there is any row to be updated or not */
   select count(*) into l_count
   from msd_mfg_forecast
   where rate_end_date is null and
         bucket_type = '1' and
         instance = p_instance  and
         forecast_designator = nvl(p_designator, forecast_designator) and
         created_by_refresh_num = p_new_refresh_num and
         rownum < 2;
Line: 1447

      p_str :=    'UPDATE msd_mfg_forecast f ' ||
 		' SET  forecast_date = ' ||
                 ' nvl((SELECT t.week_end_date FROM msd_st_time t ' ||
                 '      WHERE  f.forecast_date = t.day and t.instance = '||
                 ''''|| -999 ||'''' ||'), f.forecast_date)
		WHERE f.rate_end_date is NULL and
			f.bucket_type = ' || '''' || 1 ||''''|| ' and
                        f.created_by_refresh_num = ' || p_new_refresh_num || ' and
 			f.instance = ' || ''''||p_instance ||'''' ||
                        ' and f.forecast_designator = nvl(:p_designator, f.forecast_designator) ';
Line: 1461

   /* First check if there is any row to be updated or not */
   select count(*) into l_count
   from msd_mfg_forecast
   where rate_end_date is null and
         bucket_type = '2' and
         instance = p_instance and
         forecast_designator = nvl(p_designator, forecast_designator) and
         rownum < 2;
Line: 1472

       p_str :=  ' UPDATE msd_mfg_forecast f ' ||
 		' SET  forecast_date = ' ||
                 '       nvl((SELECT t.month_end_date FROM msd_st_time t
 			     WHERE  f.forecast_date = t.day and t.instance = '||
                              '''' || -999 ||'''' ||'), f.forecast_date)
		WHERE f.rate_end_date is NULL and
			f.bucket_type = ' || '''' || 2 ||''''|| ' and
                        f.created_by_refresh_num = ' || p_new_refresh_num || ' and
 			f.instance = ' || ''''||p_instance ||'''' ||
                       ' and f.forecast_designator = nvl(:p_designator,f.forecast_designator) ';
Line: 1486

/******************************* Insert ****************************************/

   /* Find If there is any row needs to be exploded with Daily bucket.
      If so, delete those rows from fact table and cache them into arrary */

   DELETE FROM msd_mfg_forecast
   WHERE instance = p_instance AND
         forecast_designator = nvl(p_designator,forecast_designator) AND
         bucket_type = C_DAILY_BUCKET AND
         created_by_refresh_num = p_new_refresh_num AND
         forecast_date <> nvl(rate_end_date, forecast_date)
   RETURNING
         FORECAST_DESIGNATOR, PRD_LEVEL_ID, ITEM, INV_ORG, CUSTOMER,
         SALES_CHANNEL, SHIP_TO_LOC, USER_DEFINED1, USER_DEFINED2,
         BUCKET_TYPE, FORECAST_DATE, RATE_END_DATE,
         ORIGINAL_QUANTITY, CURRENT_QUANTITY,
         sr_inv_org_pk, sr_item_pk, sr_customer_pk, sr_sales_channel_pk,
         sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk,
         sr_demand_class_pk
   BULK COLLECT INTO
         a_FORECAST_DESIGNATOR, a_prd_level_id, a_ITEM, a_INV_ORG, a_CUSTOMER,
         a_SALES_CHANNEL, a_SHIP_TO_LOC, a_USER_DEFINED1, a_USER_DEFINED2,
         a_BUCKET_TYPE, a_FORECAST_DATE, a_RATE_END_DATE,
         a_ORIGINAL_QUANTITY, a_CURRENT_QUANTITY,
         a_sr_inv_org_pk, a_sr_item_pk, a_sr_customer_pk, a_sr_sales_channel_pk,
         a_sr_ship_to_loc_pk, a_sr_user_defined1_pk, a_sr_user_defined2_pk,
         a_sr_demand_class_pk;
Line: 1514

   /* Bulk INSERT cached rows with explosion, For Daily Bucket */
   IF (a_sr_item_pk.exists(1)) THEN
      FORALL i IN a_sr_item_pk.FIRST..a_sr_item_pk.LAST
         INSERT INTO msd_mfg_forecast(instance, forecast_designator, bucket_type,
		 	forecast_date, rate_end_date, original_quantity,
			current_quantity, creation_date, created_by,
			last_update_date, last_updated_by, last_update_login,
			sr_inv_org_pk, prd_level_id, sr_item_pk, sr_customer_pk,
			sr_sales_channel_pk, sr_ship_to_loc_pk,
			sr_user_defined1_pk, sr_user_defined2_pk,
                        sr_demand_class_pk,
                        created_by_refresh_num, last_refresh_num, action_code)
         SELECT p_instance, a_forecast_designator(i), a_bucket_type(i),
	        t.day, NULL, a_original_quantity(i),
		a_current_quantity(i), SYSDATE, FND_GLOBAL.USER_ID,
		SYSDATE, FND_GLOBAL.USER_ID, fnd_global.login_id,
		a_sr_inv_org_pk(i), a_prd_level_id(i), a_sr_item_pk(i), a_sr_customer_pk(i),
		a_sr_sales_channel_pk(i), a_sr_ship_to_loc_pk(i),
		a_sr_user_defined1_pk(i), a_sr_user_defined2_pk(i),
                a_sr_demand_class_pk(i),
                p_new_refresh_num, p_new_refresh_num, 'I'
         FROM
                msd_st_time t
         WHERE
                t.day between a_forecast_date(i) and a_rate_end_date(i) and
                t.instance = '-999';
Line: 1547

      If so, delete those rows from fact table and cache them into arrary */
   /* Also, rate_end_date can equal to forecast_date
      since we already update it */
   DELETE FROM msd_mfg_forecast
   WHERE instance = p_instance AND
         forecast_designator = nvl(p_designator,forecast_designator) AND
         bucket_type = C_WEEKLY_BUCKET AND
         created_by_refresh_num = p_new_refresh_num AND
         rate_end_date IS NOT NULL
   RETURNING
         FORECAST_DESIGNATOR, ITEM, INV_ORG, CUSTOMER,
         SALES_CHANNEL, SHIP_TO_LOC, USER_DEFINED1, USER_DEFINED2,
         BUCKET_TYPE, FORECAST_DATE, RATE_END_DATE,
         ORIGINAL_QUANTITY, CURRENT_QUANTITY,
         sr_inv_org_pk, prd_level_id, sr_item_pk, sr_customer_pk, sr_sales_channel_pk,
         sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk,
         sr_demand_class_pk
   BULK COLLECT INTO
         a_FORECAST_DESIGNATOR, a_ITEM, a_INV_ORG, a_CUSTOMER,
         a_SALES_CHANNEL, a_SHIP_TO_LOC, a_USER_DEFINED1, a_USER_DEFINED2,
         a_BUCKET_TYPE, a_FORECAST_DATE, a_RATE_END_DATE,
         a_ORIGINAL_QUANTITY, a_CURRENT_QUANTITY,
         a_sr_inv_org_pk, a_prd_level_id, a_sr_item_pk, a_sr_customer_pk, a_sr_sales_channel_pk,
         a_sr_ship_to_loc_pk, a_sr_user_defined1_pk, a_sr_user_defined2_pk,
         a_sr_demand_class_pk;
Line: 1573

   /* Bulk INSERT cached rows with explosion, For Weekly Bucket */
   IF (a_sr_item_pk.exists(1)) THEN
      FORALL i IN a_sr_item_pk.FIRST..a_sr_item_pk.LAST
         INSERT INTO msd_mfg_forecast(instance, forecast_designator, bucket_type,
		 	forecast_date, rate_end_date, original_quantity,
			current_quantity, creation_date, created_by,
			last_update_date, last_updated_by, last_update_login,
			sr_inv_org_pk, prd_level_id, sr_item_pk, sr_customer_pk,
			sr_sales_channel_pk, sr_ship_to_loc_pk,
			sr_user_defined1_pk, sr_user_defined2_pk,
                        sr_demand_class_pk,
                        created_by_refresh_num, last_refresh_num, action_code)
         SELECT p_instance, a_forecast_designator(i), a_bucket_type(i),
	        t.week_end_date, NULL, a_original_quantity(i),
		a_current_quantity(i), SYSDATE, FND_GLOBAL.USER_ID,
		SYSDATE, FND_GLOBAL.USER_ID, fnd_global.login_id,
		a_sr_inv_org_pk(i), a_prd_level_id(i), a_sr_item_pk(i), a_sr_customer_pk(i),
		a_sr_sales_channel_pk(i), a_sr_ship_to_loc_pk(i),
		a_sr_user_defined1_pk(i), a_sr_user_defined2_pk(i),
                a_sr_demand_class_pk(i),
                p_new_refresh_num, p_new_refresh_num, 'I'
         FROM
  	       (select distinct week_start_date,  week_end_date
                from msd_st_time
	        where instance = '-999') t
         WHERE
                t.week_start_date between a_forecast_date(i) and a_rate_end_date(i) or t.week_end_date between a_forecast_date(i) and a_rate_end_date(i);
Line: 1606

      If so, delete those rows from fact table and cache them into arrary */
   /* Also, rate_end_date can equal to forecast_date
      since we already update it */
   DELETE FROM msd_mfg_forecast
   WHERE instance = p_instance AND
         forecast_designator = nvl(p_designator,forecast_designator) AND
         bucket_type = C_MONTHLY_BUCKET AND
         created_by_refresh_num = p_new_refresh_num AND
         rate_end_date IS NOT NULL
   RETURNING
         FORECAST_DESIGNATOR, ITEM, INV_ORG, CUSTOMER,
         SALES_CHANNEL, SHIP_TO_LOC, USER_DEFINED1, USER_DEFINED2,
         BUCKET_TYPE, FORECAST_DATE, RATE_END_DATE,
         ORIGINAL_QUANTITY, CURRENT_QUANTITY,
         sr_inv_org_pk, prd_level_id, sr_item_pk, sr_customer_pk, sr_sales_channel_pk,
         sr_ship_to_loc_pk, sr_user_defined1_pk, sr_user_defined2_pk,
         sr_demand_class_pk
   BULK COLLECT INTO
         a_FORECAST_DESIGNATOR, a_ITEM, a_INV_ORG, a_CUSTOMER,
         a_SALES_CHANNEL, a_SHIP_TO_LOC, a_USER_DEFINED1, a_USER_DEFINED2,
         a_BUCKET_TYPE, a_FORECAST_DATE, a_RATE_END_DATE,
         a_ORIGINAL_QUANTITY, a_CURRENT_QUANTITY,
         a_sr_inv_org_pk, a_prd_level_id, a_sr_item_pk, a_sr_customer_pk, a_sr_sales_channel_pk,
         a_sr_ship_to_loc_pk, a_sr_user_defined1_pk, a_sr_user_defined2_pk,
         a_sr_demand_class_pk;
Line: 1632

   /* Bulk INSERT cached rows with explosion, For Monthly Bucket */
   IF (a_sr_item_pk.exists(1)) THEN
      FORALL i IN a_sr_item_pk.FIRST..a_sr_item_pk.LAST
         INSERT INTO msd_mfg_forecast(instance, forecast_designator, bucket_type,
		 	forecast_date, rate_end_date, original_quantity,
			current_quantity, creation_date, created_by,
			last_update_date, last_updated_by, last_update_login,
			sr_inv_org_pk, prd_level_id, sr_item_pk, sr_customer_pk,
			sr_sales_channel_pk, sr_ship_to_loc_pk,
			sr_user_defined1_pk, sr_user_defined2_pk,
                        sr_demand_class_pk,
                        created_by_refresh_num, last_refresh_num, action_code)
         SELECT p_instance, a_forecast_designator(i), a_bucket_type(i),
	        t.month_end_date, NULL, a_original_quantity(i),
		a_current_quantity(i), SYSDATE, FND_GLOBAL.USER_ID,
		SYSDATE, FND_GLOBAL.USER_ID, fnd_global.login_id,
		a_sr_inv_org_pk(i), a_prd_level_id(i), a_sr_item_pk(i), a_sr_customer_pk(i),
		a_sr_sales_channel_pk(i), a_sr_ship_to_loc_pk(i),
		a_sr_user_defined1_pk(i), a_sr_user_defined2_pk(i),
                a_sr_demand_class_pk(i),
                p_new_refresh_num, p_new_refresh_num, 'I'
         FROM
               (select distinct month_start_date, month_end_date
                from msd_st_time
	        where instance = '-999') t
         WHERE
                t.month_start_date between a_forecast_date(i) and a_rate_end_date(i);
Line: 1663

      update msd_mfg_forecast
      set bucket_type = C_DAILY_BUCKET
      WHERE instance = p_instance AND
      forecast_designator = nvl(p_designator,forecast_designator) AND
      bucket_type = C_WEEKLY_BUCKET AND
      created_by_refresh_num = p_new_refresh_num;
Line: 1685

   only insert working date into the table, since holiday and weekends will have
   NULL for seq_num.
*/
PROCEDURE populate_calendar_dates(p_cal_code   VARCHAR2,
				  p_min_date   DATE,
				  p_max_date   DATE,
				  p_dblink     VARCHAR2 ) IS

   p_cal_type    NUMBER;
Line: 1699

   p_str :=    'INSERT INTO msd_st_time(instance, calendar_code,
			calendar_type,seq_num, month_start_date,
			month_end_date, week_start_date,
			week_end_date, day,last_update_date,
			last_updated_by, creation_date, created_by,
			last_update_login)
                SELECT ' || '''-999''' || ', calendar_code, 1,
			seq_num, month_start_date,month_end_date, week_start_date, week_end_date, day,
			SYSDATE, FND_GLOBAL.USER_ID, SYSDATE, FND_GLOBAL.USER_ID, FND_GLOBAL.LOGIN_ID
                FROM    msd_sr_mfg_time_v' || p_dblink ||
              ' WHERE  seq_num <> -1 and calendar_code = :p_cal_code '||
                        ' AND day BETWEEN :p_min_date AND :p_max_date ';
Line: 1747

   /* Select min and max date for the forecast_date and rate_end_date. */
   l_str := 'SELECT min(forecast_date), max( nvl(rate_end_date, forecast_date))'||
	    ' FROM '||p_table_name|| ' WHERE instance = '||''''||p_instance||'''';
Line: 1762

   l_str := 'SELECT parameter_value FROM msd_setup_parameters'||
	l_dblink || ' WHERE parameter_name = '|| '''MSD_MASTER_ORG''';
Line: 1768

   l_str := 'SELECT calendar_code FROM mtl_parameters' ||
	l_dblink || ' WHERE organization_id = :l_org_id ';
Line: 1773

   /* DWK Delete existing calendar before populating the current one */
   DELETE msd_st_time WHERE instance = '-999';
Line: 1776

   /* Populate calendar dates. We will delete all these data
     after we finish exploiting entities */
   populate_calendar_dates(l_cal_code, l_min_date, l_max_date, l_dblink);
Line: 1811

   SELECT instance_type FROM msc_apps_instances
   WHERE to_char(instance_id) = p_instance;
Line: 1832

   SELECT count(*) INTO l_count FROM msd_mfg_forecast
   WHERE  instance = p_instance AND
          forecast_designator = nvl(p_designator,forecast_designator) AND
          (bucket_type <> C_DAILY_BUCKET OR
	   forecast_date <> nvl(rate_end_date, forecast_date)) and
-- VM created_by_refresh .....
          rownum < 2;
Line: 1866

   SELECT nvl(min(scn_build_refresh_num), 0) INTO l_least_refresh_num
   FROM msd_dp_parameters;
Line: 1870

   l_sql_stmt := ' DELETE FROM ' || p_table_name ||
                 ' WHERE ACTION_CODE = ' || '''D''' ||
                 ' and LAST_REFRESH_NUM <= ' || l_least_refresh_num;
Line: 1891

select cs_definition_id
  from msd_cs_definitions
 where name = p_name;
Line: 1905

  insert into msd_cs_data_headers
	(	cs_data_header_id,
		instance,
		cs_definition_id,
		cs_name,
		last_update_date,
		last_updated_by,
		creation_date,
		created_by,
		last_update_login,
                last_refresh_num
	)
         select	msd_cs_data_headers_s.nextval,
		p_instance,
	        x_cs_id,
		'SINGLE_STREAM',
		sysdate,
		fnd_global.user_id,
		sysdate,
		fnd_global.user_id,
		fnd_global.login_id,
                p_ref_num from dual;