DBA Data[Home] [Help]

APPS.AP_PURGE_PKG SQL Statements

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

Line: 87

   UPDATE financials_purges
   SET status = P_Status
   WHERE purge_name = P_Purge_Name;
Line: 136

      /* Bug#2274656 Selecting Recon Accounting Flag also in this program unit */
  SELECT DECODE(ASP.accounting_method_option, 'Accrual',                     'Y',
         DECODE(ASP.secondary_accounting_method,
                   'Accrual', 'Y', 'N')),
         DECODE(ASP.accounting_method_option,'Cash','Y',
         DECODE(ASP.secondary_accounting_method,
                   'Cash',    'Y', 'N')),
         nvl(ASP.RECON_ACCOUNTING_FLAG,'N')
  INTO   p_using_accrual_basis,
         p_using_cash_basis,
         p_recon_acctg_flag
  FROM   ap_system_parameters ASP;
Line: 200

  select count(1)
  into invoice_count
  from ap_purge_invoice_list
  where double_check_flag = 'Y';
Line: 208

     select count(1)
     into po_count
     from po_purge_po_list
     where double_check_flag = 'Y';
Line: 216

        select count(1)
        into req_count
        from po_purge_req_list
        where double_check_flag = 'Y';
Line: 224

            select count(1)
            into vendor_count
            from po_purge_vendor_list
            where double_check_flag = 'Y';
Line: 345

  delete from chv_purge_schedule_list cpsl
  where exists (select null
                from chv_cum_periods ccp,
                     chv_schedule_items csi,
                     chv_schedule_headers csh,
                     chv_org_options coo
                where ccp.organization_id  = g_organization_id
                and   sysdate between ccp.cum_period_start_date and
                                      NVL(ccp.cum_period_end_date,sysdate + 1)
                and  coo.organization_id = ccp.organization_id
                and  coo.enable_cum_flag = 'Y'
                and  csh.schedule_id = csi.schedule_id
                and  csh.schedule_horizon_start >= ccp.cum_period_start_date
                and  csi.schedule_item_id = cpsl.schedule_item_id);
Line: 396

  delete from chv_purge_schedule_list cpsl
  where exists (select null
                from   chv_schedule_items csi,
                       ece_spso_items esi
                where  csi.schedule_item_id = cpsl.schedule_item_id
                and    csi.schedule_id = esi.schedule_id);
Line: 424

     Because performance of delete stmt in do_dependent_inv_checks was very poor.
     This function does same check with the delete stmt.
  */

 TYPE tab_status_type IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
Line: 437

  select pl.invoice_id
    from ap_purge_invoice_list pl,
         ap_invoice_payments ip
   where pl.invoice_id = ip.invoice_id;
Line: 443

  select invoice_id
    from ap_purge_invoice_list
   where invoice_id = l_invoice_id
     and double_check_flag = 'Y';
Line: 465

  select pil.invoice_id
    from ap_invoice_payments ip,
         ap_purge_invoice_list pil
   where ip.check_id = l_check_id
     and ip.invoice_id = pil.invoice_id (+) ;
Line: 510

  select check_id
    from ap_invoice_payments
   where invoice_id = l_invoice_id ;
Line: 583

            UPDATE ap_purge_invoice_list
               SET double_check_flag = 'S'
             WHERE invoice_id = p_id ;
Line: 591

        /* if this chain is not purgeable, delete selected invoice from purge list */
        p_count := tab_inv.count;
Line: 598

            DELETE FROM ap_purge_invoice_list
              WHERE invoice_id = p_id ;
Line: 603

        /* delete unpurgeable list beforehand for performance */
        p_count := tab_check.count;
Line: 611

            DELETE FROM ap_purge_invoice_list
            WHERE invoice_id in ( select invoice_id
                from ap_invoice_payments
                where check_id = p_id);
Line: 625

  update ap_purge_invoice_list
    set double_check_flag = 'Y'
   where double_check_flag = 'S' ;
Line: 678

   DELETE
   FROM ap_purge_invoice_list PL
   WHERE EXISTS (
	SELECT 'payment schedule not purgeable'
	FROM ap_payment_schedules PS,
	     ap_invoices I
	WHERE PS.invoice_id = PL.invoice_id
	AND   PS.invoice_id = I.invoice_id
	AND ((PS.payment_status_flag <> 'Y'
        AND  I.cancelled_date is null)
        OR   PS.last_update_date > g_activity_date));
Line: 700

     DELETE
     FROM ap_purge_invoice_list PL
     WHERE EXISTS
	(SELECT 'project-related vendor invoices'
	FROM	ap_invoice_distributions d
	WHERE	d.invoice_id = pl.invoice_id
	AND	d.project_id is not null)   -- bug1746226
        OR EXISTS
	   (SELECT 'project-related expense report'
	    FROM   ap_invoices i
	    WHERE  i.invoice_id = pl.invoice_id
	    AND	   i.source = 'Oracle Project Accounting');
Line: 737

      DELETE
      FROM ap_purge_invoice_list PL
      WHERE EXISTS
              (SELECT 'distributions not purgeable'
                 FROM ap_invoice_distributions D, ap_invoices I
                WHERE I.invoice_id = D.invoice_id
                  AND PL.invoice_id = D.invoice_id
       	          AND (   D.last_update_date > g_activity_date
       		       OR D.posted_flag <> 'Y'
       		       OR D.accrual_posted_flag  =
       		          DECODE(p_using_accrual_basis,
                                 'Y', 'N',
                                 'Z')
       	               OR D.cash_posted_flag =
       		          DECODE(p_using_cash_basis,
                                 'Y', DECODE(D.cash_posted_flag,
                                             'N', 'N',
		                             'P', 'P',
                                             'Z'),
                                 'Z')
       		       OR D.po_distribution_id IS NOT NULL
       		       OR (    D.assets_addition_flag||'' =
       		               DECODE(g_assets_status,
                               'Y', 'U',
                               'cantequalme')
                           AND I.cancelled_date IS NULL)));
Line: 767

     DELETE
     FROM ap_purge_invoice_list PL
     WHERE EXISTS
              (SELECT 'distributions not purgeable'
	 	 FROM ap_invoice_distributions D, ap_invoices I
	 	WHERE I.invoice_id = D.invoice_id
                  AND PL.invoice_id = D.invoice_id
         	  AND (   D.last_update_date > g_activity_date
              	       OR D.posted_flag <> 'Y'
                       OR D.accrual_posted_flag =
            	          DECODE(p_using_accrual_basis,
                                 'Y', 'N',
                                 'Z')
              	       OR D.cash_posted_flag =
              	          DECODE(p_using_cash_basis,
                                 'Y', DECODE(D.cash_posted_flag,
                                            'N', 'N',
		                            'P', 'P',
                                            'Z'),
                                 'Z')
                       OR (    D.assets_addition_flag||'' =
       	                       DECODE(g_assets_status,
                                      'Y', 'U',
		                      'cantequalme')
                           AND I.cancelled_date IS NULL)));
Line: 804

   	DELETE
   	FROM ap_purge_invoice_list PL
   	WHERE EXISTS
      		(SELECT 'payment not purgeable'
       		FROM ap_invoice_payments_all P,
                     ap_checks C
       		WHERE P.invoice_id = PL.invoice_id
       		AND P.check_id = C.check_id
       		AND  (((P.posted_flag <> 'Y'
       		OR
                P.accrual_posted_flag =
       		DECODE(p_using_accrual_basis, 'Y','N','Z')
       		OR
                P.cash_posted_flag =
       		DECODE(p_using_cash_basis,'Y',
       		DECODE(P.cash_posted_flag,'N',
		'N','P','P','Z'),'Z')
       		OR
                P.last_update_date > g_activity_date
       		OR
                C.last_update_date > g_activity_date
                OR
                /*Following two conditions added for bug#2274656 to prevent
                  Future Dated checks being purged before they are matured */
                (C.future_pay_due_date is not null
                 AND C.status_lookup_code ='ISSUED')

/* Code Modified by MSWAMINA.
   Bug 2211285.
   Payments should not be considered to in the purge list if it has any reference
   information left in cash management. AP assumes that if a customer uses
   CE, They have already purged the related data in CE before purging the AP
   payments information.
   So Added the following condition back. */
/*  Fix for bug#2274656
   Bug#2211285 hard codes the date in case Cleared Date and Void date are null, to an infinite
   value and makes the condition always true , so the payment records would not
   get purged if it has not been Cleared, but some customers may not be using
   recon accounting at all.  Now the recon accounting flag is selected
   in get_accounting_method()  and we decide based on that */
   		OR
               decode(p_recon_acctg_flag,'Y',nvl(c.cleared_date,
                                     nvl(c.void_date,to_date('12/31/2999','MM/DD/YYYY'))))
                                                                           > g_activity_date
		))
                OR
                EXISTS (SELECT 'Referenced by cashbook'
                        from ce_statement_reconcils_all SR
                        where C.check_id=SR.reference_id
                        AND SR.reference_type= 'PAYMENT'
                        AND SR.org_id = C.org_id )));
Line: 867

   	DELETE
   	FROM ap_purge_invoice_list PL
   	WHERE EXISTS
	       (SELECT  'related to prepayment'
		FROM    ap_invoice_prepays IP
		WHERE	PL.invoice_id = IP.invoice_id
		OR	PL.invoice_id = IP.prepay_id);
Line: 878

        DELETE
        FROM ap_purge_invoice_list PL
        WHERE EXISTS
               (SELECT  'X'
                FROM    ap_invoice_distributions ID
                WHERE   PL.invoice_id = ID.invoice_id
                AND     ID.line_type_lookup_code   = 'PREPAY'
                AND     ID.prepay_distribution_id  IS NOT NULL);
Line: 896

  DELETE FROM ap_purge_invoice_list PL
  where EXISTS(
          select 'history not purgeable'
          from ap_invoice_payments aip
          ,       ap_payment_history aph
          where aip.invoice_id = PL.invoice_id
          and aip.check_id = aph.check_id
          -- To check for posted_flag added for bug#2274656
          and nvl(aph.posted_flag,'N') <> 'Y'
          --Bug 1579474
          --and aph.last_update_date >= g_activity_date);
Line: 907

          and aph.last_update_date > g_activity_date);
Line: 917

  DELETE FROM ap_purge_invoice_list PL
  WHERE EXISTS (
          Select 'invoice accounting not purgeable'
          from  xla_events xe, --Bug 4588031
                xla_transaction_entities xte, --Bug 4588031
                xla_ae_headers xeh, --Bug 4588031
                ap_invoices_all ai,ap_system_parameters_all asp--bug5052748
          where xte.entity_code = 'AP_INVOICES'
          and xte.source_id_int_1 = PL.invoice_id
          AND pl.invoice_id=ai.invoice_id
          AND ai.org_id=asp.org_id
          AND asp.set_of_books_id=xte.ledger_id
          and xte.entity_id = xe.entity_id
          and xe.event_id = xeh.event_id --Bug6318079
          and xe.application_id = 200
          and xeh.application_id = 200
          and xte.application_id = 200
          and (xeh.gl_transfer_status_code = 'N'
                  OR ( xeh.last_update_date > g_activity_date )))
     OR EXISTS (
          Select 'payment accounting not purgeable'
          from  xla_events xe, --Bug 4588031
                xla_transaction_entities xte, --Bug 4588031
                ap_invoice_payments aip,
                ap_system_parameters_all asp,--bug5052478
                xla_ae_headers xeh --Bug 4588031
          where xte.entity_code = 'AP_PAYMENTS'
          and   xte.source_id_int_1 = aip.check_id
          and   xte.entity_id = xe.entity_id
          AND   asp.set_of_books_id=xte.ledger_id
          AND   aip.org_id=asp.org_id
          and   PL.invoice_id = aip.invoice_id
          and   xe.event_id = xeh.event_id
          and   xe.application_id = 200
          and   xeh.application_id = 200
          and   xte.application_id = 200
          and   (xeh.gl_transfer_status_code = 'N'
                  OR ( xeh.last_update_date > g_activity_date)));
Line: 962

   DELETE FROM ap_purge_invoice_list PL
   WHERE EXISTS (
          select 'matched'
          from ap_invoice_distributions aid, rcv_transactions rcv
          where aid.invoice_id = PL.invoice_id
          and aid.rcv_transaction_id = rcv.transaction_id
          and rcv.last_update_date > g_activity_date);
Line: 970

  DELETE FROM ap_purge_invoice_list PL
  WHERE EXISTS
                (select null
                 from  ap_invoice_distributions ad
                 where ad.invoice_id = PL.invoice_id
                 and   ad.rcv_transaction_id is not null
                 and exists (
                 select 'matching'  from  ap_invoice_distributions ad2
                 where ad2.rcv_transaction_id =  ad.rcv_transaction_id
                 and ad2.invoice_id NOT IN (
                        select invoice_id
			from  ap_purge_invoice_list
			where double_check_flag = 'Y')));
Line: 985

  SELECT count(*) INTO l_list_count FROM ap_purge_invoice_list;
Line: 1044

select count(1)
into invoice_count
from ap_purge_invoice_list
where double_check_flag = 'Y';
Line: 1097

           delete from ap_purge_invoice_list apl
	   where exists
	        (select null
	         from  ap_invoice_distributions ad
	         where ad.invoice_id = apl.invoice_id
                 and   ad.po_distribution_id is not null
	         and not exists (select null
       		   	         from  po_purge_po_list ppl,
				       po_distributions pd
                  	         where ppl.po_header_id =
				       pd.po_header_id
                  	         and   pd.po_distribution_id =
                                       ad.po_distribution_id));
Line: 1113

           update ap_purge_invoice_list apl
           set double_check_flag = 'N'
           where double_check_flag = 'Y'
           and   exists (select /*+NO_UNNEST*/ null
                         from  ap_invoice_distributions ad,po_distributions pd
                         where ad.invoice_id = apl.invoice_id
                         AND   pd.po_distribution_id=ad.po_distribution_id
                         and   ad.po_distribution_id is not null
                         and not exists (SELECT null
                                         FROM  po_purge_po_list ppl
                                         WHERE ppl.double_check_flag = 'Y'
                                         AND   ppl.po_header_id =pd.po_header_id));
Line: 1131

	select count(1)
	into invoice_count
	from ap_purge_invoice_list
	where double_check_flag = 'Y';
Line: 1157

           SELECT count(*)
           INTO   start_list_count
           FROM   ap_purge_invoice_list
           WHERE  double_check_flag = DECODE(p_purge_status, 'INITIATING', 'Y',
                                                   double_check_flag);
Line: 1165

              DELETE
              FROM ap_purge_invoice_list PL
              WHERE EXISTS (
                         SELECT 'relational problem'
                         FROM ap_invoice_payments IP1,
                              ap_invoice_payments IP2
                         WHERE PL.invoice_id = IP1.invoice_id
                         AND   IP1.check_id = IP2.check_id
                         AND   IP2.invoice_id NOT IN (
                                 SELECT PL2.invoice_id
                                 FROM ap_purge_invoice_list PL2
                                 WHERE PL2.invoice_id =
                                          IP2.invoice_id)
                          );
Line: 1183

              UPDATE ap_purge_invoice_list PL
              SET PL.double_check_flag = 'N'
              WHERE PL.double_check_flag = 'Y'
              AND EXISTS (
                      SELECT /*+NO_UNNEST*/'relational problem'
                      FROM ap_invoice_payments IP1, ap_invoice_payments IP2
                      WHERE PL.invoice_id = IP1.invoice_id
                      AND   IP1.check_id = IP2.check_id
                      AND   IP2.invoice_id NOT IN (
                              SELECT PL2.invoice_id
                              FROM ap_purge_invoice_list PL2
                              WHERE PL2.invoice_id = IP2.invoice_id
                              AND PL2.double_check_flag ='Y'));
Line: 1200

           SELECT count(*)
           INTO list_count
           FROM ap_purge_invoice_list
           WHERE  double_check_flag = DECODE(p_purge_status, 'INITIATING', 'Y',
                                                   double_check_flag);
Line: 1285

  insert into chv_purge_cum_list
       	 (cum_period_id,
          purge_name,
          double_check_flag)
  select  ccp.cum_period_id,
          p_purge_name,
          'Y'
  from    chv_cum_periods ccp
  where   ccp.organization_id = g_organization_id
  and     NVL(ccp.cum_period_end_date, sysdate + 1) <= g_activity_date
  and     NVL(ccp.cum_period_end_date,sysdate + 1) < sysdate;
Line: 1302

  insert into chv_purge_schedule_list
  	 (schedule_item_id,
          purge_name,
          double_check_flag)
  select  csi.schedule_item_id,
          p_purge_name,
          'Y'
  from    chv_schedule_items csi,
          chv_schedule_headers csh,
          chv_purge_cum_list cpcl,
	  chv_cum_periods ccp
  where   csh.schedule_id = csi.schedule_id
  and     csh.schedule_horizon_start between ccp.cum_period_start_date
				       and ccp.cum_period_end_date
  and     ccp.cum_period_id = cpcl.cum_period_id
  and     csi.organization_id = g_organization_id;
Line: 1355

  insert into chv_purge_schedule_list
   	 (schedule_item_id,
       	  purge_name,
          double_check_flag)
  select  csi.schedule_item_id,
          p_purge_name,
          'Y'
  from    chv_schedule_items csi,
          chv_schedule_headers csh
  where   csh.schedule_id = csi.schedule_id
  and     csh.last_update_date <= g_activity_date
  and     NVL(csi.item_purge_status,'N') <> 'PURGED'
  and     csi.organization_id = g_organization_id;
Line: 1404

      Print('(Inserting into ap_purge_invoice_list)' ||debug_info);
Line: 1407

   	INSERT INTO ap_purge_invoice_list
	(invoice_id, purge_name, double_check_flag)
	SELECT 	DISTINCT I.invoice_id, p_purge_name, 'Y'
	FROM 	ap_invoices I, ap_invoice_distributions D
	WHERE	I.invoice_id = D.invoice_id
	AND	I.payment_status_flag || '' = 'Y'
	AND	I.invoice_type_lookup_code <> 'PREPAYMENT'
	AND	D.posted_flag || '' = 'Y'
        AND     D.accrual_posted_flag = DECODE(p_using_accrual_basis, 'Y','Y',
                                                     D.accrual_posted_flag)
        AND     D.cash_posted_flag = DECODE(p_using_cash_basis, 'Y','Y',
                                         D.cash_posted_flag)
	AND	D.last_update_date <= g_activity_date
	AND	I.last_update_date <= g_activity_date
	AND	I.invoice_date <= g_activity_date
	UNION
	SELECT	I.invoice_id, p_purge_name, 'Y'
	FROM	ap_invoices I, ap_invoice_distributions D
	WHERE	I.invoice_id = D.invoice_id (+)
	AND	I.last_update_date <= g_activity_date
	AND	I.invoice_date <= g_activity_date
	AND	I.invoice_amount = 0
	AND	I.invoice_type_lookup_code <> 'PREPAYMENT'
	GROUP BY I.invoice_id
	HAVING	SUM(NVL(D.amount, 0)) = 0;
Line: 1433

        select count(*) into temp from ap_purge_invoice_list;
Line: 1439

           Print('(Done inserting into ap_purge_invoice_list)' ||debug_info);
Line: 1478

	insert into po_purge_vendor_list
       		(vendor_id,
		purge_name,
		double_check_flag)
	select  vnd.vendor_id,
		p_purge_name,
		'Y'
	from 	ap_suppliers vnd
	where   vnd.end_date_active <= g_activity_date
	and not exists (select 'vnd.vendor is a parent of
			another vendor'
                	from ap_suppliers v
                	where v.parent_vendor_id =
			      vnd.vendor_id)
        --Bug 2653578
        and PO_THIRD_PARTY_STOCK_GRP.validate_supplier_purge(
                                                vnd.vendor_id) = 'TRUE';
Line: 1506

 	      delete from po_purge_vendor_list pvl
	      where exists
	             (select null
		      from  fa_mass_additions fma
		      where fma.po_vendor_id = pvl.vendor_id)
		      or    exists
				(select null
				from  fa_asset_invoices fai
				where fai.po_vendor_id = pvl.vendor_id);
Line: 1524

		delete from po_purge_vendor_list pvl
		where exists
			(select null
			from  ap_invoices_all ai
			where ai.vendor_id = pvl.vendor_id)
		or    exists
			(select null
			from ap_selected_invoices_all asi,
                     	     ap_supplier_sites_all pvs
			where asi.vendor_site_id =
		 	      pvs.vendor_site_id
                and   pvs.vendor_id      = pvl.vendor_id)
		or    exists
			(select null
			from ap_recurring_payments_all arp
			where arp.vendor_id = pvl.vendor_id);
Line: 1551

		delete from po_purge_vendor_list pvl
		where exists   (select null
				from po_headers_all ph
				where ph.vendor_id =
				      pvl.vendor_id)
		or  exists     (select null
				from rcv_shipment_headers
		        	rcvsh
				where rcvsh.vendor_id =
				      pvl.vendor_id)
		or  exists     (select null
				from po_rfq_vendors rfq
				where rfq.vendor_id =
		 		      pvl.vendor_id);
Line: 1617

	delete from po_purge_vendor_list pvl
	where exists   (select null
	        	from  fa_mass_additions fma
		        where fma.po_vendor_id =
                              pvl.vendor_id)
        or    exists   (select null
		        from  fa_asset_invoices fai
		        where fai.po_vendor_id =
                              pvl.vendor_id);
Line: 1631

     delete from po_purge_vendor_list pvl
     where exists   (select null
		     from  ap_invoices_all ai
		     where ai.vendor_id = pvl.vendor_id)
     or    exists   (select null
		     from ap_selected_invoices_all asi,
                     ap_supplier_sites_all pvs
		     where asi.vendor_site_id =
                           pvs.vendor_site_id
                     and   pvs.vendor_id  =  pvl.vendor_id)
     or    exists   (select null
		     from ap_recurring_payments_all arp
		     where arp.vendor_id = pvl.vendor_id);
Line: 1655

     delete from po_purge_vendor_list pvl
     where exists   (select null
		     from po_headers_all ph
		     where ph.vendor_id = pvl.vendor_id)
     or  exists     (select null
		     from rcv_shipment_headers rcvsh
		     where rcvsh.vendor_id = pvl.vendor_id)
     or  exists     (select null
		     from po_rfq_vendors rfq
		     where rfq.vendor_id = pvl.vendor_id)
     or  exists     (select null
                     from rcv_headers_interface rhi
                     where rhi.vendor_id = pvl.vendor_id)
     or  exists     (select null
                     from rcv_transactions_interface rti
                     where rti.vendor_id = pvl.vendor_id);
Line: 1683

     delete from po_purge_vendor_list pvl
     where exists   (select null
        from chv_schedule_headers csh
        where csh.vendor_id = pvl.vendor_id);
Line: 1697

     delete from po_purge_vendor_list pvl
     where exists   (select null
                from  ece_tp_details etd,
                      ap_supplier_sites_all pvs
                where etd.tp_header_id = pvs.tp_header_id
                and pvs.vendor_id = pvl.vendor_id
                and etd.last_update_date > g_activity_date);
Line: 1723

     delete from po_purge_vendor_list pvl
     where exists   (select null
                     from  mrp_sr_source_org msso
                     where msso.vendor_id = pvl.vendor_id);
Line: 2085

range_inserted  VARCHAR2(1);
Line: 2106

        range_inserted := 'N';
Line: 2110

        select 'Y'
        into   range_inserted
        from   sys.dual
        where  exists (select null
                       from   ap_history_invoices
                       where  purge_name = p_purge_name
                        and    invoice_id between range_low and range_high);
Line: 2120

        range_inserted := 'N';
Line: 2123

        if (range_inserted <> 'Y') then
          --
          debug_info := 'Summerizing sub-group from Oracle Purchasing -- Invoices';
Line: 2131

          INSERT INTO ap_history_invoices_all
                  (invoice_id, vendor_id, vendor_site_code, invoice_num, invoice_date,
                   invoice_amount, batch_name, purge_name, doc_sequence_id,
                   doc_sequence_value,org_id)
          SELECT  i.invoice_id, i.vendor_id, v.vendor_site_code, i.invoice_num,
                  i.invoice_date, i.invoice_amount, b.batch_name, p_purge_name,
                  i.doc_sequence_id, i.doc_sequence_value,i.org_id
          FROM    ap_invoices_all i, ap_supplier_sites_all v, ap_batches_all b
          WHERE   i.vendor_site_id = v.vendor_site_id
          AND     i.batch_id = b.batch_id (+)
          AND     i.invoice_id IN (SELECT PL.invoice_id
                                   FROM  ap_purge_invoice_list PL
                                   WHERE PL.double_check_flag = 'Y'
                                   AND   PL.invoice_id BETWEEN range_low AND
                                                           range_high);
Line: 2156

          INSERT INTO ap_history_checks_all
          (check_id, bank_account_id, check_number, check_date, amount,
          currency_code, void_flag, purge_name, doc_sequence_id,
          doc_sequence_value, payment_id,org_id)
          SELECT
          ac.check_id, ac.bank_account_id, ac.check_number, ac.check_date,
          ac.amount, ac.currency_code, DECODE(void_date, null, null, 'Y'),
          p_purge_name, ac.doc_sequence_id, ac.doc_sequence_value, ac.payment_id,
	  ac.org_id
          FROM ap_checks_all AC,
               ap_invoice_payments_all IP,
               ap_purge_invoice_list PL
          WHERE PL.invoice_id        = IP.invoice_id
          AND   IP.check_id          = AC.check_id
          AND   PL.double_check_flag = 'Y'
          AND   PL.invoice_id BETWEEN range_low AND range_high
          AND NOT EXISTS (SELECT null
                          FROM   ap_history_checks_all hc
                          WHERE  hc.check_id = AC.check_id)
          GROUP BY ac.check_id, ac.bank_account_id, ac.check_number,
                   ac.check_date, ac.amount, ac.currency_code,
                   DECODE(void_date, null, null, 'Y'), purge_name,
                   ac.doc_sequence_id, ac.doc_sequence_value, ac.payment_id,
		   ac.org_id; --Bug 6277474 added the org_id in group by clause.
Line: 2189

          INSERT INTO ap_history_inv_payments_all
          (invoice_id, check_id, amount,org_id)
          SELECT
          IP.invoice_id, IP.check_id, SUM(IP.amount),IP.org_id
          FROM  ap_invoice_payments_all IP, ap_purge_invoice_list PL
          WHERE IP.invoice_id = PL.invoice_id
          AND   PL.double_check_flag = 'Y'
          AND   PL.invoice_id BETWEEN range_low AND range_high
          GROUP BY IP.invoice_id, IP.check_id,
		   IP.org_id; --Bug 6277474 added the org_id in group by clause.
Line: 2239

range_inserted  VARCHAR2(1);
Line: 2253

  range_inserted := 'N';
Line: 2259

  select 'Y'
  into   range_inserted
  from   sys.dual
  where  exists (select null
                 from   po_history_vendors vnd
                 where  vnd.purge_name = p_purge_name);
Line: 2268

      range_inserted := 'N';
Line: 2271

  if (range_inserted <> 'Y') then
  --
          debug_info := 'Vendors';
Line: 2279

          insert into po_history_vendors
               (vendor_id,
                vendor_name,
                segment1,
                vendor_type_lookup_code,
                purge_name)
          select  vnd.vendor_id,
                vnd.vendor_name,
                vnd.segment1,
                vnd.vendor_type_lookup_code,
                p_purge_name
          from  po_purge_vendor_list pvl,
                ap_suppliers vnd
          where pvl.vendor_id = vnd.vendor_id
          and   pvl.double_check_flag = 'Y';
Line: 2330

range_inserted  VARCHAR2(1);
Line: 2354

        range_inserted := 'N';
Line: 2357

        select MAX('Y')
        into   range_inserted
        from   sys.dual
        where  exists (select null
                       from   chv_schedule_items csi,
			      chv_schedule_headers csh,
                              chv_history_schedules chs
                       where  csi.item_id         = chs.item_id
                       and    csi.schedule_id     = chs.schedule_id
		       and    csh.schedule_id     = chs.schedule_id
		       and    csh.vendor_id       = chs.vendor_id
		       and    csh.vendor_site_id  = chs.vendor_site_id
		       and    csi.organization_id = chs.organization_id
                       and    chs.purge_name      = p_purge_name
                       and    csi.schedule_item_id between range_low
                                               and range_high);
Line: 2374

        Print('(Range Inserted) ' || range_inserted);
Line: 2375

        if (NVL(range_inserted,'N') <> 'Y') then
          --
          debug_info := 'Summerizing sub-group from Oracle Supplier Scheduling';
Line: 2383

          insert into chv_history_schedules
                (schedule_id,
                 vendor_id,
                 vendor_site_id,
                 schedule_type,
                 schedule_subtype,
		 schedule_horizon_start,
		 bucket_pattern_id,
		 creation_date,
		 schedule_num,
		 schedule_revision,
		 schedule_status,
		 item_id,
		 organization_id,
                 purge_name
                 )
          select  csh.schedule_id,
                  csh.vendor_id,
                  csh.vendor_site_id,
                  csh.schedule_type,
                  csh.schedule_subtype,
		  csh.schedule_horizon_start,
		  csh.bucket_pattern_id,
		  csh.creation_date,
		  csh.schedule_num,
		  csh.schedule_revision,
		  csh.schedule_status,
		  csi.item_id,
		  csi.organization_id,
                  p_purge_name
          from  chv_purge_schedule_list cpsl,
                chv_schedule_headers csh,
                chv_schedule_items csi
          where   cpsl.schedule_item_id = csi.schedule_item_id
	  and     csi.schedule_id = csh.schedule_id
          and     cpsl.double_check_flag     = 'Y'
          and     cpsl.schedule_item_id between range_low and range_high;
Line: 2432

  range_inserted := 'N';
Line: 2435

  select MAX('Y')
  into   range_inserted
  from   sys.dual
  where  exists (select null
                 from   chv_cum_periods ccp,
                        chv_history_cum_periods chcp
		 where  ccp.cum_period_id   = chcp.cum_period_id
                 and    chcp.purge_name     = p_purge_name);
Line: 2447

      NVL(range_inserted,'N') <> 'Y') then
      -- summarize_schedules_by_org
          insert into chv_history_cum_periods
                (cum_period_id,
		 cum_period_name,
		 cum_period_start_date,
		 cum_period_end_date,
		 creation_date,
                 purge_name
                 )
          select  ccp.cum_period_id,
       		  ccp.cum_period_name,
		  ccp.cum_period_start_date,
		  ccp.cum_period_end_date,
		  ccp.creation_date,
                  p_purge_name
          from  chv_purge_cum_list cpcl,
                chv_cum_periods ccp
          where   cpcl.cum_period_id = ccp.cum_period_id
          and     cpcl.double_check_flag     = 'Y';
Line: 2515

  select nvl(min(invoice_id),-1),
         nvl(max(invoice_id),-1)
  into   p_inv_lower_limit, p_inv_upper_limit
  from   ap_purge_invoice_list
  where  double_check_flag = 'Y';
Line: 2522

  select nvl(min(po_header_id),-1),
         nvl(max(po_header_id),-1)
  into   p_po_lower_limit, p_po_upper_limit
  from   po_purge_po_list
  where  double_check_flag = 'Y';
Line: 2529

  select nvl(min(requisition_header_id),-1),
         nvl(max(requisition_header_id),-1)
  into   p_req_lower_limit, p_req_upper_limit
  from   po_purge_req_list
  where  double_check_flag = 'Y';
Line: 2536

  select nvl(min(schedule_item_id),-1),
         nvl(max(schedule_item_id),-1)
  into   p_chv_lower_limit, p_chv_upper_limit
  from   chv_purge_schedule_list
  where  double_check_flag = 'Y';
Line: 2613

  debug_info := 'Inserting summary records into history tables';
Line: 2730

  UPDATE ap_purge_invoice_list PL
  SET PL.double_check_flag = 'N'
  WHERE PL.double_check_flag = 'Y'
  AND EXISTS(
                SELECT 'invoice no longer purgeable'
                FROM ap_invoices I
                WHERE PL.invoice_id = I.invoice_id
                AND ((  I.payment_status_flag <> 'Y'
                        AND
                        I.invoice_amount <> 0)
                     OR I.last_update_date > g_activity_date
                     OR I.invoice_date > g_activity_date));
Line: 2751

     UPDATE ap_purge_invoice_list PL
     SET PL.double_check_flag = 'N'
     WHERE PL.double_check_flag = 'Y'
     AND (EXISTS
                (SELECT 'project-related vendor invoices'
                FROM    ap_invoice_distributions d
                WHERE   d.invoice_id = pl.invoice_id
                AND     d.project_id is not null   -- bug1746226
                )
     OR EXISTS
                (SELECT 'project-related expense report'
                FROM    ap_invoices i
                WHERE   i.invoice_id = pl.invoice_id
                AND     i.source = 'Oracle Project Accounting'
                ));
Line: 2778

  UPDATE ap_purge_invoice_list PL
  SET PL.double_check_flag = 'N'
  WHERE PL.double_check_flag = 'Y'
  AND EXISTS (
                SELECT /*+NO_UNNEST*/ 'payment schedule no longer purgeable'
                FROM ap_payment_schedules PS,
                     ap_invoices I
                WHERE PS.invoice_id = PL.invoice_id
                AND   PS.invoice_id = I.invoice_id
                AND ((PS.payment_status_flag <> 'Y'
                      AND  I.cancelled_date is null)
                     OR PS.last_update_date > g_activity_date)
                );
Line: 2810

        UPDATE ap_purge_invoice_list PL
        SET PL.double_check_flag = 'N'
        WHERE PL.double_check_flag = 'Y'
        AND EXISTS
            (SELECT /*+NO_UNNEST*/ 'distribution no longer purgeable'
               FROM ap_invoice_distributions D, ap_invoices I
              WHERE I.invoice_id = D.invoice_id
                AND PL.invoice_id = D.invoice_id
                AND (   D.last_update_date > g_activity_date
                     OR D.posted_flag <> 'Y'
                     OR D.po_distribution_id IS NOT NULL
                     OR (    D.assets_addition_flag||'' =
                             Decode(g_Assets_Status,
                                    'Y', 'U',
                                    'cantequalme')
                         AND I.cancelled_date IS NULL)));
Line: 2829

        UPDATE ap_purge_invoice_list PL
        SET PL.double_check_flag = 'N'
        WHERE PL.double_check_flag = 'Y'
        AND EXISTS
            (SELECT /*+NO_UNNEST*/'distribution no longer purgeable'
               FROM ap_invoice_distributions D, ap_invoices I
              WHERE I.invoice_id = D.invoice_id
                AND PL.invoice_id = D.invoice_id
                AND (   D.last_update_date > g_activity_date
                     OR D.posted_flag <> 'Y'
                     OR (    D.assets_addition_flag||'' =
                             Decode(g_Assets_Status,
                                    'Y', 'U',
                                    'cantequalme')
                         AND I.cancelled_date IS NULL)));
Line: 2855

        UPDATE ap_purge_invoice_list PL
        SET PL.double_check_flag = 'N'
        WHERE PL.double_check_flag = 'Y'
        AND EXISTS (
                SELECT /*+NO_UNNEST*/'payment no longer purgeable'
                FROM ap_invoice_payments P, ap_checks C
                WHERE P.invoice_id = PL.invoice_id
                AND P.check_id = C.check_id
                AND     (P.posted_flag <> 'Y'
                        OR P.last_update_date > g_activity_date
                        OR C.last_update_date > g_activity_date
                        OR (NVL(C.cleared_date, C.void_date) > g_activity_date
			    AND nvl(C.cleared_date, C.void_date) is not NULL)
		));
Line: 2878

        UPDATE ap_purge_invoice_list PL
        SET PL.double_check_flag = 'N'
        WHERE PL.double_check_flag = 'Y'
        AND EXISTS (
                SELECT 'recently related to prepayment'
                FROM ap_invoice_prepays IP
                WHERE   PL.invoice_id = IP.invoice_id
                        OR PL.invoice_id = IP.prepay_id);
Line: 2894

        UPDATE ap_purge_invoice_list PL
        SET PL.double_check_flag = 'N'
        WHERE EXISTS (
                 SELECT 'matched'
                 FROM  ap_invoice_distributions aid
                 ,      rcv_transactions rcv
                 WHERE aid.invoice_id = PL.invoice_id
                 and  aid.rcv_transaction_id = rcv.transaction_id
                 --Bug 1579474
                 and  rcv.last_update_date > g_activity_date
                 );
Line: 2913

        UPDATE ap_purge_invoice_list PL
	SET double_check_flag = 'N'
	WHERE EXISTS (
		SELECT null
		FROM ap_invoice_distributions ad
		WHERE ad.invoice_id = PL.invoice_id
		and ad.rcv_transaction_id IS NOT NULL
		and EXISTS (
			SELECT 'matching'
			FROM ap_invoice_distributions ad2
			where ad2.rcv_transaction_id = ad.rcv_transaction_id
			and ad2.invoice_id NOT IN (
				SELECT invoice_id
				FROM ap_purge_invoice_list
				WHERE double_check_flag = 'Y')));
Line: 2939

   UPDATE ap_purge_invoice_list PL
   SET PL.double_check_flag = 'N'
   WHERE EXISTS (
                 SELECT 'invoice accounting not purgeable'
                 FROM   xla_events xe,
                        xla_ae_headers xeh,
                        xla_transaction_entities xte,
                        ap_invoices_all ai,
                        ap_system_parameters_all asp --bug5052748
                 where xte.entity_code = 'AP_INVOICES'
                 and   xte.entity_id = xe.entity_id
                 and   xte.source_id_int_1 =PL.invoice_id
                 AND ai.invoice_id=pl.invoice_id
                 AND ai.org_id=asp.org_id
                 AND asp.set_of_books_id=xte.ledger_id
                 and   xe.event_id = xeh.event_id
                 and   xe.application_id = 200
                 and   xeh.application_id = 200
                 and   xte.application_id = 200
                 and   (xeh.gl_transfer_status_code = 'N'
                        OR ( xeh.last_update_date > g_activity_date)))
   OR EXISTS (
                 SELECT 'payment accounting not purgeable'
                 FROM xla_events xe
                 ,    ap_invoice_payments aip
                 ,    ap_checks apc
                 ,    xla_ae_headers xeh
                 ,    xla_transaction_entities xte
                 WHERE xte.entity_code = 'AP_CHECKS'
                 and  xte.source_id_int_1 = apc.check_id
                 and PL.invoice_id = aip.invoice_id
                 and aip.check_id = apc.check_id
                 and xe.event_id = xeh.event_id
                 and xe.application_id = 200
                 and xeh.application_id = 200
                 and xte.application_id = 200
                 and xe.event_id = xeh.event_id
                 and (xeh.gl_transfer_status_code = 'N'
                      OR ( xeh.last_update_date > g_activity_date)));
Line: 3009

   Because performance of delete stmt in do_dependent_inv_checks was very poor.
   This function does same check with the delete stmt.
*/

 TYPE tab_status_type IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
Line: 3019

  select pl.invoice_id
    from ap_purge_invoice_list pl,
         ap_invoice_payments ip
   where pl.invoice_id = ip.invoice_id;
Line: 3025

  select invoice_id
    from ap_purge_invoice_list
   where invoice_id = l_invoice_id
     and double_check_flag = 'Y';
Line: 3047

  select pil.invoice_id
    from ap_invoice_payments ip,
         ap_purge_invoice_list pil
   where ip.check_id = l_check_id
     and ip.invoice_id = pil.invoice_id (+)
     and pil.double_check_flag = 'Y';
Line: 3093

  select check_id
    from ap_invoice_payments
   where invoice_id = l_invoice_id ;
Line: 3165

            UPDATE ap_purge_invoice_list
               SET double_check_flag = 'S'
             WHERE invoice_id = p_id ;
Line: 3173

        /* if this chain is not purgeable, delete selected invoice from purge list */
        p_count := tab_inv.count;
Line: 3180

            UPDATE ap_purge_invoice_list
               SET double_check_flag = 'N'
             WHERE invoice_id = p_id ;
Line: 3186

        /* delete unpurgeable list beforehand for performance */
        p_count := tab_check.count;
Line: 3194

            UPDATE ap_purge_invoice_list
               SET double_check_flag = 'N'
            WHERE invoice_id in ( select invoice_id
                from ap_invoice_payments
                where check_id = p_id);
Line: 3209

  update ap_purge_invoice_list
    set double_check_flag = 'Y'
   where double_check_flag = 'S' ;
Line: 3261

  SELECT count(*)
  INTO   fp_check_rows
  FROM   ap_checks;
Line: 3272

  SELECT count(*)
  INTO   fp_invoice_payment_rows
  FROM   ap_invoice_payments;
Line: 3283

  SELECT count(*)
  INTO   fp_invoice_rows
  FROM ap_invoices;
Line: 3374

  SELECT count(*)
  INTO   fp_payment_history_rows
  FROM   ap_payment_history;
Line: 3385

  SELECT count(*)
  INTO   fp_encumbrance_line_rows
  FROM   ap_encumbrance_lines;
Line: 3396

  SELECT count(*)
  INTO   fp_rcv_subledger_detail_rows
  FROM   rcv_sub_ledger_details;
Line: 3435

  update po_purge_vendor_list pvl
  set double_check_flag = 'N'
  where pvl.double_check_flag = 'Y'
  and   not exists (select null
                    from    ap_suppliers vnd
                    where   vnd.vendor_id = pvl.vendor_id
                    --and   nvl(vnd.vendor_type_lookup_code, 'VENDOR') <> 'EMPLOYEE'
                    and     nvl(vnd.end_date_active,sysdate) <=
                                g_activity_date);
Line: 3493

        update po_purge_vendor_list pvl
        set double_check_flag = 'N'
        where pvl.double_check_flag = 'Y'
        and (exists    (select null
                        from fa_mass_additions fma
                        where fma.po_vendor_id = pvl.vendor_id)
             or
             exists    (select null
                        from fa_asset_invoices fai
                        where fai.po_vendor_id = pvl.vendor_id));
Line: 3511

     update po_purge_vendor_list pvl
     set double_check_flag = 'N'
     where pvl.double_check_flag = 'Y'
     and  (exists   (select null
                     from ap_invoices_all ai
                     where ai.vendor_id = pvl.vendor_id)
           or
           exists   (select null
                     from ap_selected_invoices_all asi,
                          ap_supplier_sites_all pvs
                     where asi.vendor_site_id = pvs.vendor_site_id
                    and   pvs.vendor_id      = pvl.vendor_id)
           or
           exists   (select null
                     from ap_recurring_payments_all arp
                     where arp.vendor_id = pvl.vendor_id));
Line: 3538

     update po_purge_vendor_list pvl
     set double_check_flag = 'N'
     where pvl.double_check_flag = 'Y'
     and (exists   (select null
                    from po_headers_all ph
                     where ph.vendor_id = pvl.vendor_id)
          or
          exists    (select null
                     from po_rfq_vendors rfq
                     where rfq.vendor_id = pvl.vendor_id)
          or
          exists    (select null
                     from rcv_shipment_headers rcvsh
                     where rcvsh.vendor_id = pvl.vendor_id)
          or
          exists    (select null
                     from rcv_headers_interface rhi
                     where rhi.vendor_id = pvl.vendor_id)
          or
          exists    (select null
                     from rcv_transactions_interface rti
                     where rti.vendor_id = pvl.vendor_id));
Line: 3572

     update po_purge_vendor_list pvl
     set double_check_flag = 'N'
     where pvl.double_check_flag = 'Y'
     and   (exists   (select null
                from chv_schedule_headers csh
                where csh.vendor_id = pvl.vendor_id));
Line: 3593

     update po_purge_vendor_list pvl
     set double_check_flag = 'N'
     where pvl.double_check_flag = 'Y'
     and   (exists   (select null
                from  mrp_sr_source_org msso
                where msso.vendor_id = pvl.vendor_id));
Line: 3613

     update po_purge_vendor_list pvl
     set double_check_flag = 'N'
     where pvl.double_check_flag = 'Y'
     and   (exists   (select null
                from  ece_tp_details etd,
                      ap_supplier_sites_all pvs
                where etd.tp_header_id = pvs.tp_header_id
                and pvs.vendor_id = pvl.vendor_id
                and etd.last_update_date > g_activity_date));
Line: 3673

  update chv_purge_schedule_list cpsl
  set double_check_flag = 'N'
  where cpsl.double_check_flag = 'Y'
  and  not exists (select 'schedule not purgeable' from chv_schedule_items csi,
                             chv_schedule_headers csh
            where   csh.schedule_id = csi.schedule_id
            and     csh.last_update_date <= g_activity_date
            and     csi.organization_id = g_organization_id
            and     csi.schedule_item_id = cpsl.schedule_item_id);
Line: 3718

  update chv_purge_cum_list cpcl
  set double_check_flag = 'N'
  where cpcl.double_check_flag = 'Y'
  and not exists (select  null from chv_cum_periods ccp
            where   ccp.organization_id = g_organization_id
            and     NVL(ccp.cum_period_end_date, sysdate + 1) <= g_activity_date
            and     NVL(ccp.cum_period_end_date,sysdate + 1) < sysdate
            and     ccp.cum_period_id = cpcl.cum_period_id);
Line: 3734

  update chv_purge_schedule_list cpsl
  set double_check_flag = 'N'
  where cpsl.double_check_flag = 'Y'
  and not exists (select null from chv_schedule_items csi,
                             chv_schedule_headers csh,
			     chv_cum_periods ccp,
			     chv_purge_cum_list cpcl
            where   csh.schedule_id = csi.schedule_id
	    and     csh.schedule_horizon_start between ccp.cum_period_start_date
						   and ccp.cum_period_end_date
	    and     ccp.cum_period_id = cpcl.cum_period_id
            and     csi.organization_id = g_organization_id
            and     csi.schedule_item_id = cpsl.schedule_item_id);
Line: 3783

  update chv_purge_schedule_list cpsl
  set double_check_flag = 'N'
  where cpsl.double_check_flag = 'Y'
  and exists   (select null
              from chv_cum_periods ccp,
                   chv_schedule_items csi,
                   chv_schedule_headers csh,
                   chv_org_options coo
              where ccp.organization_id  = g_organization_id
              and   sysdate between ccp.cum_period_start_date and
                                    NVL(ccp.cum_period_end_date,sysdate + 1)
              and  coo.organization_id = ccp.organization_id
              and  coo.enable_cum_flag = 'Y'
              and  csh.schedule_id = csi.schedule_id
              and  csh.schedule_horizon_start >= ccp.cum_period_start_date
              and  csi.schedule_item_id = cpsl.schedule_item_id);
Line: 3835

  update chv_purge_schedule_list cpsl
  set double_check_flag = 'N'
  where cpsl.double_check_flag = 'Y'
  and exists  (select null
              from chv_schedule_items csi,
              ece_spso_items esi
              where csi.schedule_item_id = cpsl.schedule_item_id
              and csi.schedule_id = esi.schedule_id);
Line: 3893

  SELECT count(*)
  INTO   chv_auth_rows
  FROM   chv_authorizations;
Line: 3905

  SELECT count(*)
  INTO   chv_cum_adj_rows
  FROM   chv_cum_adjustments;
Line: 3917

  SELECT count(*)
  INTO   chv_cum_rows
  FROM   chv_cum_periods;
Line: 3928

  SELECT count(*)
  INTO   chv_hor_rows
  FROM   chv_horizontal_schedules;
Line: 3939

  SELECT count(*)
  INTO   chv_ord_rows
  FROM   chv_item_orders;
Line: 3950

  SELECT count(*)
  INTO   chv_head_rows
  FROM   chv_schedule_headers;
Line: 3961

  SELECT count(*)
  INTO   chv_item_rows
  FROM   chv_schedule_items
  WHERE  NVL(item_purge_status,'N') <> 'PURGED';
Line: 4025

  UPDATE financials_purges
  SET
  ap_checks                = fp_check_rows,
  ap_invoice_payments      = fp_invoice_payment_rows,
  ap_invoices              = fp_invoice_rows,
  po_headers               = fp_po_header_rows ,
  po_receipts              = fp_receipt_line_rows,
  po_requisition_headers   = fp_req_header_rows,
  po_vendors               = fp_vendor_rows,
  po_approved_supplier_list = fp_po_asl_rows,
  po_asl_attributes 	   = fp_po_asl_attr_rows,
  po_asl_documents 	   = fp_po_asl_doc_rows,
  chv_authorizations 	   = fp_chv_auth_rows,
  chv_cum_adjustments 	   = fp_chv_cum_adj_rows,
  chv_cum_periods 	   = fp_chv_cum_rows,
  chv_horizontal_schedules = fp_chv_hor_rows,
  chv_item_orders	   = fp_chv_ord_rows,
  chv_schedule_headers 	   = fp_chv_head_rows,
  chv_schedule_items 	   = fp_chv_item_rows,
  ap_ae_lines              = fp_ae_line_rows,
  ap_ae_headers		   = fp_ae_header_rows,
  ap_accounting_events	   = fp_accounting_event_rows,
  ap_chrg_allocations      = fp_chrg_allocation_rows,
  ap_payment_history       = fp_payment_history_rows,
  ap_encumbrance_lines     = fp_encumbrance_line_rows,
  rcv_subledger_details    = fp_rcv_subledger_detail_rows
  WHERE purge_name 	   = fp_purge_name ;
Line: 4061

   UPDATE ap_purge_invoice_list PL
   SET PL.double_check_flag = 'N'
   WHERE EXISTS (
               SELECT 'history not purgeable'
               FROM ap_invoice_payments aip
               ,    ap_payment_history aph
               WHERE aip.invoice_id = PL.invoice_id
               and aip.check_id = aph.check_id
               and aph.last_update_date > g_activity_date);
Line: 4545

		        'Delete Seeded Data') <> TRUE) then
          Print('purge_schedules_by_cum failed!');
Line: 4579

	  	      'Delete Seeded Data') <> TRUE) then
         Print('purge_schedules_by_cum failed!');
Line: 4675

CURSOR overflow_select is
SELECT C.check_stock_id,C.check_number
FROM ap_invoice_payments P, ap_purge_invoice_list PL,
     ap_checks C
WHERE P.invoice_id = PL.invoice_id
AND P.check_id = C.check_id
AND PL.double_check_flag = 'Y'
AND PL.invoice_id BETWEEN range_low AND range_high;
Line: 4687

to_be_deleted_check_number      NUMBER;
Line: 4703

  OPEN overflow_select;
Line: 4707

    debug_info := 'Fetch overflow_select  Cursor';
Line: 4712

    FETCH overflow_select into overflow_check_stock_id,
                               to_be_deleted_check_number;
Line: 4715

    EXIT WHEN overflow_select%NOTFOUND OR overflow_select%NOTFOUND IS NULL;
Line: 4720

                   ||' to_be_deleted_check_number = '
                   ||to_char(to_be_deleted_check_number));
Line: 4724

    overflow_check_number := to_be_deleted_check_number - 1;
Line: 4730

      SELECT 'exist'
      INTO  overflow_exist
      FROM  ap_checks C
      WHERE C.check_stock_id = overflow_check_stock_id
      AND   C.check_number = overflow_check_number
      AND   C.status_lookup_code = 'OVERFLOW';
Line: 4747

          debug_info := 'Delete_Overflow from ap_checks';
Line: 4754

          DELETE FROM ap_checks C
          WHERE C.check_stock_id     = overflow_check_stock_id
          AND   C.check_number       = overflow_check_number
          AND   C.status_lookup_code = 'OVERFLOW';
Line: 4771

            SELECT 'exist'
            INTO  overflow_exist
            FROM  ap_checks C
            WHERE C.check_stock_id = overflow_check_stock_id
            AND   C.check_number = overflow_check_number
            AND   C.status_lookup_code = 'OVERFLOW';
Line: 4788

  CLOSE overflow_select;
Line: 4810

CURSOR setup_spoil_select is
SELECT distinct C.checkrun_name
FROM   ap_checks C, ap_invoice_selection_criteria D
WHERE  D.LAST_UPDATE_DATE <= g_activity_date
AND  C.checkrun_name NOT IN
     (SELECT distinct b.checkrun_name
      FROM   ap_checks a,
             ap_invoice_selection_criteria b
      WHERE  a.checkrun_name = b.checkrun_name
      AND    a.status_lookup_code not in
             ('SET UP', 'SPOILED'))
AND  C.checkrun_name = D.checkrun_name
AND  C.last_update_date <= g_activity_date;
Line: 4827

selected_checkrun               ap_invoice_selection_criteria.checkrun_name%TYPE;
Line: 4843

  OPEN setup_spoil_select;
Line: 4847

    debug_info := 'Fetch setup_spoil_select  Cursor';
Line: 4852

    FETCH setup_spoil_select into selected_checkrun;
Line: 4854

    EXIT WHEN setup_spoil_select%NOTFOUND OR setup_spoil_select%NOTFOUND IS NULL;
Line: 4862

    debug_info := 'delete_setup_spoil';
Line: 4867

    DELETE FROM ap_checks C
    WHERE  C.checkrun_name = selected_checkrun
    AND    C.status_lookup_code in ('SET UP','SPOILED')
    AND    C.last_update_date <= g_activity_date;
Line: 4874

    debug_info := 'delete_invoice_selection';
Line: 4879

    DELETE FROM ap_invoice_selection_criteria C
    WHERE  C.checkrun_name = selected_checkrun
    AND    C.last_update_date <= g_activity_date;
Line: 4906

  Function: Delete_AP_Tables

 *==========================================================================*/
FUNCTION Delete_AP_Tables
	 (P_Calling_Sequence   IN  VARCHAR2)
RETURN BOOLEAN IS

debug_info                   	VARCHAR2(200);
Line: 4922

to_be_deleted_check_number	NUMBER;
Line: 4931

    SELECT invoice_id
    FROM ap_purge_invoice_list
    WHERE double_check_flag = 'Y'
    and invoice_id > low_inv_id
    ORDER BY invoice_id asc;
Line: 4939

        SELECT PL.invoice_id
        FROM ap_purge_invoice_list PL
        WHERE PL.double_check_flag = 'Y'
        AND PL.invoice_id BETWEEN low_inv_id AND high_inv_id;
Line: 4955

  current_calling_sequence := 'Delete_AP_Tables<-'||P_Calling_Sequence;
Line: 4957

  debug_info := 'Starting Delete_AP_Tables';
Line: 4959

     Print('(Delete_AP_Tables)'||debug_info);
Line: 4968

  select nvl(min(invoice_id),-1)
  ,      nvl(max(invoice_id),-1)
  into range_low, range_high
  from ap_purge_invoice_list
  where double_check_flag = 'Y';
Line: 4988

        Print('(Delete_AP_Tables)'||debug_info);
Line: 4998

     delete from ap_chrg_allocations aca
     where exists (
		select 'allocations'
		from ap_invoice_distributions aid
		,    ap_purge_invoice_list    pil
		where aca.item_dist_id      = aid.invoice_distribution_id
		and   pil.invoice_id        = aid.invoice_id
              and   pil.invoice_id BETWEEN range_low and range_high
		and   pil.double_check_flag = 'Y');
Line: 5011

     DELETE FROM ap_doc_sequence_audit AUD
     WHERE (AUD.doc_sequence_id , AUD.doc_sequence_value)
            IN (SELECT C.doc_sequence_id , C.doc_sequence_value
                  FROM ap_purge_invoice_list PL,
                       ap_checks C,
                       ap_invoice_payments IP
                  WHERE PL.double_check_flag = 'Y'
                  AND   PL.invoice_id BETWEEN range_low AND range_high
                  AND   PL.invoice_id = IP.invoice_id
                  AND   IP.check_id = C.check_id ) ;
Line: 5026

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5032

            'delete_ap_tables') <> TRUE) then
         Print( 'Overflow failed!');
Line: 5037

     debug_info := 'delete_checks';
Line: 5039

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5045

     DELETE FROM ap_checks_all C
     WHERE C.check_id IN (
	   SELECT P.check_id
	   FROM ap_invoice_payments P, ap_purge_invoice_list PL
	   WHERE P.invoice_id = PL.invoice_id
	   AND PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5055

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5061

     if (Setup_Spoil('delete_ap_tables') <> TRUE) then
         Print('Setup_Spoil failed!');
Line: 5068

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5072

     DELETE FROM ap_payment_history aph
     WHERE EXISTS (
	SELECT 'history purgeable'
	FROM ap_invoice_payments aip
	,    ap_purge_invoice_list PL
	WHERE aip.invoice_id = PL.invoice_id
	and aip.check_id     = aph.check_id
	and PL.double_check_flag = 'Y');
Line: 5083

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5089

     DELETE FROM ap_invoice_payments
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5099

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5105

     DELETE FROM ap_payment_schedules
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5115

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5121

     DELETE FROM ap_trial_balance
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5130

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5136

     DELETE FROM ap_holds
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5145

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5151

     DELETE FROM ap_inv_aprvl_hist
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5161

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5165

     DELETE FROM ap_invoice_distributions
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5174

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5180

     DELETE FROM ap_doc_sequence_audit AUD
     WHERE (AUD.doc_sequence_id , AUD.doc_sequence_value)
            IN (SELECT I.doc_sequence_id , I.doc_sequence_value
                   FROM ap_purge_invoice_list PL,
                        ap_invoices I
                   WHERE PL.double_check_flag = 'Y'
                   AND   PL.invoice_id BETWEEN range_low AND range_high
                   AND   PL.invoice_id = I.invoice_id);
Line: 5198

	--delete all related transactions: dists, holds, payment shedules, payments
        AP_DBI_PKG.Maintain_DBI_Summary
              (p_table_name => 'AP_INVOICES',
               p_operation => 'D',
               p_key_value1 => l_invoice_id,
                p_calling_sequence => current_calling_sequence);
Line: 5210

        Print('(Delete_AP_Tables)'||debug_info);
Line: 5216

     DELETE FROM ap_invoices
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND PL.invoice_id BETWEEN range_low AND range_high);
Line: 5247

     Print('(Delete_AP_Tables)'||debug_info);
Line: 5253

  DELETE FROM ap_batches B
  WHERE B.last_update_date <= g_activity_date
  AND NOT EXISTS (
	  SELECT null
	  FROM ap_invoices I
	  WHERE I.batch_id = B.batch_id);
Line: 5262

  debug_info := 'Completed deleteing from Oracle Payables';
Line: 5264

     Print('(Delete_AP_Tables)'||debug_info);
Line: 5277

END Delete_AP_Tables;
Line: 5298

to_be_deleted_check_number	NUMBER;
Line: 5304

    SELECT invoice_id
    FROM ap_purge_invoice_list
    WHERE double_check_flag = 'Y'
    and invoice_id > low_inv_id
    ORDER BY invoice_id asc;
Line: 5317

  SELECT nvl(min(invoice_id),-1)
  ,      nvl(max(invoice_id),-1)
  into range_low, range_high
  FROM   ap_purge_invoice_list
  WHERE  double_check_flag = 'Y';
Line: 5355

  DELETE   FROM   ap_liability_balance alb
  WHERE  EXISTS   (
         SELECT   'records exist'
           FROM   ap_purge_invoice_list   pil
	  WHERE   alb.invoice_id          = pil.invoice_id
            AND   pil.double_check_flag   = 'Y'
            AND   pil.invoice_id BETWEEN  range_low
                                     AND  range_high)
  AND             journal_sequence_id IS NULL;
Line: 5369

 DELETE FROM ap_ae_lines ael
  WHERE ael.ae_header_id in
      ( SELECT aeh.ae_header_id
          FROM ap_ae_headers          aeh
              ,ap_accounting_events   aae
              ,ap_purge_invoice_list  pil
          WHERE aae.source_id              = pil.invoice_id
           and aae.source_table            = 'AP_INVOICES'
           and aae.accounting_event_id     = aeh.accounting_event_id
           and pil.double_check_flag       = 'Y'
           and pil.invoice_id BETWEEN range_low AND range_high) ;
Line: 5381

 DELETE FROM ap_ae_lines ael
  WHERE ael.ae_header_id in
        ( SELECT aeh.ae_header_id
            FROM ap_ae_headers        aeh  -- bug 2153117 added
              ,ap_accounting_events   aae
              ,ap_invoice_payments    aip
              ,ap_purge_invoice_list  pil
        WHERE aae.source_id              = aip.check_id
              and aae.source_table        = 'AP_CHECKS'
              and pil.double_check_flag  = 'Y'
              and aae.accounting_event_id = aeh.accounting_event_id
              and aip.invoice_id          = pil.invoice_id
              and pil.invoice_id BETWEEN range_low AND range_high);
Line: 5401

  DELETE FROM ap_ae_headers aeh
  WHERE aeh.accounting_event_id IN
      ( SELECT  aae.accounting_event_id
	FROM  ap_accounting_events     aae
        ,     ap_purge_invoice_list    pil
	WHERE aae.source_id           = pil.invoice_id
	and   aae.source_table        = 'AP_INVOICES'
	and   pil.double_check_flag   = 'Y'
        -- Commented the below line as a fix for bug 2880690
        -- and   aae.accounting_event_id = aeh.accounting_event_id
        and   pil.invoice_id BETWEEN range_low AND range_high
       ) ;
Line: 5415

  DELETE FROM ap_ae_headers aeh
  WHERE  aeh.accounting_event_id in
      ( SELECT aae.accounting_event_id
	FROM  ap_accounting_events   aae
        ,     ap_invoice_payments    aip
 	,     ap_purge_invoice_list  pil
	-- bug2153117 removed
        -- ,     ap_ae_headers          aeh
	WHERE aae.source_id           = aip.check_id
	and   aae.source_table        = 'AP_CHECKS'
	and   pil.double_check_flag   = 'Y'
        -- Commented the below line as a fix for bug 2880690
        -- and   aae.accounting_event_id = aeh.accounting_event_id
 	and   aip.invoice_id          = pil.invoice_id
        and   pil.invoice_id BETWEEN range_low AND range_high) ;
Line: 5438

  DELETE FROM ap_encumbrance_lines aen
  WHERE EXISTS (
	SELECT 'dist'
	FROM  ap_purge_invoice_list    pil
	,     ap_invoice_distributions aid
	WHERE aen.invoice_distribution_id  = aid.invoice_distribution_id
	and   aid.invoice_id               = pil.invoice_id
        and   pil.double_check_flag        = 'Y'
        and   pil.invoice_id BETWEEN range_low AND range_high);
Line: 5450

/*  -- delete_ap_accounting_events
    -- Fix for bug 2545172 , commented above delete statement and wrote
    -- below 3 delete statement

  DELETE FROM AP_ACCOUNTING_EVENTS AAE
  WHERE aae.source_id in (SELECT PIL.INVOICE_ID
                            FROM AP_PURGE_INVOICE_LIST PIL
                          WHERE  PIL.DOUBLE_CHECK_FLAG = 'Y'
                          AND PIL.INVOICE_ID BETWEEN range_low AND range_high )
        AND AAE.SOURCE_TABLE = 'AP_INVOICES'
        ;
Line: 5462

  DELETE FROM AP_ACCOUNTING_EVENTS AAE  WHERE
            aae.source_id in ( SELECT APC.CHECK_ID
                                FROM AP_PURGE_INVOICE_LIST PIL,
                                      AP_CHECKS APC,
                                      AP_INVOICE_PAYMENTS AIP
                                WHERE PIL.DOUBLE_CHECK_FLAG = 'Y'
                                      AND APC.CHECK_ID = AIP.CHECK_ID
                                      AND AIP.INVOICE_ID = PIL.INVOICE_ID
                                      AND PIL.INVOICE_ID BETWEEN range_low
                                          AND range_high )
            AND AAE.SOURCE_TABLE = 'AP_CHECKS' ;
Line: 5475

  DELETE FROM AP_ACCOUNTING_EVENTS AAE  WHERE
            AAE.source_id IN ( SELECT APH.CHECK_ID
                               FROM AP_PURGE_INVOICE_LIST PIL,
                                    AP_INVOICE_PAYMENTS AIP,
                                    AP_PAYMENT_HISTORY APH
                              WHERE PIL.DOUBLE_CHECK_FLAG = 'Y'
                                    AND APH.CHECK_ID = AIP.CHECK_ID
                                    AND AIP.INVOICE_ID = PIL.INVOICE_ID
                                    AND PIL.INVOICE_ID BETWEEN range_low
                                        AND range_high )
            and AAE.SOURCE_TABLE = 'AP_PAYMENT_HISTORY'  ;
Line: 5541

    SELECT schedule_item_id
    FROM chv_purge_schedule_list
    WHERE double_check_flag = 'Y'
    and schedule_item_id > low_chv_id
    ORDER BY schedule_item_id asc;
Line: 5573

  select nvl(min(schedule_item_id),-1)
  ,      nvl(max(schedule_item_id),-1)
  into range_low, range_high
  from chv_purge_schedule_list
  where double_check_flag = 'Y';
Line: 5599

      update chv_schedule_items csi
      set csi.item_purge_status = 'PURGED'
      where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = csi.schedule_item_id
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5615

      delete from chv_item_orders cio
      where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = cio.schedule_item_id
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5630

      delete from chv_horizontal_Schedules chs
      where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = chs.schedule_item_id
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5645

     delete from chv_authorizations ca
     where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = ca.reference_id
           and   ca.reference_type = 'SCHEDULE_ITEMS'
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5682

   delete from chv_authorizations ca
   where exists
        (select null
         from  chv_purge_cum_list cpcl
         where cpcl.cum_period_id = ca.reference_id
         and   cpcl.double_check_flag = 'Y'
	 and   ca.reference_type = 'CUM_PERIODS');
Line: 5697

   delete from chv_cum_adjustments cca
   where exists
        (select null
         from  chv_purge_cum_list cpcl
         where cpcl.cum_period_id = cca.cum_period_id
         and   cpcl.double_check_flag = 'Y');
Line: 5711

   delete from chv_cum_periods ccp
   where exists
        (select null
         from  chv_purge_cum_list cpcl
         where cpcl.cum_period_id = ccp.cum_period_id
         and   cpcl.double_check_flag = 'Y');
Line: 5727

   delete from   chv_schedule_items csi
   where not exists (select null
                       from chv_schedule_items cs
                      where csi.schedule_id = cs.schedule_id
                        and nvl(cs.item_purge_status,'ACTIVE') <> 'PURGED');
Line: 5742

   delete from chv_schedule_headers csh
   where not exists (select null
                       from chv_schedule_items csi
                      where csh.schedule_id = csi.schedule_id );
Line: 5783

    SELECT schedule_item_id
    FROM chv_purge_schedule_list
    WHERE double_check_flag = 'Y'
    and schedule_item_id > low_chv_id
    ORDER BY schedule_item_id asc;
Line: 5815

  select nvl(min(schedule_item_id),-1)
  ,      nvl(max(schedule_item_id),-1)
  into range_low, range_high
  from chv_purge_schedule_list
  where double_check_flag = 'Y';
Line: 5838

      update chv_schedule_items csi
      set csi.item_purge_status = 'PURGED'
      where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = csi.schedule_item_id
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5854

      delete from chv_item_orders cio
      where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = cio.schedule_item_id
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5869

      delete from chv_horizontal_Schedules chs
      where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = chs.schedule_item_id
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5884

     delete from chv_authorizations ca
     where exists
          (select null
           from  chv_purge_schedule_list cpsl
           where cpsl.schedule_item_id = ca.reference_id
           and   ca.reference_type = 'SCHEDULE_ITEMS'
           and   cpsl.double_check_flag = 'Y'
           and   cpsl.schedule_item_id between range_low and range_high);
Line: 5919

   delete from   chv_schedule_items csi
   where not exists (select null
                       from chv_schedule_items cs
                      where csi.schedule_id = cs.schedule_id
                        and nvl(cs.item_purge_status,'ACTIVE') <> 'PURGED');
Line: 5928

   delete from chv_schedule_headers csh
   where not exists (select null
                       from chv_schedule_items csi
                      where csh.schedule_id = csi.schedule_id );
Line: 5965

select vendor_id
from  po_purge_vendor_list pvl
where  pvl.double_check_flag = 'Y';
Line: 5970

select vendor_id,
       vendor_site_id
from   po_vendor_sites_all
where  vendor_id in (select vendor_id
                     from   po_purge_vendor_list pvl
                     where  pvl.double_check_flag = 'Y');
Line: 5992

  delete from ap_suppliers vnd
  where exists
        (select null
	 from po_purge_vendor_list pvl
	 where pvl.vendor_id = vnd.vendor_id
	 and   pvl.double_check_flag = 'Y');
Line: 6028

  delete from ap_supplier_sites_all vnd
  where exists
        (select null
	 from po_purge_vendor_list pvl
	 where pvl.vendor_id = vnd.vendor_id
	 and   pvl.double_check_flag = 'Y');
Line: 6041

  delete from ap_supplier_contacts pc
  where not exists
            (select null
	     from ap_supplier_sites_all ps
	     where ps.vendor_site_id = pc.vendor_site_id);
Line: 6054

  delete from ap_bank_account_uses_all abau
  where exists
        (select null
	 from po_purge_vendor_list pvl
	 where pvl.vendor_id = abau.vendor_id
	 and   pvl.double_check_flag = 'Y');
Line: 6070

      delete from po_vendor_list_entries pvle
      where not exists
            (select null
	     from ap_suppliers vnd
	     where vnd.vendor_id = pvle.vendor_id);
Line: 6081

      delete from po_vendor_list_headers h
      where not exists
            (select null
	     from po_vendor_list_entries e
	     where e.vendor_list_header_id =
                   h.vendor_list_header_id);
Line: 6095

      delete from po_asl_documents pad where
      exists (select null from po_asl_attributes paa,
                          po_purge_vendor_list pvl
	 where pvl.vendor_id = paa.vendor_id
	 and   pvl.double_check_flag = 'Y'
         and   paa.using_organization_id = pad.using_organization_id
         and   paa.asl_id = pad.asl_id);
Line: 6105

      delete from po_asl_attributes paa
      where exists
        (select null
	 from po_purge_vendor_list pvl
	 where pvl.vendor_id = paa.vendor_id
	 and   pvl.double_check_flag = 'Y');
Line: 6119

      delete from po_approved_supplier_list pasl
      where exists
        (select null
	 from po_purge_vendor_list pvl
	 where pvl.vendor_id = pasl.vendor_id
	 and   pvl.double_check_flag = 'Y');
Line: 6164

      update mrp_sourcing_rules msr
      set planning_active = 2
      where exists (select null
                    from po_purge_vendor_list pvl,
                    mrp_sr_source_org msso,
                    mrp_sr_receipt_org msro
                    where pvl.vendor_id = msso.vendor_id
                    and msso.sr_receipt_id = msro.sr_receipt_id
                    and msro.sourcing_rule_id = msr.sourcing_rule_id
                    and   pvl.double_check_flag = 'Y');
Line: 6175

     update mrp_recommendations mr
     set source_vendor_id = null, source_vendor_site_id = null
     where exists (select null
                   from po_purge_vendor_list pvl
                   where pvl.vendor_id = mr.source_vendor_id
                   and   pvl.double_check_flag = 'Y');
Line: 6182

     delete from mrp_sr_source_org msso
     where exists (select null
                   from po_purge_vendor_list pvl
                   where pvl.vendor_id = msso.vendor_id
                   and   pvl.double_check_flag = 'Y');
Line: 6188

     delete from mrp_item_sourcing mis
     where exists (select null
                   from po_purge_vendor_list pvl
                   where pvl.vendor_id = mis.vendor_id
                   and   pvl.double_check_flag = 'Y');
Line: 6213

  Function: Delete_Seeded_Data

 *==========================================================================*/
FUNCTION Delete_Seeded_Data
	 (P_Purge_Name          IN  VARCHAR2,
          P_Category            IN  VARCHAR2,
          P_activity_Date       IN  DATE,
          P_Range_Size          IN  NUMBER,
          P_Purchasing_Status   IN  VARCHAR2,
          P_MRP_Status          IN  VARCHAR2,
          P_Debug_Switch        IN  VARCHAR2,
          P_Calling_Sequence    IN  VARCHAR2)
RETURN BOOLEAN IS

debug_info                   	VARCHAR2(200);
Line: 6271

  current_calling_sequence := 'Delete_Seeded_Data<-'||P_Calling_Sequence;
Line: 6275

  debug_info := 'Starting Delete_Seeded_Data';
Line: 6277

     Print('(Delete_Seeded_Data)'||debug_info);
Line: 6284

     if (delete_ap_tables('Delete_Seeded_Data') <> TRUE) then
        Print('delete_ap_tables failed!');
Line: 6299

   if (purge_accounting('Delete_Seeded_Data') <> TRUE) then
        Print('purge_accounting failed!');
Line: 6321

     PO_AP_PURGE_GRP.delete_records
     ( p_api_version => 1.0,
       p_init_msg_list => 'T',
       p_commit => 'T',
       x_return_status => l_po_return_status,
       x_msg_data => l_po_msg,
       p_purge_name => p_purge_name,
       p_purge_category => p_category,
       p_range_size => p_range_size);
Line: 6358

   if (delete_ap_tables('Delete_Seeded_Data') <> TRUE) then
        Print('delete_ap_tables failed!');
Line: 6363

   PO_AP_PURGE_GRP.delete_records
     ( p_api_version => 1.0,
       p_init_msg_list => 'T',
       p_commit => 'T',
       x_return_status => l_po_return_status,
       x_msg_data => l_po_msg,
       p_purge_name => p_purge_name,
       p_purge_category => p_category,
       p_range_size => p_range_size);
Line: 6387

   if (purge_accounting('Delete_Seeded_Data') <> TRUE) then
        Print('purge_accounting failed!');
Line: 6428

   if (purge_vendors('Delete_Seeded_Data') <> TRUE) then
        Print('purge_vendors failed!');
Line: 6457

   if (purge_schedules_by_org('Delete_Seeded_Data') <> TRUE) then
        Print('purge_schedules_by_org failed!');
Line: 6470

		      'Delete Seeded Data')
        <> TRUE) then
        Print('purge_schedules_by_org failed!');
Line: 6480

  if (purge_schedules_by_cum('Delete_Seeded_Data') <> TRUE) then
       Print('purge_schedules_by_cum failed!');
Line: 6494

		      'Delete Seeded Data')
        <> TRUE) then
        Print('purge_schedules_by_cum failed!');
Line: 6502

  UPDATE financials_purges
  SET
  ap_checks              = nvl(ap_checks, 0) - check_rows,
  ap_invoice_payments    = nvl(ap_invoice_payments, 0) - invoice_payment_rows,
  ap_invoices            = nvl(ap_invoices, 0) - invoice_rows,
  po_headers             = nvl(po_headers, 0) - po_header_rows,
  po_requisition_headers = nvl(po_requisition_headers, 0) - req_header_rows,
  po_vendors             = nvl(po_vendors, 0) - vendor_rows,
  po_receipts            = nvl(po_receipts, 0) - shipment_line_rows,
  po_approved_supplier_list = nvl(po_approved_supplier_list,0) - po_asl_rows,
  po_asl_attributes      = nvl(po_asl_attributes,0) - po_asl_attr_rows,
  po_asl_documents       = nvl(po_asl_documents,0) - po_asl_doc_rows,
  chv_authorizations     = nvl(chv_authorizations,0) - chv_auth_rows,
  chv_cum_adjustments    = nvl(chv_cum_adjustments,0) - chv_cum_adj_rows,
  chv_cum_periods	 = nvl(chv_cum_periods,0) - chv_cum_rows,
  chv_horizontal_Schedules = nvl(chv_horizontal_schedules,0) - chv_hor_rows,
  chv_item_orders        = nvl(chv_item_orders,0) - chv_ord_rows,
  chv_schedule_headers   = nvl(chv_schedule_headers,0) - chv_head_rows,
  chv_schedule_items     = nvl(chv_schedule_items,0) - chv_item_rows,
  ap_ae_lines		 = nvl(ap_ae_lines,0) - ae_line_rows,
  ap_ae_headers		 = nvl(ap_ae_headers,0) - ae_header_rows,
  ap_accounting_events 	 = nvl(ap_accounting_events,0) - accounting_event_rows
  WHERE purge_name = p_purge_name;
Line: 6549

  delete from ap_purge_invoice_list;
Line: 6551

  PO_AP_PURGE_GRP.delete_purge_lists
  (  p_api_version => 1.0,
     p_init_msg_list => 'T',
     p_commit => 'F',
     x_return_status => l_po_return_status,
     x_msg_data => l_po_msg,
     p_purge_name => p_purge_name);
Line: 6560

  delete from po_purge_vendor_list;
Line: 6563

  delete from chv_purge_schedule_list;
Line: 6566

  delete from chv_purge_cum_list;
Line: 6574

                       'Delete_Seeded_Data')
         <> TRUE) then
        Print('set_purge_status failed!');
Line: 6589

END Delete_Seeded_Data;
Line: 6600

 delete from ap_history_checks
 where purge_name = g_purge_name;
Line: 6619

  delete from chv_history_schedules
  where purge_name = g_purge_name;
Line: 6622

  delete from chv_history_cum_periods
  where purge_name = g_purge_name;
Line: 6642

  delete from chv_purge_schedule_list;
Line: 6643

  delete from chv_purge_cum_list;
Line: 6662

  delete from chv_history_schedules
  where purge_name = g_purge_name;
Line: 6683

  delete from chv_purge_schedule_list;
Line: 6703

  delete from ap_history_invoices
  where purge_name = g_purge_name;
Line: 6724

  delete from ap_purge_invoice_list;
Line: 6744

  delete from ap_history_invoice_payments ahp
  where not exists (select null
                  from ap_history_invoices ahi
                  where ahi.invoice_id = ahp.invoice_id);
Line: 6767

  delete from po_history_vendors
  where purge_name = g_purge_name;
Line: 6788

  delete from po_purge_vendor_list;
Line: 6844

   PO_AP_PURGE_GRP.delete_purge_lists
   (  p_api_version => 1.0,
      p_init_msg_list => 'T',
      p_commit => 'T',
      x_return_status => l_po_return_status,
      x_msg_data => l_po_msg,
      p_purge_name => p_purge_name);
Line: 6887

     PO_AP_PURGE_GRP.delete_history_tables
     (  p_api_version => 1.0,
        p_init_msg_list => 'T',
        p_commit => 'T',
        x_return_status => l_po_return_status,
        x_msg_data => l_po_msg,
        p_purge_name => p_purge_name);