0% found this document useful (0 votes)
251 views

Negative Ledger Id Dfix - SQL

This script deletes journal entries from accounting tables with negative ledger IDs. It identifies the affected journal entries, backs them up to temporary tables, then calls an API to delete the journal batches containing the negative ledger entries. The script must be run with the primary ledger ID, bug number, and journal entry source name provided as parameters.

Uploaded by

Kriez Namuhuja
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
251 views

Negative Ledger Id Dfix - SQL

This script deletes journal entries from accounting tables with negative ledger IDs. It identifies the affected journal entries, backs them up to temporary tables, then calls an API to delete the journal batches containing the negative ledger entries. The script must be run with the primary ledger ID, bug number, and journal entry source name provided as parameters.

Uploaded by

Kriez Namuhuja
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

REM

+================================================================================+
REM |
|
REM | File Name : Negative_ledger_id_dfix.txt
|
REM |
|
REM | Issue: Data exists in GL with Negative ledger_id.
|
REM | |
REM | Fix Approach : Run this script to purge the negative ledger_id data in GL.
|
REM | This script has to be run only by providing primary ledger_id.
|
REM |
|
REM | USAGE
|
REM | Supply the following when prompted:
|
REM | 1) P_File_name : Provide file_name in .html format
|
REM | 2) P_Ledger_id : Provide Primary_ledger_id
|
REM | 3) P_Bug_Number: Provide Bug number
|
REM | (Provide only numbers without wild card characters)
|
REM | 4) P_je_source_name: Provide Journal Entry Soruce_name
|
REM
*================================================================================*/
set verify off
set linesize 20000
Set ECHO OFF
set heading on
Set MARKUP HTML ON SPOOL ON
Set trimspool on
set pagesize 500;
set serveroutput on;

PROMPT PROVIDE FILE NAME


Define P_FILE_NAME = &p_file_Name

PROMPT PROVIDE PRIMARY LEDGER ID ONLY


Define P_LEDGER_ID = &primary_ledger_id

PROMPT PROVIDE BUG#


Define P_BUG_NUMBER = &BUG_NUMBER

PROMPT Provide Je Source


Define P_JE_SOURCE_NAME = '&p_je_source_name'

SPOOL &p_file_name

PROMPT ****Datafix to delete negative ledger id data from Gl tables****


PROMPT ------------------------------------------------------------------
PROMPT DROP BACK UP TABLES IF ANY
PROMPT ----------------------------------------------------

drop table gl_invalid_jrnls_&P_BUG_NUMBER;


drop table gl_je_batches_&P_BUG_NUMBER;
drop table gl_je_headers_&P_BUG_NUMBER;
drop table gl_je_lines_&P_BUG_NUMBER;
drop table gir_&P_BUG_NUMBER;

PROMPT

PROMPT CREATING TABLE gl_invalid_jrnls_&P_BUG_NUMBER


PROMPT ----------------------------------------------------

create table gl_invalid_jrnls_&P_BUG_NUMBER as


select /*+ parallel(h) parallel(i) leading(h) */
h.ledger_id, h.je_header_id , h.je_batch_id, ir.gl_sl_link_id,
ir.gl_sl_link_table
from gl_je_headers h , gl_import_references ir
where h.ledger_id in (SELECT -1 * (gled.ledger_id)
FROM gl_ledger_relationships glr, gl_ledgers gled
WHERE glr.primary_ledger_id = &p_ledger_id
AND glr.application_id = 101
AND ((glr.target_ledger_category_code IN ('SECONDARY','ALC')
AND glr.relationship_type_code = 'SUBLEDGER')
OR (glr.target_ledger_category_code IN ('PRIMARY')
AND glr.relationship_type_code = 'NONE'))
and glr.target_ledger_id = gled.ledger_id
AND Nvl(gled.complete_flag,'Y') = 'Y'
group by gled.ledger_id)
and h.je_batch_id = ir.je_batch_id
and h.je_header_id = ir.je_header_id
and h.je_source = '&p_je_source_name'
;

PROMPT CREATING TABLE gl_je_batches_&P_BUG_NUMBER


PROMPT ----------------------------------------------------

create table gl_je_batches_&P_BUG_NUMBER as


select * from gl_je_batches where je_batch_id in
( select distinct je_batch_id from gl_invalid_jrnls_&P_BUG_NUMBER );
PROMPT

PROMPT CREATING TABLE gl_je_headers_&P_BUG_NUMBER


PROMPT ----------------------------------------------------

create table gl_je_headers_&P_BUG_NUMBER as


select * from gl_je_headers where je_batch_id in
( select distinct je_batch_id from gl_invalid_jrnls_&P_BUG_NUMBER );
PROMPT

PROMPT CREATING TABLE gl_je_lines_&P_BUG_NUMBER


PROMPT ----------------------------------------------------

create table gl_je_lines_&P_BUG_NUMBER as


select * from gl_je_lines where je_header_id in
( select distinct je_header_id from gl_je_headers_&P_BUG_NUMBER );
PROMPT
PROMPT CREATING TABLE gir_&P_BUG_NUMBER
PROMPT ----------------------------------------------------

create table gir_&P_BUG_NUMBER as


select * from gl_import_references
where (je_header_id) in
( select je_header_id from gl_invalid_jrnls_&P_BUG_NUMBER );

PROMPT

PROMPT For encumbrance journals update budgetary_control_status to 'R' if set to


'P'
PROMPT
-----------------------------------------------------------------------------

update gl_je_batches
set budgetary_control_status = 'R'
where je_batch_id in
(select distinct je_batch_id from gl_invalid_jrnls_&P_BUG_NUMBER )
and actual_flag in ('A', 'E')
and budgetary_control_status = 'P';

PROMPT

PROMPT CALL GL API TO DELETE THE BATCHES


PROMPT ----------------------------------------------------

declare
CURSOR rev_batch is
select distinct b.rowid, b.je_batch_id ,b.name
from gl_je_batches b,
gl_invalid_jrnls_&P_BUG_NUMBER b1
where b.je_batch_id = b1.je_batch_id;

x_row_id VARCHAR2(1000);
x_je_batch_id number;
x_name VARCHAR2(1000);
begin
DBMS_OUTPUT.ENABLE(null);

DBMS_OUTPUT.PUT_LINE('Starting to delete any -ve ledger Batches');


open rev_batch;

loop
fetch rev_batch into x_row_id, x_je_batch_id, x_name;
exit when rev_batch%NOTFOUND;

DBMS_OUTPUT.PUT_LINE(' Deleting Batch: '|| x_je_batch_id|| ' NAME: '||


x_name);
gl_je_batches_pkg.Delete_Row(x_row_id,x_je_batch_id);
commit;

end loop;

exception
when others then
DBMS_OUTPUT.PUT_LINE('error for batch name: '||x_name||' '|| SQLERRM);

end;
/

UNDEFINE P_FILE_NAME
UNDEFINE P_LEDGER_ID
UNDEFINE P_BUG_NUMBER
UNDEFINE P_JE_SOURCE_NAME

set markup html off;


spool off;

You might also like