DBA Data[Home] [Help]

APPS.AP_PURGE_PKG SQL Statements

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

Line: 30

Procedure Update_Financials_Purges ( p_check_rows             IN NUMBER DEFAULT 0,
                                     p_invoice_payment_rows   IN NUMBER DEFAULT 0,
                                     p_invoice_rows           IN NUMBER DEFAULT 0,
                                     p_ae_line_rows	      IN NUMBER DEFAULT 0,
                                     p_ae_header_rows	      IN NUMBER DEFAULT 0,
                                     p_accounting_event_rows  IN NUMBER DEFAULT 0,
                                     p_invoice_lines_rows     IN NUMBER DEFAULT 0,               --bug 11829621
                                     p_invoice_distributions_rows IN NUMBER DEFAULT 0,           --bug 11829621
				     p_purge_name             IN VARCHAR2         );
Line: 99

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

      /* 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: 212

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

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

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

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

  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: 408

  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: 436

     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: 459

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

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

  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: 542

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

  SELECT MAX( invoice_id )
  INTO   max_inv_id
  FROM   ap_invoices ;
Line: 602

  SELECT MAX( check_id )
  INTO   max_chk_id
  FROM   ap_invoice_payments ; */
Line: 605

  SELECT last_number
  INTO   max_inv_id
  FROM   all_sequences
  WHERE  sequence_owner = l_sch_name
  AND    sequence_name  = 'AP_INVOICES_S' ;
Line: 611

  SELECT last_number
  INTO   max_chk_id
  FROM   all_sequences
  WHERE  sequence_owner = l_sch_name
  AND    sequence_name  = 'AP_CHECKS_S' ;
Line: 632

    tab_inv_vc2.DELETE ;     -- Bug 8942883
Line: 633

    tab_check_vc2.DELETE ;   -- Bug 8942883
Line: 665

               UPDATE ap_purge_invoice_list
                  SET double_check_flag = 'S'
                WHERE invoice_id = p_id_vc2 ;
Line: 670

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

        /* if this chain is not purgeable, delete selected invoice from purge list */
	IF use_vc2 THEN					-- Bug 8942883
	   p_count := tab_inv_vc2.count;
Line: 692

               DELETE FROM ap_purge_invoice_list
                 WHERE invoice_id = p_id_vc2 ;
Line: 696

               DELETE FROM ap_purge_invoice_list
                 WHERE invoice_id = p_id ;
Line: 702

        /* delete unpurgeable list beforehand for performance */
	IF use_vc2 THEN					-- Bug 8942883
	   p_count := tab_check_vc2.count;
Line: 716

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

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

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

  SELECT invoice_id
    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.pa_addition_flag in ('Y','T'))
        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: 810

  DELETE /*+ PARALLEL(pl) ROWID(pl) */
    FROM ap_purge_invoice_list pl
   WHERE pl.rowid IN
        (SELECT /*+ ORDERED PARALLEL(pl1) FULL(pl1) USE_NL(i,ps)
                    INDEX(i AP_INVOICES_U1) INDEX(ps AP_PAYMENT_SCHEDULES_U1) */
                pl1.rowid
           FROM ap_purge_invoice_list pl1,
                ap_invoices i,
                ap_payment_schedules ps
          WHERE i.invoice_id = pl1.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: 836

   DELETE
   FROM ap_purge_invoice_list PL
   WHERE EXISTS (
        SELECT 'Invoices are not transfered to PA'
        FROM ap_invoices I,
             ap_invoice_distributions D
        WHERE I.invoice_id = PL.invoice_id
          AND I.invoice_id = D.invoice_id
          AND I.source = 'Oracle Project Accounting'
          AND D.pa_addition_flag not in ('Y','T','E','Z') );
Line: 847

    /*   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: 874

      DELETE
      FROM ap_purge_invoice_list
      WHERE invoice_id = l_invoice_id;
Line: 910

      DELETE /*+ PARALLEL(pl) ROWID(pl) */
        FROM ap_purge_invoice_list pl
       WHERE pl.rowid IN
             (SELECT /*+ ORDERED PARALLEL(pl1) FULL(pl1) USE_NL(i,d)
                         INDEX(i AP_INVOICES_U1) INDEX(d AP_INVOICE_DISTRIBUTIONS_U1) */
                     pl1.rowid
                FROM ap_purge_invoice_list pl1,
                     ap_invoices i,
                     ap_invoice_distributions d
               WHERE i.invoice_id = pl1.invoice_id
                 AND i.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_tracking_flag = 'Y' /* bug 11707744 */
                          AND d.assets_addition_flag || '' = decode(g_assets_status,'Y','U','cantequalme')
                          AND i.cancelled_date IS NULL)));
Line: 935

     DELETE
     FROM ap_purge_invoice_list PL
     WHERE EXISTS
              (SELECT /*+ no_unnest */ 'distributions not purgeable' -- 7759218
	 	 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_tracking_flag = 'Y'   /* bug 11707744 */
                           AND D.assets_addition_flag||'' =
       	                       DECODE(g_assets_status,
                                      'Y', 'U',
		                      'cantequalme')
                           AND I.cancelled_date IS NULL)));
Line: 978

  DELETE /*+ PARALLEL(pl) ROWID(pl) */
    FROM ap_purge_invoice_list pl
   WHERE pl.rowid IN
         (SELECT /*+ ORDERED PARALLEL(pl1) FULL(pl1) USE_NL(p,c)
                     INDEX(p AP_INVOICE_PAYMENTS_N1) INDEX(c AP_CHECKS_U1) */
                 pl1.rowid
            FROM ap_purge_invoice_list pl1,
                 ap_invoice_payments p,
                 ap_checks c
           WHERE p.invoice_id = pl1.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 (c.future_pay_due_date IS NOT NULL AND c.status_lookup_code = 'ISSUED')
                   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))
          );
Line: 999

   DELETE /*+ PARALLEL(pl) ROWID(pl) */
     FROM ap_purge_invoice_list pl
    WHERE pl.rowid IN
          (SELECT /*+ ORDERED PARALLEL(pl1) FULL(pl1) USE_NL(p, sr)
                      INDEX(p AP_INVOICE_PAYMENTS_N1) INDEX(sr CE_STATEMENT_RECONS_N2) */
         DISTINCT pl1.rowid
             FROM ap_purge_invoice_list pl1,
                  ap_invoice_payments p,
                  ce_statement_reconciliations sr
            WHERE p.invoice_id = pl1.invoice_id
              AND p.check_id = sr.reference_id
              AND sr.reference_type = 'PAYMENT'
          );
Line: 1023

   	DELETE
   	FROM ap_purge_invoice_list PL
   	WHERE EXISTS
	       (SELECT  /*+ no_unnest */ 'related to prepayment' -- 7759218
		FROM    ap_invoice_prepays IP
		WHERE	PL.invoice_id = IP.invoice_id
		OR	PL.invoice_id = IP.prepay_id);
Line: 1034

        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: 1052

  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: 1063

          and aph.last_update_date > g_activity_date);
Line: 1073

  DELETE /*+ PARALLEL(pl) ROWID(pl) */
   FROM ap_purge_invoice_list PL
  WHERE pl.rowid IN (
          Select /*+ ORDERED PARALLEL(pl1) FULL(pl1) */
                pl1.rowid -- 7759218
          from  ap_purge_invoice_list pl1,
                ap_invoices_all ai,
                xla_events xe, --Bug 4588031
                xla_transaction_entities xte, --Bug 4588031
                xla_ae_headers xeh, --Bug 4588031
                ap_system_parameters_all asp--bug5052748
          where xte.entity_code = 'AP_INVOICES'
          and NVL(XTE.SOURCE_ID_INT_1,-99) = PL1.invoice_id    --11059839
          AND pl1.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 ))
          UNION
          Select /*+ ORDERED PARALLEL(pl1) FULL(pl1) */
                pl1.rowid -- 7759218
          from  ap_purge_invoice_list pl1,
                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   NVL(XTE.SOURCE_ID_INT_1,-99) = aip.check_id          --11059839
          and   xte.entity_id = xe.entity_id
          AND   asp.set_of_books_id=xte.ledger_id
          AND   aip.org_id=asp.org_id
          and   PL1.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: 1126

   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: 1134

  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: 1149

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

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

           delete from ap_purge_invoice_list apl
	   where exists
	        (select /*+ no_unnest */ null -- 7759218
	         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: 1277

           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: 1295

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

           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: 1329

              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: 1347

              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: 1364

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

  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: 1466

  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: 1519

  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: 1569

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

   SELECT NVL( approx_rows, 0 ),
          NVL(pay_alone,'A')
   INTO   l_approx_rows,
          l_pay_alone
   FROM   financials_purges
   WHERE  purge_name = p_purge_name ;
Line: 1598

        INSERT INTO ap_purge_invoice_list pl
          (
            invoice_id,
            purge_name,
            double_check_flag
          )
        WITH purge_inv AS
          (SELECT /*+ MATERIALIZE INDEX(i AP_INVOICES_N5) */ rowid inv_rowid
             FROM ap_invoices i
            WHERE i.invoice_date <= g_activity_date
          ) ,
          purge_zero_inv AS
          (SELECT /*+ MATERIALIZE INDEX(i AP_INVOICES_N4)*/ rowid inv_rowid
             FROM ap_invoices i
            WHERE i.invoice_amount = 0
          )
        SELECT invoice_id, p_purge_name purge_name, 'Y' double_check_flag
          FROM
          (SELECT invoice_id, check_id
             FROM
            (SELECT /*+ ORDERED PARALLEL(PI) FULL(pi) USE_NL(i,p,c,d,l)
                    INDEX(p AP_INVOICE_PAYMENTS_N1) INDEX(c AP_CHECKS_U1) INDEX(d
                    AP_INVOICE_DISTRIBUTIONS_U1) INDEX(l AP_INVOICE_LINES_U1) */
              i.invoice_id, MIN(c.check_id) check_id
            FROM purge_inv pi,
              ap_invoices i,
              ap_invoice_payments p,
              ap_checks c,
              ap_invoice_distributions d,
              ap_invoice_lines l
            WHERE i.rowid    = pi.inv_rowid
            AND i.invoice_id = l.invoice_id
            AND i.invoice_id = d.invoice_id
            AND l.line_number = d.invoice_line_number -- bug14237038
            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)
            OR d.cash_posted_flag = DECODE(p_using_cash_basis, 'Y', 'Y', d.cash_posted_flag))
            AND d.last_update_date <= g_activity_date
            AND	l.last_update_date <= g_activity_date
            AND i.last_update_date <= g_activity_date
            AND p.invoice_id = i.invoice_id
            AND p.check_id = c.check_id
            AND p.last_update_date <= g_activity_date
            AND c.last_update_date <= g_activity_date
            AND NVL(i.exclusive_payment_flag, 'N') = DECODE(l_pay_alone, 'N', 'N', 'A',
                                                NVL(i.exclusive_payment_flag, 'N'), 'Y')
            GROUP BY i.invoice_id
            UNION
            SELECT /*+ ORDERED PARALLEL(pzi) FULL(pzi) USE_NL(i,p,d)
                       INDEX(p AP_INVOICE_PAYMENTS_N1) INDEX(d AP_INVOICE_DISTRIBUTIONS_U1) */
               i.invoice_id, NULL check_id
              FROM purge_zero_inv pzi,
                   ap_invoices i,
                   ap_invoice_payments p,
                   ap_invoice_distributions d
            WHERE i.rowid                   = pzi.inv_rowid
              AND p.invoice_id (+)            = i.invoice_id
              AND i.invoice_id                = d.invoice_id(+)
              AND i.last_update_date         <= g_activity_date
              AND i.invoice_date             <= g_activity_date
              AND i.invoice_type_lookup_code <> 'PREPAYMENT'
              AND p.check_id                 IS NULL
            GROUP BY i.invoice_id
            HAVING SUM(NVL(d.amount, 0)) = 0
            )
          ORDER BY DECODE(l_pay_alone, 'Y', invoice_id, 'N', check_id, check_id),
            DECODE(l_pay_alone, 'Y', check_id, 'N', invoice_id, invoice_id)
          )
        WHERE(l_approx_rows = 0 OR rownum <= l_approx_rows) ;
Line: 1681

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

	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: 1748

 	      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: 1766

		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: 1793

		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: 1859

	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: 1873

     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: 1897

     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: 1925

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

     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: 1965

     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: 2070

  select nvl(pay_alone,'A')
    into l_pay_alone
    from financials_purges
   where purge_name =  P_Purge_Name ;
Line: 2340

range_inserted  VARCHAR2(1);
Line: 2361

        range_inserted := 'N';
Line: 2365

        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: 2375

        range_inserted := 'N';
Line: 2378

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

          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: 2411

          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: 2444

          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: 2494

range_inserted  VARCHAR2(1);
Line: 2508

  range_inserted := 'N';
Line: 2514

  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: 2523

      range_inserted := 'N';
Line: 2526

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

          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: 2585

range_inserted  VARCHAR2(1);
Line: 2609

        range_inserted := 'N';
Line: 2612

        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: 2629

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

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

          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: 2687

  range_inserted := 'N';
Line: 2690

  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: 2702

      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: 2770

  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: 2777

  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: 2784

  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: 2791

  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: 2868

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

  SELECT invoice_id
    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.pa_addition_flag in ('Y','T'))
        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: 3004

  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: 3025

  UPDATE ap_purge_invoice_list PL
  SET PL.double_check_flag = 'N'
  WHERE PL.double_check_flag = 'Y'
  AND EXISTS(
                SELECT 'lines no longer purgeable'
                FROM ap_invoice_lines IL
                WHERE PL.invoice_id = IL.invoice_id
                AND IL.last_update_date > g_activity_date );
Line: 3044

     UPDATE ap_purge_invoice_list PL
     SET PL.double_check_flag = 'N'
     WHERE PL.double_check_flag = 'Y'
     AND EXISTS (
        SELECT 'Invoices are not transfered to PA'
        FROM ap_invoices I,
             ap_invoice_distributions D
        WHERE I.invoice_id = PL.invoice_id
          AND I.invoice_id = D.invoice_id
          AND I.source <> 'Oracle Project Accounting'
          AND D.pa_addition_flag not in ('Y','T','E','Z') );
Line: 3056

           /* 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: 3089

     	  UPDATE ap_purge_invoice_list PL
     	  SET PL.double_check_flag = 'N'
          WHERE PL.double_check_flag = 'Y'
      	  AND invoice_id = l_invoice_id;
Line: 3113

  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: 3145

        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_tracking_flag = 'Y' /* bug 11707744 */
                         AND D.assets_addition_flag||'' =
                             Decode(g_Assets_Status,
                                    'Y', 'U',
                                    'cantequalme')
                         AND I.cancelled_date IS NULL)));
Line: 3165

        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_tracking_flag = 'Y' /* bug 11707744 */
                         AND D.assets_addition_flag||'' =
                             Decode(g_Assets_Status,
                                    'Y', 'U',
                                    'cantequalme')
                         AND I.cancelled_date IS NULL)));
Line: 3192

        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: 3215

        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: 3231

        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: 3250

        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: 3276

   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 NVL(XTE.SOURCE_ID_INT_1,-99) = PL.invoice_id    /* Bug#12615876 */
                 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 (
   /* Changed the subquery - bug 12955426. Now the delete stmt (in Do_independent_inv_checks())
      and update stmt (in Retest_Invoice_Independents()) has same queries. */
                 Select 'payment accounting not purgeable' -- 7759218
          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   NVL(XTE.SOURCE_ID_INT_1,-99) = aip.check_id          --11059839
          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: 3320

		 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  NVL(XTE.SOURCE_ID_INT_1,-99) = apc.check_id --Bug#12615876
                 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: 3368

   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: 3388

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

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

  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: 3473

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

  SELECT COUNT(*) into l_dummy
FROM ap_invoice_payments_all aip
WHERE check_id IN
  (SELECT DISTINCT check_id
   FROM ap_invoice_payments_all
   WHERE invoice_id IN
    (SELECT invoice_id
     FROM ap_purge_invoice_list
     WHERE double_check_flag = 'Y') )
AND NOT EXISTS
  (SELECT 'CHECK'
   FROM ap_purge_invoice_list pil
   WHERE pil.invoice_id = aip.invoice_id)
AND ROWNUM =1;
Line: 3571

  SELECT MAX( invoice_id )
  INTO   max_inv_id
  FROM   ap_invoices ;
Line: 3575

  SELECT MAX( check_id )
  INTO   max_chk_id
  FROM   ap_invoice_payments ; */
Line: 3578

  SELECT last_number
  INTO   max_inv_id
  FROM   all_sequences
  WHERE  sequence_owner = l_sch_name
  AND    sequence_name  = 'AP_INVOICES_S' ;
Line: 3584

  SELECT last_number
  INTO   max_chk_id
  FROM   all_sequences
  WHERE  sequence_owner = l_sch_name
  AND    sequence_name  = 'AP_CHECKS_S' ;
Line: 3605

    tab_inv_vc2.DELETE   ; -- Bug 8942883
Line: 3606

    tab_check_vc2.DELETE ; -- Bug 8942883
Line: 3638

               UPDATE ap_purge_invoice_list
                  SET double_check_flag = 'S'
                WHERE invoice_id = p_id_vc2 ;
Line: 3643

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

        /* if this chain is not purgeable, delete selected invoice from purge list */
        IF use_vc2 THEN					-- Bug 8942883
	   p_count := tab_inv_vc2.count;
Line: 3665

               UPDATE ap_purge_invoice_list
                  SET double_check_flag = 'N'
                WHERE invoice_id = p_id_vc2 ;
Line: 3670

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

        /* delete unpurgeable list beforehand for performance */
	IF use_vc2 THEN					-- Bug 8942883
	   p_count := tab_check_vc2.count;
Line: 3691

               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_vc2);
Line: 3698

               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: 3714

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

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

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

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

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

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

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

  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: 3997

        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: 4015

     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: 4042

     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: 4076

     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: 4097

     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: 4117

     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: 4177

  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: 4222

  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: 4238

  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: 4287

  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: 4339

  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: 4397

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

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

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

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

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

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

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

  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: 4565

   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: 5049

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

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

  Bug 13799066 : Deleted the debug messages from the function
 *==========================================================================*/
FUNCTION Overflow
         (Overflow_Exist      OUT NOCOPY VARCHAR2,
          p_start_rowid       IN  ROWID   ,  -- Bug 8913560 range_low           IN  NUMBER,
          p_end_rowid         IN  ROWID  ,   -- Bug 8913560 range_high          IN  NUMBER,
	  p_purge_name        IN  VARCHAR2,  -- Bug 8913560
          P_Calling_Sequence  IN  VARCHAR2)
RETURN BOOLEAN IS

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 -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
    PL.rowid BETWEEN p_start_rowid AND p_end_rowid;
Line: 5193

to_be_deleted_check_number      NUMBER;
Line: 5210

  OPEN overflow_select;
Line: 5214

    FETCH overflow_select into overflow_check_stock_id,
                               to_be_deleted_check_number;
Line: 5217

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

    overflow_check_number := to_be_deleted_check_number - 1;
Line: 5225

      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: 5244

          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: 5250

          Update_Financials_Purges ( p_check_rows => l_check_rows ,
	                             p_purge_name => p_purge_name ) ;
Line: 5260

            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: 5277

  CLOSE overflow_select;
Line: 5299

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: 5316

selected_checkrun               ap_invoice_selection_criteria.checkrun_name%TYPE;
Line: 5332

  OPEN setup_spoil_select;
Line: 5336

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

    FETCH setup_spoil_select into selected_checkrun;
Line: 5343

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

    debug_info := 'delete_setup_spoil';
Line: 5356

    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: 5363

    debug_info := 'delete_invoice_selection';
Line: 5368

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

  Function: Delete_AP_Tables

 *==========================================================================*/
FUNCTION Delete_AP_Tables
         (P_Calling_Sequence   IN  VARCHAR2,
          p_start_rowid        IN  ROWID   ,  -- Bug 8913560
          p_end_rowid          IN  ROWID   ,  -- Bug 8913560
	  p_purge_name         IN  VARCHAR2,  -- Bug 8913560
	  P_rows_processed     OUT NOCOPY NUMBER)    -- Bug 9481539
RETURN BOOLEAN IS

debug_info                   	VARCHAR2(200);
Line: 5415

to_be_deleted_check_number	NUMBER;
Line: 5425

    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: 5434

        SELECT PL.invoice_id
        FROM ap_purge_invoice_list PL
        WHERE PL.double_check_flag = 'Y'
        AND   -- Bug 8913560 PL.invoice_id BETWEEN low_inv_id AND high_inv_id
	      PL.rowid BETWEEN p_start_rowid AND p_end_rowid ;
Line: 5460

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

  debug_info := 'Starting Delete_AP_Tables';
Line: 5464

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

  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: 5494

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

     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: 5517

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		        PL.rowid BETWEEN p_start_rowid AND p_end_rowid
                  AND   PL.invoice_id = IP.invoice_id
                  AND   IP.check_id = C.check_id ) ;
Line: 5533

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

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

     debug_info := 'delete_checks';
Line: 5547

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

     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 -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
	       PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5566

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

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

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

     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'
        and PL.rowid BETWEEN p_start_rowid AND p_end_rowid); --9481539
Line: 5595

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid);
Line: 5613

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5629

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5645

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5661

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5678

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5695

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

     DELETE FROM ap_invoice_lines
     WHERE invoice_id IN (
	   SELECT PL.invoice_id
	   FROM ap_purge_invoice_list PL
	   WHERE PL.double_check_flag = 'Y'
	   AND   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5713

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
    		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid
                   AND   PL.invoice_id = I.invoice_id);
Line: 5738

	--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: 5750

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

     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   -- Bug 8913560 PL.invoice_id BETWEEN range_low AND range_high
		 PL.rowid BETWEEN p_start_rowid AND p_end_rowid );
Line: 5767

     Update_Financials_Purges ( p_check_rows             => l_check_rows          ,
                                p_invoice_payment_rows   => l_invoice_payment_rows,
                                p_invoice_rows           => l_invoice_rows        ,
                                p_invoice_lines_rows     => l_invoice_lines_rows  ,                --bug 11829621
                                p_invoice_distributions_rows => l_invoice_distributions_rows,      --bug 11829621
                                p_purge_name             => g_purge_name          ) ;
Line: 5797

  /* 9481539, moving this delete statement to parent process delete_seeded_data
  debug_info := 'deleting from ap_batches';
Line: 5800

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

  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: 5815

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

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

END Delete_AP_Tables;
Line: 5854

to_be_deleted_check_number	NUMBER;
Line: 5860

    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: 5877

  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: 5915

  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   /*  Bug 8913560 pil.invoice_id BETWEEN  range_low AND  range_high */
		  pil.rowid BETWEEN p_start_rowid AND p_end_rowid )
  AND             journal_sequence_id IS NULL;
Line: 5929

 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: 5941

 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: 5961

  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: 5975

  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: 5998

  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   /*  Bug 8913560 pil.invoice_id BETWEEN  range_low AND  range_high */
	      pil.rowid BETWEEN p_start_rowid AND p_end_rowid);
Line: 6010

/*  -- 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: 6022

  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: 6035

  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: 6101

    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: 6133

  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: 6159

      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: 6175

      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: 6190

      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: 6205

     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: 6242

   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: 6257

   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: 6271

   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: 6287

   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: 6302

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

    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: 6375

  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: 6398

      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: 6414

      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: 6429

      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: 6444

     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: 6479

   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: 6488

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

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

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: 6552

  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: 6589

  DELETE
    FROM ap_supplier_contacts pc
   WHERE pc.org_party_site_id IN
         ( SELECT vnd.party_site_id
             FROM ap_supplier_sites_all vnd
                , po_purge_vendor_list pvl
	   WHERE pvl.vendor_id = vnd.vendor_id
             AND pvl.double_check_flag = 'Y'
         );
Line: 6601

  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: 6616

  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: 6630

  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: 6646

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

      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: 6671

      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: 6681

      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: 6695

      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: 6740

      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: 6751

     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: 6758

     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: 6764

     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: 6789

  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: 6849

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

  debug_info := 'Starting Delete_Seeded_Data';
Line: 6855

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

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

        SELECT count(*)
        INTO   ae_line_rows
        FROM   ap_ae_lines;
Line: 6873

        SELECT count(*)
        INTO   ae_header_rows
        FROM   ap_ae_headers;
Line: 6877

        SELECT count(*)
        INTO   accounting_event_rows
        FROM   ap_accounting_events;
Line: 6889

	UPDATE financials_purges
        SET
        ap_checks                = check_rows,
        ap_invoice_payments      = invoice_payment_rows,
        ap_invoices              = invoice_rows,
        ap_ae_lines		 = ae_line_rows,
        ap_ae_headers		 = ae_header_rows,
        ap_accounting_events 	 = accounting_event_rows
        WHERE purge_name = p_purge_name;
Line: 6902

        SELECT NVL( ap_checks, 0 )           ,
	       NVL( ap_invoice_payments, 0 ) ,
               NVL( ap_invoices, 0 )         ,
               NVL( ap_ae_lines, 0 )         ,
               NVL( ap_ae_headers, 0 )       ,
               NVL( ap_accounting_events, 0 )
	INTO   check_rows,
	       invoice_payment_rows,
	       invoice_rows,
	       ae_line_rows,
	       ae_header_rows,
	       accounting_event_rows
        FROM   financials_purges
	WHERE  purge_name = p_purge_name;
Line: 6920

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

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

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

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

     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: 7012

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

   SELECT NVL( ap_checks, 0 )           ,
          NVL( ap_invoice_payments, 0 ) ,
          NVL( ap_invoices, 0 )         ,
          NVL( ap_ae_lines, 0 )         ,
          NVL( ap_ae_headers, 0 )       ,
          NVL( ap_accounting_events, 0 )
   INTO   check_rows,
          invoice_payment_rows,
          invoice_rows,
          ae_line_rows,
          ae_header_rows,
          accounting_event_rows
   FROM   financials_purges
   WHERE  purge_name = p_purge_name;
Line: 7035

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

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

   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: 7075

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

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

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

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

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

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

  	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: 7240

  DELETE FROM ap_batches B
  WHERE B.last_update_date <= g_activity_date
  AND NOT EXISTS (
          SELECT null
          FROM ap_invoices_all I --bug13799066
          WHERE I.batch_id = B.batch_id);
Line: 7249

  /*  delete from ap_purge_invoice_list; */
Line: 7258

  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: 7267

  delete from po_purge_vendor_list;
Line: 7270

  delete from chv_purge_schedule_list;
Line: 7273

  delete from chv_purge_cum_list;
Line: 7281

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

END Delete_Seeded_Data;
Line: 7307

 delete from ap_history_checks
 where purge_name = g_purge_name;
Line: 7326

  delete from chv_history_schedules
  where purge_name = g_purge_name;
Line: 7329

  delete from chv_history_cum_periods
  where purge_name = g_purge_name;
Line: 7349

  delete from chv_purge_schedule_list;
Line: 7350

  delete from chv_purge_cum_list;
Line: 7369

  delete from chv_history_schedules
  where purge_name = g_purge_name;
Line: 7390

  delete from chv_purge_schedule_list;
Line: 7410

  delete from ap_history_invoices
  where purge_name = g_purge_name;
Line: 7431

  delete from ap_purge_invoice_list;
Line: 7451

  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: 7474

  delete from po_history_vendors
  where purge_name = g_purge_name;
Line: 7495

  delete from po_purge_vendor_list;
Line: 7551

   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: 7594

     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);
Line: 7687

  Purpose   : This is called for Delete_Seeded_Data() and in turn, it spawns
              multiple child requests to delete Payables and Accounting data
 *==========================================================================*/
PROCEDURE Submit_Multiple_Requests ( p_purge_name IN         VARCHAR2 ,
                                     p_success    OUT NOCOPY BOOLEAN  ) IS  -- Bug 9268290
  l_debug_info                VARCHAR2(2000);
Line: 7717

    SELECT COUNT(0)
    INTO   l_total_recs
    FROM   ap_purge_invoice_list
    WHERE  double_check_flag = 'Y';
Line: 7839

              purge_accounting() and delete_ap_tables() for deleting records
 *==========================================================================*/
PROCEDURE Purge_acctg_and_ap_table
               (errbuf                  IN OUT NOCOPY VARCHAR2,
                retcode                 IN OUT NOCOPY VARCHAR2,
	        P_batch_size            IN            VARCHAR2,
                P_Worker_Id             IN            NUMBER,
                P_Num_Workers           IN            NUMBER,
		P_Script_Name           IN            VARCHAR2,
		P_Debug_Switch          IN            VARCHAR2 DEFAULT NULL,
		p_purge_name            IN            VARCHAR2 DEFAULT NULL)
  IS
  l_debug_info                VARCHAR2(2000);
Line: 7866

  l_mode                      VARCHAR2(30) := 'UPDATE';
Line: 7892

  ad_parallel_updates_pkg.initialize_rowid_range(
           ad_parallel_updates_pkg.ROWID_RANGE,
           l_table_owner,
           l_table_name,
           p_script_name,
           p_worker_id,
           p_num_workers,
           p_batch_size,
	   0);
Line: 7903

  ad_parallel_updates_pkg.get_rowid_range(
           l_start_rowid,
           l_end_rowid,
           l_any_rows_to_process,
           p_batch_size,
           TRUE);
Line: 7926

         if (delete_ap_tables('Purge_acctg_and_ap_table', l_start_rowid, l_end_rowid, p_script_name,l_rows_processed ) <> TRUE) then
            Print('delete_ap_tables failed!');
Line: 7933

	  Print('Invoices deleted -> '||to_char(l_rows_processed));
Line: 7936

         ad_parallel_updates_pkg.processed_rowid_range( l_rows_processed,
						        l_end_rowid);
Line: 7943

         ad_parallel_updates_pkg.get_rowid_range(l_start_rowid,
	 				         l_end_rowid,
					         l_any_rows_to_process,
					         p_batch_size,
					         FALSE);
Line: 7955

   Print('Total invoices deleted in this worker -> '||to_char(l_final_count));
Line: 7968

  Procedure : Update_Financials_Purges
  Purpose   : Updates the financilas_purges table during the delete process of
              accounting and ap tables that is done using multiple child requests
 *==========================================================================*/
Procedure Update_Financials_Purges ( p_check_rows             IN NUMBER DEFAULT 0,
                                     p_invoice_payment_rows   IN NUMBER DEFAULT 0,
                                     p_invoice_rows           IN NUMBER DEFAULT 0,
                                     p_ae_line_rows	      IN NUMBER DEFAULT 0,
                                     p_ae_header_rows	      IN NUMBER DEFAULT 0,
                                     p_accounting_event_rows  IN NUMBER DEFAULT 0,
                                     p_invoice_lines_rows     IN NUMBER DEFAULT 0, --bug 11829621
                                     p_invoice_distributions_rows IN NUMBER DEFAULT 0, --bug 11829621
				     p_purge_name             IN VARCHAR2         )
IS
    PRAGMA AUTONOMOUS_TRANSACTION ;
Line: 7984

    UPDATE financials_purges
    SET    ap_checks             = NVL(ap_checks           , 0 ) + p_check_rows,
           ap_invoice_payments   = NVL(ap_invoice_payments , 0 ) + p_invoice_payment_rows,
           ap_invoices           = NVL(ap_invoices         , 0 ) + p_invoice_rows,
           ap_invoice_lines      = NVL(ap_invoice_lines    , 0 ) + p_invoice_lines_rows,                        --bug 11829621
           ap_invoice_distributions = NVL(ap_invoice_distributions , 0 ) + p_invoice_distributions_rows,        --bug 11829621
           ap_ae_lines		 = NVL(ap_ae_lines         , 0 ) + p_ae_line_rows,
           ap_ae_headers	 = NVL(ap_ae_headers       , 0 ) + p_ae_header_rows,
           ap_accounting_events  = NVL(ap_accounting_events, 0 ) + p_accounting_event_rows
    WHERE  purge_name            = p_purge_name;