SQL Statements which compliment the following note:
Note 1279848.1 - R12: Discrepancies With Period End Accruals - Troubleshooting
1. SQL -1 SELECT SUM( quantity) AS a, po_line_location_id FROM (SELECT DECODE(transaction_type, 'RECEIVE',quantity, 'RETURN TO VENDOR', -1*qu antity ) AS quantity, po_header_id, po_line_location_id, transaction_date FROM rcv_transactions rt1 WHERE rt1.transaction_type IN ('RECEIVE', 'RETURN TO VENDOR') UNION SELECT quantity, po_header_id, po_line_location_id , transaction_date FROM rcv_transactions rt2 WHERE rt2.transaction_type = 'CORRECT' AND rt2.parent_transaction_id IN (SELECT transaction_id FROM rcv_transactions WHERE transaction_type = 'RECEIVE' ) UNION SELECT -1*quantity AS quantity, po_header_id, po_line_location_id , transaction_date FROM rcv_transactions rt3 WHERE rt3.transaction_type = 'CORRECT' AND parent_transaction_id IN (SELECT transaction_id FROM rcv_transactions WHERE transaction_type = 'RETURN TO RECEIVE' ) ) X, gl_period_statuses gp WHERE X.transaction_date <= gp.end_date AND gp.period_name = '&period_name' AND gp.set_of_books_id = &set_of_Books_id AND gp.application_id = 201 AND X.po_header_id = &po_header_id GROUP BY po_line_location_id; 2. SQL -2 SELECT SUM( quantity) , po_line_location_id FROM (SELECT DECODE(transaction_type, 'RECEIVE',quantity, 'RETURN TO VENDOR', -1*qu antity ) AS quantity, po_header_id, po_line_location_id, transaction_date FROM rcv_transactions rt1 WHERE rt1.transaction_type IN ('RECEIVE', 'RETURN TO VENDOR') UNION SELECT quantity, po_header_id, po_line_location_id , transaction_date FROM rcv_transactions rt2 WHERE rt2.transaction_type = 'CORRECT' AND rt2.parent_transaction_id IN (SELECT transaction_id FROM rcv_transactions WHERE transaction_type = 'RECEIVE' ) UNION SELECT -1*quantity AS quantity, po_header_id, po_line_location_id , transaction_date FROM rcv_transactions rt3 WHERE rt3.transaction_type = 'CORRECT' AND parent_transaction_id IN (SELECT transaction_id FROM rcv_transactions WHERE transaction_type = 'RETURN TO RECEIVE' ) ) X, gl_period_statuses gp WHERE X.transaction_date <= gp.end_date AND gp.period_name = '&period_name' AND gp.set_of_books_id = &set_of_Books_id AND gp.application_id = 200 AND X.po_line_location_id IN (SELECT line_location_id FROM po_line_locations_all pll, po_releases_all por WHERE pll.po_release_id = por.po_release_id AND por.release_num = '&blanket_release_number' AND pll.po_header_id = &po_header_id ) GROUP BY po_line_location_id; 3. SQL -3 SELECT SUM(NVL(quantity_invoiced,0)) AS b, ap.po_distribution_id FROM ap_invoice_distributions_all ap, gl_period_statuses gp WHERE po_distribution_id IN (SELECT po_distribution_id FROM po_distributions_all WHERE po_header_id = &po_header_id ) AND ap.accounting_date <= gp.end_date AND gp.period_name = '&Period_name' AND gp.set_of_books_id = &set_of_Books_id AND gp.application_id = 201 AND NVL(cancellation_flag,'N') <> 'N' AND NVL(reversal_flag, 'N') <> 'N' GROUP BY ap.po_distribution_id 4. SQL -4 SELECT pll.closed_code, pll.closed_date, pll.accrue_on_receipt_flag FROM po_line_locations_all pll, gl_period_statuses gp WHERE pll.closed_date IS NOT NULL AND closed_code NOT IN ( 'CLOSED', 'FINALLY CLOSED') AND pll.closed_date > gp.end_date AND gp.period_name = '&Period_name' AND gp.set_of_books_id = &set_of_Books_id AND gp.application_id = 201 AND po_header_id = &po_header_id 5. SQL -5 Enter the 'run_date' Ex. 01-01-2014 as the date on which the period end program was submitted. SELECT SUM( quantity) AS a, po_line_location_id FROM (SELECT DECODE(transaction_type, 'RECEIVE',quantity, 'RETURN TO VENDOR', -1*qu antity ) AS quantity, po_header_id, po_line_location_id, transaction_date, creation_date FROM rcv_transactions rt1 WHERE rt1.transaction_type IN ('RECEIVE', 'RETURN TO VENDOR') UNION SELECT quantity, po_header_id, po_line_location_id , transaction_date, creation_date FROM rcv_transactions rt2 WHERE rt2.transaction_type = 'CORRECT' AND rt2.parent_transaction_id IN (SELECT transaction_id FROM rcv_transactions WHERE transaction_type = 'RECEIVE' ) UNION SELECT -1*quantity AS quantity, po_header_id, po_line_location_id , transaction_date, creation_date FROM rcv_transactions rt3 WHERE rt3.transaction_type = 'CORRECT' AND parent_transaction_id IN (SELECT transaction_id FROM rcv_transactions WHERE transaction_type = 'RETURN TO RECEIVE' ) ) X, gl_period_statuses gp WHERE X.transaction_date <= gp.end_date AND to_date(X.creation_date) > to_date(&run_date) AND gp.period_name = '&period_name' AND gp.set_of_books_id= &set_of_Books_id AND gp.application_id = 201 AND X.po_header_id = &po_header_id GROUP BY po_line_location_id; 6. SQL -6 - Run Date should be in format - 01-01-2014 SELECT SUM(NVL(quantity_invoiced,0)) AS b, ap.po_distribution_id FROM ap_invoice_distributions_all ap, gl_period_statuses gp WHERE po_distribution_id IN (SELECT po_distribution_id FROM po_distributions_all WHERE po_header_id = &po_header_id ) AND ap.accounting_date <= gp.end_date AND ap.creation_date > gp.end_date AND to_date(ap.creation_date ) > to_date(&run_date) AND gp.period_name = '&Period_name' AND gp.set_of_books_id= &set_of_Books_id AND gp.application_id = 201 GROUP BY ap.po_distribution_id; 7. SQL -7 SELECT rsl.reference3 PO_distribution_id , rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, rsl.period_name, rsl.rcv_sub_ledger_id FROM rcv_receiving_sub_ledger rsl WHERE period_name = '&period_name' AND accrual_method_flag = 'P'; 8. SQL -8 SELECT rsl.reference3 PO_distribution_id , rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, rsl.period_name, rsl.rcv_sub_ledger_id FROM rcv_receiving_sub_ledger rsl WHERE period_name = '&period_name' AND accrual_method_flag = 'P' AND reference2 ='&po_header_id'; 9. SQL -9 SELECT pod.po_distribution_id, rsl.rcv_sub_ledger_id sub_ledger_id_missing_in_SLA, rsl.creation_date, rsl.set_of_books_id ledger_id FROM rcv_receiving_sub_ledger rsl, rcv_transactions rt, po_headers_all poh, po_line_locations_all poll, po_distributions_all pod, gl_period_statuses gp WHERE poll.accrue_on_receipt_flag = 'N' AND poll.po_header_id = poh.po_header_id AND rsl.reference2 = poh.po_header_id AND pod.po_header_id = poh.po_header_id AND rsl.reference3 = pod.po_distribution_id AND pod.line_location_id = poll.line_location_id AND rsl.period_name = '&period_name' AND rsl.accounting_line_type = 'Accrual' AND rsl.rcv_sub_ledger_id NOT IN (SELECT source_distribution_id_num_1 FROM xla_distribution_links WHERE source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND ae_header_id IN (SELECT ae_header_id FROM xla_ae_headers ) ) AND poh.segment1 = '&po_number' AND poh.org_id = &org_id; 10. SQL -10 SELECT xdl.ae_header_id FROM xla.xla_distribution_links xdl, xla.xla_ae_lines xal, po.rcv_receiving_sub_ledger rrsl WHERE rrsl.gl_sl_link_id =xal.gl_sl_link_id AND xal.gl_sl_link_table ='RSL' AND xal.application_id =707 AND xdl.source_distribution_type ='RCV_RECEIVING_SUB_LEDGER' AND xdl.source_distribution_id_num_1 IS NULL AND xdl.application_id =707 AND xdl.application_id =xal.application_id AND xdl.ref_ae_header_id =xal.ae_header_id AND xdl.temp_line_num =xal.ae_line_num AND xdl.ae_header_id =xal.ae_header_id AND rrsl.rcv_sub_ledger_id IS NOT NULL AND xal.ledger_id = rrsl.set_of_books_id ; 11. SQL -11 SELECT rsl.reference3 AS po_distribution_id, rsl.reference2 AS po_header_id, xah.ae_header_id, xah.accounting_entry_status_code, xah.gl_transfer_status_code, xah.accrual_reversal_flag, xah.parent_ae_header_id, xah.period_name FROM rcv_receiving_sub_ledger rsl, xla_ae_headers xah, xla_distribution_links xdl WHERE xah.accounting_entry_status_code <> 'F' AND xah.ae_header_id = xdl.ae_header_id AND xdl.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xdl.source_distribution_id_num_1 = rsl.rcv_sub_ledger_id AND xah.event_type_code = 'PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND rsl.rcv_transaction_id = 0 AND rsl.reference2 = &PO_header_id; 12. SQL -12 SELECT rsl.reference3 AS po_distribution_id, rsl.reference2 AS po_header_id, xah.ae_header_id, xah.accounting_entry_status_code, xah.gl_transfer_status_code, xah.accrual_reversal_flag, xah.parent_ae_header_id, xah.period_name FROM rcv_receiving_sub_ledger rsl, xla_ae_headers xah, xla_distribution_links xdl WHERE xah.accounting_entry_status_code <> 'F' AND xah.ae_header_id = xdl.ae_header_id AND xdl.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xdl.source_distribution_id_num_1 = rsl.rcv_sub_ledger_id AND xah.event_type_code = 'PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND rsl.rcv_transaction_id = 0; 13. SQL -13 SELECT * FROM xla_accounting_errors WHERE event_id IN (SELECT event_id FROM xla_ae_headers WHERE accounting_entry_status_code IN ('I' , 'E', 'R') AND event_type_code = 'PERIOD_END_ACCRUAL' AND period_name = '&period_name' ); 14. SQL -14 SELECT rsl.reference3 po_distribution_id, rsl.creation_date, xh.accounting_date, rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, xh.ae_header_id, xh.period_name FROM xla_ae_headers xh, xla_distribution_links xd, rcv_receiving_sub_ledger rsl WHERE xd.event_type_code ='PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND xh.ledger_id = &ledger_id AND xh.ae_header_id = xd.ae_header_id AND xd.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xd.source_distribution_id_num_1 =rsl.rcv_sub_ledger_id AND rsl.period_name = xh.period_name AND rsl.set_of_books_id = xh.ledger_id AND accrual_reversal_flag = 'Y' AND xh.ae_header_id NOT IN (SELECT parent_ae_header_id FROM xla_ae_headers WHERE event_type_code ='PERIOD_END_ACCRUAL' AND period_name = '&period_name' AND ledger_id = &ledger_id AND accrual_reversal_flag = 'N'); 15. SQL -15 SELECT rsl.reference3 po_distribution_id, rsl.creation_date, rsl.accounting_date, rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, xh.ae_header_id, xh.period_name, xh.accounting_entry_status_code, xh.Gl_transfer_status_code FROM xla_ae_headers xh, xla_distribution_links xd, xla_ae_lines xl, rcv_receiving_sub_ledger rsl WHERE xd.event_type_code ='PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND xl.ledger_id = &ledger_id AND xh.ae_header_id =xd.ae_header_id AND xh.ae_header_id = xl.ae_header_id AND xd.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xd.source_distribution_id_num_1 =rsl.rcv_sub_ledger_id AND rsl.period_name = xh.period_name AND rsl.set_of_books_id = xh.ledger_id AND accrual_reversal_flag = 'Y' AND xl.gl_sl_link_id NOT IN (SELECT gl_sl_link_id FROM gl_import_references WHERE gl_sl_link_table = 'XLAJEL' ); 16. SQL -16 SELECT rsl.reference3 po_distribution_id, rsl.creation_date, rsl.accounting_date , rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, xh.ae_header_id, xh.period_name, xh.accounting_entry_status_code, xh.Gl_transfer_status_code FROM xla_ae_headers xh, xla_distribution_links xd, xla_ae_lines xl, rcv_receiving_sub_ledger rsl WHERE xd.event_type_code ='PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND xl.ledger_id = &ledger_id AND xh.ae_header_id =xd.ae_header_id AND xh.ae_header_id = xl.ae_header_id AND xd.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xd.source_distribution_id_num_1 =rsl.rcv_sub_ledger_id AND rsl.period_name = xh.period_name AND rsl.set_of_books_id = xh.ledger_id AND accrual_reversal_flag = 'Y' AND xl.gl_sl_link_id NOT IN (SELECT gl_sl_link_id FROM gl_import_references WHERE gl_sl_link_table = 'XLAJEL' ) AND rsl.reference2 = '&po_header_id'; 17. SQL -17 SELECT rsl.reference3 po_distribution_id, rsl.creation_date, rsl.accounting_date , rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, xh.ae_header_id, xh.period_name, xh.accounting_entry_status_code, xh.Gl_transfer_status_code FROM xla_ae_headers xh, xla_distribution_links xd, xla_ae_lines xl, rcv_receiving_sub_ledger rsl WHERE xd.event_type_code ='PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND xl.ledger_id = &ledger_id AND xh.ae_header_id =xd.ae_header_id AND xh.ae_header_id = xl.ae_header_id AND xd.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xd.source_distribution_id_num_1 =rsl.rcv_sub_ledger_id AND rsl.period_name = xh.period_name AND rsl.set_of_books_id = xh.ledger_id AND accrual_reversal_flag = 'N' AND xl.gl_sl_link_id NOT IN (SELECT gl_sl_link_id FROM gl_import_references WHERE gl_sl_link_table = 'XLAJEL' ); 18. SQL -18 SELECT rsl.reference3 po_distribution_id, rsl.creation_date, rsl.accounting_date , rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, xh.ae_header_id, xh.period_name, xh.accounting_entry_status_code, xh.Gl_transfer_status_code FROM xla_ae_headers xh, xla_distribution_links xd, xla_ae_lines xl, rcv_receiving_sub_ledger rsl WHERE xd.event_type_code ='PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND xh.ledger_id = &ledger_id AND xh.ae_header_id =xd.ae_header_id AND xh.ae_header_id = xl.ae_header_id AND xd.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xd.source_distribution_id_num_1 =rsl.rcv_sub_ledger_id AND rsl.period_name = xh.period_name AND rsl.set_of_books_id = xh.ledger_id AND accrual_reversal_flag = 'N' AND xl.gl_sl_link_id NOT IN (SELECT gl_sl_link_id FROM gl_import_references WHERE gl_sl_link_table = 'XLAJEL' ) AND rsl.reference2 = '&po_header_id'; 19. SQL -19 SELECT rsl.reference3 po_distribution_id, rsl.creation_date, rsl.accounting_date , rsl.accounted_cr accrual_amount, rsl.accounted_dr charge_amount, xh.ae_header_id, xh.period_name, xh.accounting_entry_status_code, xh.Gl_transfer_status_code FROM xla_ae_headers xh, xla_distribution_links xd, xla_ae_lines xl, rcv_receiving_sub_ledger rsl WHERE xd.event_type_code ='PERIOD_END_ACCRUAL' AND rsl.period_name = '&period_name' AND xh.ledger_id = &ledger_id AND xh.ae_header_id =xd.ae_header_id AND xh.ae_header_id = xl.ae_header_id AND xd.source_distribution_type = 'RCV_RECEIVING_SUB_LEDGER' AND xd.source_distribution_id_num_1 =rsl.rcv_sub_ledger_id AND rsl.period_name = xh.period_name AND rsl.set_of_books_id = xh.ledger_id AND accrual_reversal_flag = 'Y' AND xh.ae_header_id IN (SELECT parent_ae_header_id FROM xla_ae_headers xh1 WHERE xh1.gl_transfer_status_code <> 'Y' AND xh1.event_type_code = 'PERIOD_END_ACCRUAL' AND xh1.period_name = xh.period_name AND xh1.accrual_reversal_flag = 'N' ); 20. SQL -20 SELECT (pd.nonrecoverable_tax/pd.quantity_ordered)*pll.price_override po_unit_pr ice_plus_NR_tax, po_distribution_id FROM po_distributions_all pd, po_line_locations_all pll WHERE pd.line_location_id = pll.line_location_id; 21. SQL -21 SELECT DISTINCT poh.segment1 po_number, pod.po_distribution_id po_distribution_id, poll.line_location_id line_location_id, DECODE(poll.matching_basis, 'AMOUNT', 1, 0) service_flag, DECODE (poll.matching_basis, 'AMOUNT', pod.amount_ordered - NVL(pod.amount_can celled, 0), pod.quantity_ordered - NVL(pod.quantity_cancelled, 0)) distribution_ quantity, DECODE (poll.matching_basis, 'AMOUNT', pod.amount_ordered, pod.quantity_ordere d) quantity_ordered, DECODE(poll.matching_basis, 'AMOUNT', poll.amount - NVL(poll.amount_cancelled, 0), poll.quantity - NVL(poll.quantity_cancelled,0)) shipment_quantity, NVL(poll.price_override,0) po_price, NVL(poll.match_option,'P') match_option, poh.currency_code currency_code, NVL(NVL(pod.rate,poh.rate),1) currency_rate, poh.rate_type curr_conv_type, pod.rate_date currency_conv_date FROM po_distributions_all pod, po_line_locations_all poll, po_headers_all poh, gl_period_statuses gp WHERE poll.po_header_id = poh.po_header_id AND pod.line_location_id = poll.line_location_id AND poh.type_lookup_code IN ('STANDARD', 'BLANKET', 'PLANNED') AND poll.shipment_type <> 'PREPAYMENT' AND gp.period_name = '&period_name' AND gp.ledger_id = &ledger_id AND (poll.closed_date IS NULL OR poll.closed_date > gp.end_date) AND NVL(poll.accrue_on_receipt_flag,'N') = 'N' AND pod.destination_type_code = 'EXPENSE' AND NVL(pod.accrued_flag, 'N') = '&accrued_receipt' AND poll.org_id = &org_id AND DECODE (poll.matching_basis, 'AMOUNT', (pod.amount_ordered - NVL(pod.amount_ cancelled, 0)), (pod.quantity_ordered - NVL(pod.quantity_cancelled, 0)) ) > 0 AND DECODE(poll.matching_basis, 'AMOUNT', (poll.amount - NVL(poll.amount _cancelled, 0)), (poll.quantity - NVL(poll.quantity_cancelled,0)) ) > 0 AND EXISTS (SELECT 1 FROM rcv_transactions rvt WHERE rvt.po_line_location_id = poll.line_location_id AND rvt.transaction_type IN ('RECEIVE','MATCH') AND rvt.transaction_date <= gp.end_date ) ORDER BY poll.line_location_id;