Sie sind auf Seite 1von 13

REM $Header: ap_sync_po_qty_amt_sel.sql 120.0.12010000.

14 2013/10/07 06:31:02
nbshaik noship $
REM +=======================================================================+
REM | Copyright (c) 2001, 2013 Oracle Corporation, Redwood Shores, CA, USA |
REM | All rights reserved. |
REM +=======================================================================+
REM | FILENAME |
REM | ap_sync_po_qty_amt_sel.sql |
REM | |
REM | DESCRIPTION |
REM | This script will identify all PO distributions that have a mis- |
REM | match with AP distributions for quantity/amount billed, quantity |
REM | /amount financed and quatity/amount recouped. |
REM | HISTORY |
REM | 29-OCT-2009 ASANSARI Created |
REM | 09-MAR-2011 ASANSARI Modified 11777613 |
REM +=======================================================================+
REM dbdrv: none
SET VERIFY OFF
SET SERVEROUTPUT ON
WHENEVER SQLERROR EXIT FAILURE ROLLBACK;
WHENEVER OSERROR EXIT FAILURE ROLLBACK;

--bug 17399534
PROMPT 1. Email ID is an optional parameter which should be provided
PROMPT if, user wants to recieve generated log on their email id.

DECLARE
l_file_location v$parameter.value%TYPE;
l_message VARCHAR2( 1000 );
l_count NUMBER;
l_instance_dets VARCHAR2(4000);
--bug 17399534
l_email_id VARCHAR2(255) := '&Email_id';
l_email_flag BOOLEAN DEFAULT FALSE;
/* Bug 17558081 */
l_instance_name VARCHAR2(100);
l_host_name VARCHAR2(100);

BEGIN
AP_Acctg_Data_Fix_PKG.Open_Log_Out_Files( 9049862||'-diag', l_file_location );
AP_Acctg_Data_Fix_PKG.Print( '<html><body>' );
l_message := 'Start of ap_sync_po_qty_amt_sel<p>';
AP_Acctg_Data_Fix_PKG.Print( l_message );

-- Printing instance details

l_message := 'Printing instance details';


AP_Acctg_Data_Fix_PKG.Print(l_message);

/* Bug 17558081 begin -exception -end block handling while printing instance
details removed */

SELECT instance_name, host_name


INTO l_instance_name, l_host_name
FROM v$instance;
AP_Acctg_Data_Fix_PKG.Print('Fix script executed on instance '||
l_instance_name||' host_name '||l_host_name||' on '||
to_char(sysdate,'DD-MON-YYYY HH:MI:SS'));

AP_Acctg_Data_Fix_PKG.Print
('++++ ============================================================ +++
+');
AP_Acctg_Data_Fix_PKG.Print(l_instance_dets);

AP_Acctg_Data_Fix_PKG.Print
('++++ ============================================================ +++
+');
--bug 17399534
l_message := 'Email ID provided: '|| l_email_id;
AP_Acctg_Data_Fix_PKG.Print(l_message);

--Dropping driver table if already exists

AP_Acctg_Data_Fix_PKG.Print( 'Dropping driver table - AP_PO_MISMATCH_9049862 if


it already exists<p>' );
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE AP_PO_MISMATCH_9049862';
EXCEPTION
WHEN OTHERS THEN
l_message := 'could not delete AP_PO_MISMATCH_9049862 '||sqlerrm ;
END;
l_message := 'Creating driver table - AP_PO_MISMATCH_9049862 <p>';
AP_Acctg_Data_Fix_PKG.Print( l_message );
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE AP_PO_MISMATCH_9049862(
PO_HEADER_ID NUMBER,
PO_LINE_ID NUMBER,
LINE_LOCATION_ID NUMBER,
PO_RELEASE_ID NUMBER,
PO_DISTRIBUTION_ID NUMBER,
UPD_QUANTITY NUMBER,
UPD_AMOUNT NUMBER,
ORI_QUANTITY NUMBER,
ORI_AMOUNT NUMBER,
MATCH_TYPE NUMBER,
UOM_CODES VARCHAR2(200), /*Bug9756279*/
PROCESS_FLAG VARCHAR2(1) default ''N'')';

l_message := 'Driver table - AP_PO_MISMATCH_9049862 created successfully<p>';


AP_Acctg_Data_Fix_PKG.Print( l_message );
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'could not create AP_PO_MISMATCH_9049862 '||sqlerrm );
END;

/* Added approved_flag,cancel_flag,closed_code conditions


on PO shipments data in all types of corruptions to
include encumbrance related data also. Bug#10277949 */

BEGIN
/********* TYPE 1 **********/
/********* PO MATCHED TO PREPAYMENT INVOICE - QUANTITY_FINANCED and
AMOUNT_FINANCED **********/
/*Bug9756279*/
l_message := 'Insert for Type 1';
EXECUTE Immediate
'Insert into AP_PO_MISMATCH_9049862(
PO_HEADER_ID,
PO_LINE_ID,
LINE_LOCATION_ID,
PO_RELEASE_ID,
PO_DISTRIBUTION_ID,
UPD_QUANTITY,
UPD_AMOUNT,
ORI_QUANTITY,
ORI_AMOUNT,
MATCH_TYPE,
UOM_CODES,
PROCESS_FLAG )
(SELECT apd.po_header_id,
apd.po_line_id,
apd.line_location_id,
apd.po_release_id,
apd.po_distribution_id,
SUM(NVL(apd.AID_QUAN,0)),
SUM(NVL(apd.AID_AMT,0)),
NVL(apd.PO_QUANTITY,0),
NVL(apd.PO_AMOUNT,0),
1 MATCH_TYPE,
apd.UOM_CODES,
apd.PROCESS_FLAG
FROM (SELECT pod.po_header_id po_header_id,
pod.po_line_id po_line_id,
pod.line_location_id line_location_id,
pod.po_release_id po_release_id,
pod.po_distribution_id po_distribution_id,
/*Bug11777613*/
DECODE( aid.dist_match_type,''PRICE_CORRECTION'', 0,
''AMOUNT_CORRECTION'', 0,''ITEM_TO_SERVICE_PO'', 0,
''ITEM_TO_SERVICE_RECEIPT'', 0,
NVL( aid.corrected_quantity,0 ) +NVL( aid.quantity_invoiced,0 ))
* DECODE(NVL(aid.matched_uom_lookup_code,pll.unit_meas_lookup_code),
pll.unit_meas_lookup_code, 1 , NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(
NVL(aid.matched_uom_lookup_code, pll.unit_meas_lookup_code),
pll.unit_meas_lookup_code,RSL.item_id),0)) AID_QUAN,
aid.amount AID_AMT,
pod.quantity_financed PO_QUANTITY,
pod.amount_financed PO_AMOUNT,
/*Bug9756279*/

DECODE(NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(nvl(aid.matched_uom_lookup_code,
pll.unit_meas_lookup_code),pll.unit_meas_lookup_code, RSL.item_id),-
999),-999,
aid.matched_uom_lookup_code||'' and ''||
pll.unit_meas_lookup_code,''None'') UOM_CODES,

DECODE(NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(nvl(aid.matched_uom_lookup_code,
pll.unit_meas_lookup_code),pll.unit_meas_lookup_code, RSL.item_id),-
999),-999,''E'',''N'') process_flag /*17399534*/
/*End of Bug9756279*/
FROM po_distributions_all pod,
ap_invoice_distributions_all aid,
po_lines_all pol,
po_line_locations_all pll,
ap_invoices_all ai,
financials_system_params_all fsp,
rcv_transactions rtxn,
rcv_shipment_lines RSL
WHERE pod.po_distribution_id = aid.po_distribution_id
AND pod.line_location_id = pll.line_location_id
AND pll.po_line_id = pol.po_line_id
AND aid.invoice_id = ai.invoice_id
AND ai.org_id = fsp.org_id
AND ( NVL(fsp.purch_encumbrance_flag,''N'') = ''N'' or
(NVL(pll.approved_flag,''N'')=''Y'' and
NVL(pll.cancel_flag,''N'')=''N'' and
NVL(pll.closed_code,'' '')<>''FINALLY CLOSED'')
)
AND aid.line_type_lookup_code IN (''ITEM'', ''ACCRUAL'',
''IPV'',''RETROACCRUAL'',''RETROEXPENSE'')
AND ai.invoice_type_lookup_code = ''PREPAYMENT''
AND aid.rcv_transaction_id = RTXN.transaction_id (+)
AND RTXN.shipment_line_id = RSL.shipment_line_id (+) ) apd
GROUP BY apd.po_header_id,
apd.po_line_id,
apd.line_location_id,
apd.po_release_id,
apd.po_distribution_id,
apd.PO_QUANTITY,
apd.PO_AMOUNT,
apd.UOM_CODES,
apd.PROCESS_FLAG
HAVING (Round(Nvl(apd.PO_QUANTITY,0),15) <>
Round(Sum(nvl(apd.AID_QUAN,0)),15))
OR (Round(Nvl(apd.PO_AMOUNT,0),15) <>
Round(Sum(nvl(apd.AID_AMT,0)),15)))';

/********* TYPE 2 **********/


/********* PO MATCHED TO PREPAYMENT APPLICATIONS - QUANTITY_RECOUPED and
AMOUNT_RECOUPED **********/
l_message := 'Insert for Type 2';
EXECUTE Immediate
'Insert into AP_PO_MISMATCH_9049862(
PO_HEADER_ID,
PO_LINE_ID,
LINE_LOCATION_ID,
PO_RELEASE_ID,
PO_DISTRIBUTION_ID,
UPD_QUANTITY,
UPD_AMOUNT,
ORI_QUANTITY,
ORI_AMOUNT,
MATCH_TYPE,
UOM_CODES,
PROCESS_FLAG )
(SELECT apd.po_header_id,
apd.po_line_id,
apd.line_location_id,
apd.po_release_id,
apd.po_distribution_id,
SUM(NVL(apd.AID_QUAN,0)),
SUM(NVL(apd.AID_AMT,0)),
NVL(apd.PO_QUANTITY,0),
NVL(apd.PO_AMOUNT,0),
2 MATCH_TYPE,
apd.UOM_CODES,
apd.PROCESS_FLAG
FROM (SELECT pod.po_header_id po_header_id,
pod.po_line_id po_line_id,
pod.line_location_id line_location_id,
pod.po_release_id po_release_id,
pod.po_distribution_id po_distribution_id,
/*Bug11777613*/
- DECODE( aid.dist_match_type,''PRICE_CORRECTION'', 0,
''AMOUNT_CORRECTION'', 0,''ITEM_TO_SERVICE_PO'', 0,
''ITEM_TO_SERVICE_RECEIPT'', 0,
NVL( aid.corrected_quantity,0 ) +NVL( aid.quantity_invoiced,0 ))
* DECODE(NVL(aid.matched_uom_lookup_code,pll.unit_meas_lookup_code),
pll.unit_meas_lookup_code, 1 , NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(
NVL(aid.matched_uom_lookup_code, pll.unit_meas_lookup_code),
pll.unit_meas_lookup_code,RSL.item_id),0)) AID_QUAN,
-aid.amount AID_AMT,
pod.quantity_recouped PO_QUANTITY,
pod.amount_recouped PO_AMOUNT,
/*End of Bug9756279*/

DECODE(NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(nvl(aid.matched_uom_lookup_code,
pll.unit_meas_lookup_code),pll.unit_meas_lookup_code, RSL.item_id),-
999),-999,
aid.matched_uom_lookup_code||'' and ''||
pll.unit_meas_lookup_code,''None'') UOM_CODES,

DECODE(NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(nvl(aid.matched_uom_lookup_code,
pll.unit_meas_lookup_code),pll.unit_meas_lookup_code, RSL.item_id),-
999),-999,''E'',''N'') process_flag /*17399534*/
/*Bug9756279*/
FROM po_distributions_all pod,
ap_invoice_distributions_all aid,
po_lines_all pol,
po_line_locations_all pll,
ap_invoices_all ai,
financials_system_params_all fsp,
rcv_transactions rtxn,
rcv_shipment_lines RSL
WHERE pod.po_distribution_id = aid.po_distribution_id
AND pod.line_location_id = pll.line_location_id
AND pll.po_line_id = pol.po_line_id
AND aid.invoice_id = ai.invoice_id
AND ai.org_id = fsp.org_id
AND ( NVL(fsp.purch_encumbrance_flag,''N'') = ''N'' or
(NVL(pll.approved_flag,''N'')=''Y'' and
NVL(pll.cancel_flag,''N'')=''N'' and
NVL(pll.closed_code,'' '')<>''FINALLY CLOSED'')
)
AND aid.line_type_lookup_code = ''PREPAY''
AND ai.invoice_type_lookup_code <> ''PREPAYMENT''
AND aid.rcv_transaction_id = RTXN.transaction_id (+)
AND RTXN.shipment_line_id = RSL.shipment_line_id (+) ) apd
GROUP BY apd.po_header_id,
apd.po_line_id,
apd.line_location_id,
apd.po_release_id,
apd.po_distribution_id,
apd.PO_QUANTITY,
apd.PO_AMOUNT,
apd.UOM_CODES,
apd.PROCESS_FLAG
HAVING (Round(Nvl(apd.PO_QUANTITY,0),15) <> -
Round(Sum(nvl(apd.AID_QUAN,0)),15))
OR (Round(Nvl(apd.PO_AMOUNT,0),15) <>
-Round(Sum(nvl(apd.AID_AMT,0)),15)))';

/********* TYPE 3 **********/


/********* PO MATCHED TO NON-PREPAY INVOICES - QUANTITY_BILLED and
AMOUNT_BILLED **********/
l_message := 'Insert for Type 3';
EXECUTE Immediate
'Insert into AP_PO_MISMATCH_9049862(
PO_HEADER_ID,
PO_LINE_ID,
LINE_LOCATION_ID,
PO_RELEASE_ID,
PO_DISTRIBUTION_ID,
UPD_QUANTITY,
UPD_AMOUNT,
ORI_QUANTITY,
ORI_AMOUNT,
MATCH_TYPE,
UOM_CODES,
PROCESS_FLAG )
(SELECT apd.po_header_id,
apd.po_line_id,
apd.line_location_id,
apd.po_release_id,
apd.po_distribution_id,
SUM(NVL(apd.AID_QUAN,0)),
SUM(NVL(apd.AID_AMT,0)),
NVL(apd.PO_QUANTITY,0),
NVL(apd.PO_AMOUNT,0),
3 MATCH_TYPE,
apd.UOM_CODES,
apd.PROCESS_FLAG
FROM (SELECT pod.po_header_id po_header_id,
pod.po_line_id po_line_id,
pod.line_location_id line_location_id,
pod.po_release_id po_release_id,
pod.po_distribution_id po_distribution_id,
/*Bug11777613*/
DECODE( aid.dist_match_type,''PRICE_CORRECTION'', 0,
''AMOUNT_CORRECTION'', 0,''ITEM_TO_SERVICE_PO'', 0,
''ITEM_TO_SERVICE_RECEIPT'', 0,
NVL( aid.corrected_quantity,0 ) +NVL( aid.quantity_invoiced,0 ))
* DECODE(NVL(aid.matched_uom_lookup_code,pll.unit_meas_lookup_code),
pll.unit_meas_lookup_code, 1 , NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(
NVL(aid.matched_uom_lookup_code, pll.unit_meas_lookup_code),
pll.unit_meas_lookup_code,RSL.item_id),0)) AID_QUAN,
aid.amount AID_AMT,
pod.quantity_billed PO_QUANTITY,
pod.amount_billed PO_AMOUNT,
/*Bug9756279*/
DECODE(NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(nvl(aid.matched_uom_lookup_code,
pll.unit_meas_lookup_code),pll.unit_meas_lookup_code, RSL.item_id),-
999),-999,
aid.matched_uom_lookup_code||'' and ''||
pll.unit_meas_lookup_code,''None'') UOM_CODES,

DECODE(NVL(AP_Acctg_Data_Fix_PKG.UOM_CONVERT(nvl(aid.matched_uom_lookup_code,
pll.unit_meas_lookup_code),pll.unit_meas_lookup_code, RSL.item_id),-
999),-999,''E'',''N'') process_flag /*17399534*/
/*End of Bug9756279*/
FROM po_distributions_all pod,
ap_invoice_distributions_all aid,
po_lines_all pol,
po_line_locations_all pll,
ap_invoices_all ai,
financials_system_params_all fsp,
rcv_transactions rtxn,
rcv_shipment_lines RSL
WHERE pod.po_distribution_id = aid.po_distribution_id
AND pod.line_location_id = pll.line_location_id
AND pll.po_line_id = pol.po_line_id
AND aid.invoice_id = ai.invoice_id
AND ai.org_id = fsp.org_id
AND ( NVL(fsp.purch_encumbrance_flag,''N'') = ''N'' or
(NVL(pll.approved_flag,''N'')=''Y'' and
NVL(pll.cancel_flag,''N'')=''N'' and
NVL(pll.closed_code,'' '')<>''FINALLY CLOSED'')
)
AND aid.line_type_lookup_code IN (''ITEM'', ''ACCRUAL'',
''IPV'',''RETROACCRUAL'',''RETROEXPENSE'')
AND ai.invoice_type_lookup_code <> ''PREPAYMENT''
AND aid.rcv_transaction_id = RTXN.transaction_id (+)
AND RTXN.shipment_line_id = RSL.shipment_line_id (+) ) apd
GROUP BY apd.po_header_id,
apd.po_line_id,
apd.line_location_id,
apd.po_release_id,
apd.po_distribution_id,
apd.PO_QUANTITY,
apd.PO_AMOUNT,
apd.UOM_CODES,
apd.PROCESS_FLAG
HAVING (Round(Nvl(apd.PO_QUANTITY,0),15) <>
Round(Sum(nvl(apd.AID_QUAN,0)),15))
OR (Round(Nvl(apd.PO_AMOUNT,0),15) <>
Round(Sum(nvl(apd.AID_AMT,0)),15)))';
/*End of Bug9756279*/
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception in inserting records into
AP_PO_MISMATCH_9049862 '||SQLERRM );
END;
/********* DELETE TRASACTIONS THAT WILL UPDATE THE COLUMNS NEGATIVE **********/
/********* DELETE TRASACTIONS THAT HAVE EQUAL UPDATE and ORIGINAL COLUMNS
**********/
BEGIN
EXECUTE Immediate
'DELETE FROM AP_PO_MISMATCH_9049862
WHERE ( upd_quantity = ori_quantity
AND upd_amount = ori_amount)
OR ( upd_quantity < 0
OR upd_amount < 0 )
AND process_flag = ''N'''; /* bug 17399534*/
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception while deleting records from
AP_PO_MISMATCH_9049862 '||SQLERRM );
END;
/*Bug9756279*/
/********* CHECK DRIVER TABLE FOR MISSING UOM CONVERSIONS **********/
-- Printing all errored po_distributions
BEGIN
EXECUTE Immediate 'SELECT count(*) FROM AP_PO_MISMATCH_9049862 WHERE
PROCESS_FLAG = ''E'' '
INTO l_count;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception in selecting count from
AP_PO_MISMATCH_9049862 '||SQLERRM );
END;
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );
IF( l_count > 0 ) THEN
AP_Acctg_Data_Fix_PKG.Print( 'Following are the PO Line Locations that dont
have UOM '||
'conversion rates defined for the UOM codes listed under the column
UOM_CODES' );
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );
BEGIN
AP_Acctg_Data_Fix_PKG.Print_html_table(
'PO_HEADER_ID,PO_LINE_ID,LINE_LOCATION_ID,PO_RELEASE_ID,PO_DISTRIBUTION_ID,UO
M_CODES',
'AP_PO_MISMATCH_9049862',
'WHERE PROCESS_FLAG = ''E'' ORDER BY PO_HEADER_ID',
'ap_sync_po_qty_amt_sel' );
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Error while printing table 1- AP_PO_MISMATCH_9049862
'||SQLCODE||'-'||SQLERRM );
END;

l_message := '_______________________________________'||
'_______________________________________';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := 'Following are the next steps to be followed '||


'to fix the issue';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '1. Define UOM conversion rates between the codes listed under the
column UOM_CODES';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '2. After setting the conversion rates, re-run the select script
'||
'ap_sync_po_qty_amt_sel.sql which is present in
$AP_TOP/patch/115/sql.';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '3. Re-running the select script will ensure sanity check for the
'||
' AP and PO data that did not have UOM rates in the previous run.';
AP_Acctg_Data_Fix_PKG.Print( l_message );

--Setting all po distributions to E if even one of them did not have conversion
rate
--These will be selected when user defines the rates and re-runs the selection
script.
BEGIN
EXECUTE Immediate
'UPDATE AP_PO_MISMATCH_9049862 a
SET a.process_flag = ''E''
WHERE a.po_distribution_id in ( select po_distribution_id
FROM AP_PO_MISMATCH_9049862 b
WHERE b.po_distribution_id = a.po_distribution_id
AND b.process_flag = ''E'')';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception while updating process_flag from
AP_PO_MISMATCH_9049862 '||SQLERRM );
END;
END IF;
/*End of Bug9756279*/
--Bug9798015
/********* CHECK RCV_TRASACTIONS DATA FOR MISMATCHING PO DISTRIBUTIONS
**********/
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );

AP_Acctg_Data_Fix_PKG.Print( 'Dropping driver table - AP_RCV_MISMATCH_9049862 if it


already exists<p>' );
BEGIN
EXECUTE IMMEDIATE 'DROP TABLE AP_RCV_MISMATCH_9049862';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'could not delete AP_RCV_MISMATCH_9049862 '||sqlerrm );
END;

l_message := 'Creating driver table 2 - AP_RCV_MISMATCH_9049862 <p>';


AP_Acctg_Data_Fix_PKG.Print( l_message );

BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE AP_RCV_MISMATCH_9049862 AS
SELECT aid.rcv_transaction_id,
SUM(nvl(aid.amount,0)) UPD_AMOUNT,
SUM(nvl(aid.quantity_invoiced,0)) UPD_QUANTITY,
nvl(rcv.amount_billed,0) RCV_AMOUNT,
nvl(rcv.quantity_billed,0) RCV_QUANTITY,
''N'' process_flag /*bug 17399534*/
FROM ap_invoice_distributions_all aid,
rcv_transactions rcv
WHERE rcv.transaction_id = aid.rcv_transaction_id
AND aid.rcv_transaction_id IS NOT NULL
AND aid.line_type_lookup_code IN (''ITEM'',''ACCRUAL'',''IPV'',''PREPAY'')
GROUP BY nvl(rcv.quantity_billed,0),
nvl(rcv.amount_billed,0),
aid.rcv_transaction_id
HAVING (SUM(nvl(aid.quantity_invoiced,0)) <> nvl(rcv.quantity_billed,0))
OR (SUM(nvl(aid.amount,0)) <> nvl(rcv.amount_billed,0))';

l_message := 'Driver table - AP_RCV_MISMATCH_9049862 created successfully<p>';


AP_Acctg_Data_Fix_PKG.Print( l_message );

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'could not create AP_RCV_MISMATCH_9049862 '||sqlerrm );
END;

/********* DELETE TRASACTIONS THAT WILL UPDATE THE COLUMNS NEGATIVE **********/
/********* DELETE TRASACTIONS THAT HAVE EQUAL UPDATE and ORIGINAL COLUMNS
**********/
BEGIN
EXECUTE Immediate
'DELETE FROM AP_RCV_MISMATCH_9049862
WHERE ( upd_quantity = rcv_quantity
AND upd_amount = rcv_amount)
OR ( upd_quantity < 0
OR upd_amount < 0 )';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception while deleting records from
AP_RCV_MISMATCH_9049862 '||SQLERRM );
END;
--End of Bug9798015

/********* PRINT DATA IN AP_PO_MISMATCH_9049862 **********/


BEGIN
EXECUTE Immediate 'SELECT count(*) FROM AP_PO_MISMATCH_9049862 '
INTO l_count;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception in selecting count from
AP_PO_MISMATCH_9049862 '||SQLERRM );
END;

AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );

IF( l_count > 0 ) THEN


AP_Acctg_Data_Fix_PKG.Print( 'Following are the PO distributions and Line
Locations which '||
'needs to be synced with Invoice distributions as part of
fix. ' ||
'By default the process_flag is N.Update the process flag to Y for
transactions'||
' which user wants to fix');
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||

'_______________________________________' );
BEGIN
AP_Acctg_Data_Fix_PKG.Print_html_table(
'PO_HEADER_ID,PO_LINE_ID,LINE_LOCATION_ID,PO_RELEASE_ID,PO_DISTRIBUTION
_ID,'||
'UPD_QUANTITY,UPD_AMOUNT,ORI_QUANTITY,ORI_AMOUNT',
'AP_PO_MISMATCH_9049862',
'WHERE PROCESS_FLAG = ''N'' ORDER BY PO_HEADER_ID',
'ap_sync_po_qty_amt_sel' );
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Error while printing table -
AP_PO_MISMATCH_9049862 '||SQLCODE||'-'||SQLERRM );
END;

l_message := '_______________________________________'||
'_______________________________________';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := 'Following are the next steps to be followed '||


'to fix the issue, if any';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '1. If you want any PO distribution to be fixed then'||


' update process_flag in table <p>'||
' AP_PO_MISMATCH_9049862 to Y for those distributions. <p>';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '2. To fix the identified transactions run '||


'ap_sync_po_qty_amt_fix.sql which is present in
$AP_TOP/patch/115/sql.';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '3. If data is not corrected contact Oracle Support and supply
files'||
' 9049862-diag-DD_MI_SS.html and 9049862-fix-DD_MI_SS.html.';
AP_Acctg_Data_Fix_PKG.Print( l_message );

AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );

ELSE
AP_Acctg_Data_Fix_PKG.Print( 'There is no mismatch in data betweem AP and PO
tables.' );
AP_Acctg_Data_Fix_PKG.Print( 'This script does not identify transactions for
which encumbrance is enabled.' );
AP_Acctg_Data_Fix_PKG.Print( 'If encumbrance is enabled for your org, please
contact Oracle Support for assistance.' );
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );
END IF;
--Bug9798015
/********* PRINT DATA IN AP_RCV_MISMATCH_9049862 **********/
BEGIN
EXECUTE Immediate 'SELECT count(*) FROM AP_RCV_MISMATCH_9049862 ' INTO
l_count;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Exception in selecting count from
AP_RCV_MISMATCH_9049862 '||SQLERRM );
END;
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );
IF( l_count > 0 ) THEN
AP_Acctg_Data_Fix_PKG.Print( 'Following are the RCV transactions which needs
to be '||
'synced with Invoice distributions as part of fix. ' ||
'By default the process_flag is N.Update the process flag
to Y for transactions'||
' which user wants to fix');
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );
BEGIN
AP_Acctg_Data_Fix_PKG.Print_html_table(
'RCV_TRANSACTION_ID,'||
'UPD_QUANTITY,UPD_AMOUNT,RCV_QUANTITY,RCV_AMOUNT',
'AP_RCV_MISMATCH_9049862',
'ORDER BY RCV_TRANSACTION_ID ',
'ap_sync_po_qty_amt_sel' );
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( 'Error while printing table - AP_RCV_MISMATCH_9049862
'||SQLCODE
||'-'||SQLERRM );
END;

l_message := '_______________________________________'||
'_______________________________________';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := 'Following are the next steps to be followed '||


'to fix the issue, if any';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '1. If you want any RCV Transaction to be fixed then'||


' update process_flag in table <p>'||
' AP_RCV_MISMATCH_9049862 to Y for those transactions. <p>';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '2. To fix the identified transactions run '||


'ap_sync_po_qty_amt_fix.sql which is present in
$AP_TOP/patch/115/sql.';
AP_Acctg_Data_Fix_PKG.Print( l_message );

l_message := '3. If data is not corrected contact Oracle Support and supply
files'||
' 9049862-diag-DD_MI_SS.html and 9049862-fix-DD_MI_SS.html.';
AP_Acctg_Data_Fix_PKG.Print( l_message );
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );

ELSE
AP_Acctg_Data_Fix_PKG.Print( 'There is no mismatch in data betweem AP and RCV
tables.' );
AP_Acctg_Data_Fix_PKG.Print( '_______________________________________'||
'_______________________________________' );
END IF;
--End of Bug9798015
AP_Acctg_Data_Fix_PKG.Print( '</body></html>' );
AP_Acctg_Data_Fix_PKG.Close_Log_Out_Files;

--bug 17399534
IF (l_email_id IS NOT NULL) THEN
l_email_flag :=
AP_Acctg_Data_Fix_PKG.send_mail_clob_impl(l_email_id,l_file_location);
END IF;
IF (l_email_flag) THEN
dbms_output.put_line ('Sent Email with log file: '||l_file_location);
ELSE
dbms_output.put_line ('Email Sending Failed with log file :'||
l_file_location);
END IF;

dbms_output.put_line( '--------------------------------------------------'||
'-----------------------------' );
dbms_output.put_line( l_file_location||' is the log file created' );
dbms_output.put_line( '--------------------------------------------------'||
'-----------------------------' );
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( l_message||sqlerrm );
l_message := 'after '||l_message||'';
AP_Acctg_Data_Fix_PKG.Print( l_message );
l_message := 'Exception :: '||SQLERRM||'';
AP_Acctg_Data_Fix_PKG.Print( l_message );
--bug 17558081
IF (l_email_id IS NOT NULL) THEN
l_email_flag :=
AP_Acctg_Data_Fix_PKG.send_mail_clob_impl(l_email_id,l_file_location);
END IF;
IF (l_email_flag) THEN
dbms_output.put_line ('Email Sent');
ELSE
dbms_output.put_line ('Email Sending Failed');
END IF;
APP_EXCEPTION.RAISE_EXCEPTION;
END;
/
COMMIT;
EXIT;

Das könnte Ihnen auch gefallen