Sei sulla pagina 1di 6

CREATE OR REPLACE PROCEDURE APPS.

xx_gl_import_proc(errbuf out varchar2,retcode o


ut varchar2)
AS
v_set_of_book_id NUMBER (15); -- To capture set of book id
v_source_name VARCHAR2 (25); -- To capture source_name
v_category_name VARCHAR2 (25); -- To Capture Catogiry Name
v_chart_of_accounts_id NUMBER (15); -- TO capture Chart Of Account Id
v_code_combination_id NUMBER (15);
v_application_id NUMBER (15);
v_closing_status VARCHAR (1);
v_flag VARCHAR (1);
v_currency_code VARCHAR2 (15);
l_period_set_name VARCHAR2 (15);
l_accounted_period_type VARCHAR2 (15);
v_err_messege VARCHAR2 (3000);
v_period_name VARCHAR2 (15);
x_group_id number;
CURSOR c
IS
SELECT *
FROM XX_GL_STAGING
WHERE status_flag = 'N';
BEGIN
select XX_GL_GROUP_ID_S.nextval into x_group_id from dual;
FOR i IN c
LOOP
v_flag := 'I';
v_err_messege:=null;
v_code_combination_id:=i.CODE_COMB_ID;
--To Capture Set Of Book Id
BEGIN
SELECT set_of_books_id
INTO v_set_of_book_id
FROM gl_sets_of_books
WHERE set_of_books_id = i.SET_OF_BOOKS_ID;
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege := v_err_messege || 'Invalid set of books id\';
END;
--TO GET CHART OF ACCOUNT
BEGIN
SELECT chart_of_accounts_id
INTO v_chart_of_accounts_id
FROM gl_sets_of_books
WHERE set_of_books_id = (v_set_of_book_id);
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege :=
v_err_messege || 'Chart Of Account Id Is not Existing \';
END;
--SOURCE VALIDATION
BEGIN
SELECT user_je_source_name
INTO v_source_name
FROM gl_je_sources
WHERE UPPER (user_je_source_name) = UPPER (trim(i.JOURNAL_NAME));
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege := v_err_messege || 'Invalid Source Name\';
END;
--Category Validatrion
BEGIN
SELECT user_je_category_name
INTO v_category_name
FROM gl_je_categories
WHERE UPPER (user_je_category_name) =
UPPER (i.JOURNAL_CATEGORY_NAME);
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege := v_err_messege || 'Invalid Category Name\';
END;
--Capture The Application Id for Validation of perioad Status
BEGIN
SELECT application_id
INTO v_application_id
FROM fnd_responsibility_vl
WHERE responsibility_id = 20434;
-- fnd_profile.value('resp_id'); --50553 for testing
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege :=
v_err_messege || 'Application Id is Not Existing\';
END;
BEGIN
SELECT period_set_name, accounted_period_type
INTO l_period_set_name, l_accounted_period_type
FROM gl_sets_of_books
WHERE set_of_books_id = v_set_of_book_id;
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege :=
v_err_messege
|| 'Period Set Name, Accounted Period Type are Not Existing \';
END;
BEGIN
SELECT period_name
INTO v_period_name
FROM gl_periods
WHERE period_set_name = l_period_set_name
AND start_date <= '02-JAN-2011'
AND '02-JAN-2011' <= end_date
AND period_type = l_accounted_period_type;
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege := v_err_messege || 'Period Name is Not Existing\';
END;
-- END;
--Validation of perioad Status
BEGIN
SELECT closing_status
INTO v_closing_status
FROM gl_period_statuses
WHERE set_of_books_id = v_set_of_book_id
AND period_name = v_period_name
AND application_id = v_application_id
AND closing_status = 'O';
-- v_flag:='I' ; -- in('O');
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege :=
v_err_messege
|| 'Transaction Date is Not In Open and Futur Period\';
END;
/* BEGIN
SELECT code_combination_id
INTO v_code_combination_id
FROM gl_code_combinations_kfv
WHERE concatenated_segments =
trim(i.segment1)
|| '.'
|| trim(i.segment2)
|| '.'
|| trim(i.segment3)
|| '.'
|| trim(i.segment4)
|| '.'
|| trim(i.segment5)
|| '.'
|| trim(i.segment6)
|| '.'
|| trim(i.segment7)
|| '.'
|| trim(i.segment8)
AND chart_of_accounts_id = v_chart_of_accounts_id;
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege :=
v_err_messege || 'Code Combination Id Is Not Existing \';
END;*/
-- IF i.status <> 'NEW'
-- THEN
-- v_flag := 'E';
-- END IF;

BEGIN
SELECT currency_code
INTO v_currency_code
FROM fnd_currencies
WHERE currency_code = trim(i.currency_code);
EXCEPTION
WHEN OTHERS
THEN
v_flag := 'E';
v_err_messege :=
v_err_messege || 'Currency Code is Not Existing \';
END;
IF (i.DEBIT_AMT IS NULL) AND (i.CREDIT_AMT IS NOT NULL)
OR ((i.DEBIT_AMT IS NOT NULL) AND i.CREDIT_AMT IS NULL)
THEN
NULL;
ELSE
v_flag := 'E';
v_err_messege :=
v_err_messege || 'Enter Either Debit Balance Or Credit Balance \';
END IF;
-- IF (i.accounted_dr IS NULL) AND (i.accounted_cr IS NOT NULL)
-- OR ((i.accounted_dr IS NOT NULL) AND i.accounted_cr IS NULL)
-- THEN
-- NULL;
-- ELSE
-- v_flag := 'E';
-- v_err_messege :=
-- v_err_messege || 'Enter Either Accounted Debit Balance Or Credit B
alance \';
-- END IF;
fnd_file.put_line(fnd_file.log,'V_FLAG'||': '||v_flag);
IF v_flag <>'E'
THEN
begin

fnd_file.put_line(fnd_file.log,'Before inserting into interface');


INSERT INTO gl_interface
(status,
set_of_books_id,
accounting_date,
currency_code,
date_created,
created_by,
actual_flag,
user_je_category_name,
user_je_source_name,
--currency_conversion_date,
--user_currency_conversion_type,
--currency_conversion_rate,
je_line_num,
entered_dr,
entered_cr,
-- accounted_dr,
-- accounted_cr,
--reference10,
period_name,
chart_of_accounts_id,
code_combination_id,
GROUP_ID
)
VALUES (i.status,
v_set_of_book_id,
'2-JAN-2011',--i.accounting_date,
v_currency_code,
i.date_created,
i.created_by,
i.actual_flag,
v_category_name,
v_source_name,
--i.CURRENCY_CONVERSION_DATE,
--i.USER_CURRENCY_CONVERSION_TYPE,
--i.CURRENCY_CONVERSION_RATE,
i.JE_LINE_NUM,
i.DEBIT_AMT,
i.CREDIT_AMT,
-- i.accounted_dr,
-- i.accounted_cr,
--i.Line_Description,
v_period_name,
v_chart_of_accounts_id,
v_code_combination_id,
x_group_id
);
fnd_file.put_line(fnd_file.log,i.JE_LINE_NUM||':'||'Inserted Sucessfully ');
COMMIT;
exception
when others then
fnd_file.put_line(fnd_file.log,i.JE_LINE_NUM||': Not Inserted Error
: '||SQLCODE||': '||SQLERRM);
END;
ELSE
BEGIN
INSERT INTO XX_GL_STG_E
(status, set_of_books_id, accounting_date,
currency_code, date_created, created_by,
actual_flag, user_je_category_name,
user_je_source_name,
segment1, segment2,
segment3, segment4, entered_dr, entered_cr,
GROUP_ID, status_flag, err_messege,je_line_num
)
VALUES (i.status, i.set_of_books_id, '02-JAN-2011',
i.currency_code, i.date_created, i.created_by,
i.actual_flag, i.JOURNAL_CATEGORY_NAME,
i.JOURNAL_NAME,
i.segment1, i.segment2,
i.segment3, i.segment4, i.DEBIT_AMT, i.CREDIT_AMT,
x_group_id, 'E', v_err_messege,i.je_line_num
);
COMMIT;
exception
when others then
fnd_file.put_line(fnd_file.log,i.JE_LINE_NUM||': In Else Not Inserted
Error: '||SQLCODE||': '||SQLERRM);
END;
END IF;
v_flag:='I';
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
fnd_file.put_line(fnd_file.log,': End Loop - Not Inserted Error: '||SQL
CODE||': '||SQLERRM);
END xx_gl_import_proc;
/