0% found this document useful (0 votes)
196 views43 pages

BTC Payroll Migration PKG

This package contains procedures for migrating payroll data from one system to another. It includes procedures for: 1. Creating formulas, functions, context parameters and other payroll elements in the new system through API calls. 2. End dating existing elements, deleting links between elements, and creating and populating user defined tables and columns for migrated payroll data. 3. Additional helper procedures for compiling formulas after creation and changing global variables during the migration process. The package body defines the implementation of each procedure to execute the necessary API calls and database operations to migrate the payroll elements and data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
196 views43 pages

BTC Payroll Migration PKG

This package contains procedures for migrating payroll data from one system to another. It includes procedures for: 1. Creating formulas, functions, context parameters and other payroll elements in the new system through API calls. 2. End dating existing elements, deleting links between elements, and creating and populating user defined tables and columns for migrated payroll data. 3. Additional helper procedures for compiling formulas after creation and changing global variables during the migration process. The package body defines the implementation of each procedure to execute the necessary API calls and database operations to migrate the payroll elements and data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 43

create or replace PACKAGE BTC_payroll_migration_pkg

AS
g_business_group_id apps.per_all_people_f.business_group_id%TYPE
:= '101';
-- Migration BG ID
g_effective_date DATE :=
to_date('01-JAN-1951','DD-MON-RRRR');
-- g_skip_formula VARCHAR2 (100) := 'AE_ONCE_EACH_PERIOD WMR';
-- g_event_group_name VARCHAR2 (200) := 'HRI_SALARY_EVG_WMR';
g_user_id fnd_user.user_id%TYPE := 1110;
g_resp_id fnd_responsibility.responsibility_id%TYPE := 53720;
g_resp_appl_id fnd_responsibility.application_id%TYPE := 800;

PROCEDURE create_formula_api;

PROCEDURE create_function_api;

PROCEDURE create_context_param_api;

PROCEDURE create_func_parameter_api;

PROCEDURE create_balance_type_api;

PROCEDURE create_element_type_api;

PROCEDURE create_input_values_api;

PROCEDURE create_balance_feeds_api;

PROCEDURE create_defined_bal_dim_api;

PROCEDURE create_formula_results_api;

PROCEDURE create_element_link_api;

PROCEDURE compile_formula;

PROCEDURE run_apis;

PROCEDURE BTC_delete_element_link_p (
p_business_group_id IN apps.pay_element_types_f.business_group_id%TYPE,
p_element_name IN apps.pay_element_types_f.element_name%TYPE,
p_effective_date IN DATE
);

PROCEDURE BTC_end_date_p (
p_table_name IN VARCHAR2,
p_column_name IN VARCHAR2,
p_business_group_id IN NUMBER,
p_effective_date IN DATE
);

PROCEDURE BTC_create_user_table_api_p (
p_table_name VARCHAR2,
p_business_group_id NUMBER,
p_effective_date IN DATE
);

PROCEDURE BTC_create_user_column_api_p (
p_table_name IN VARCHAR2,
p_column_name IN VARCHAR2,
p_name_of_formula IN VARCHAR2,
p_business_group_id IN NUMBER,
p_effective_date IN DATE
);

PROCEDURE BTC_user_row_api (
p_table_name IN VARCHAR2,
p_business_group_id IN NUMBER,
p_effective_date IN DATE
);

PROCEDURE BTC_user_values_api (
p_business_group_id IN NUMBER,
p_user_table IN VARCHAR2,
p_column_name IN VARCHAR2,
p_row_name IN VARCHAR2,
p_value IN VARCHAR2,
p_effective_date IN DATE
);

PROCEDURE BTC_user_column_values_api (
p_business_group_id IN NUMBER,
p_user_table IN VARCHAR2,
p_effective_date IN DATE
);
procedure BTC_change_global_var(
p_business_group_id IN apps.pay_element_types_f.business_group_id%TYPE,
p_effective_date IN DATE,
p_RESPONSIBILITY_NAME in apps.fnd_responsibility_tl.RESPONSIBILITY_NAME%type

);
END BTC_payroll_migration_pkg;

create or replace PACKAGE BODY BTC_payroll_migration_pkg


AS
PROCEDURE create_formula_api
AS
l_error_msg VARCHAR2 (1000) := 'No Error';

CURSOR c_ff
IS
SELECT ROWID, ff_formulas_s.NEXTVAL formula_id,
effective_start_date, effective_end_date,
business_group_id business_group_id, legislation_code,
formula_type_id, new_formula_name, description, sticky_flag,
last_update_date, last_updated_by, last_update_login,
created_by, creation_date, compile_flag, formula_text
FROM BTC_pay_formulas_t
WHERE process_flag IS NULL
AND formula_type_id = 61 --- Only Payroll formula
--AND new_formula_name = 'New Hire Mobilization AAH'
;
BEGIN
FOR ff_create IN c_ff
LOOP
BEGIN
DBMS_OUTPUT.put_line ( ' Creating Fast formulas : '
|| ff_create.new_formula_name
);

INSERT INTO ff_formulas_f


(formula_id, effective_start_date,
effective_end_date,
business_group_id,
legislation_code,
formula_type_id,
formula_name, description,
sticky_flag, last_update_date,
last_updated_by,
last_update_login, created_by,
creation_date, compile_flag,
formula_text
)
VALUES (ff_create.formula_id, g_effective_date,
ff_create.effective_end_date,
ff_create.business_group_id,
ff_create.legislation_code,
ff_create.formula_type_id,
ff_create.new_formula_name, ff_create.description,
ff_create.sticky_flag, ff_create.last_update_date,
ff_create.last_updated_by,
ff_create.last_update_login, ff_create.created_by,
ff_create.creation_date, ff_create.compile_flag,
ff_create.formula_text
);

UPDATE BTC_pay_formulas_t
SET process_flag = 'Y'
WHERE ROWID = ff_create.ROWID;

COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 999);

INSERT INTO BTC_pay_formulas_err_t


VALUES (ff_create.formula_id, ff_create.new_formula_name,
l_error_msg);

DBMS_OUTPUT.put_line ( ' Error Creating Fast formulas : '


|| l_error_msg
);
COMMIT;
END;
END LOOP;
END;

PROCEDURE create_function_api
IS
l_function_id apps.ff_functions.function_id%TYPE;
l_object_version_number apps.ff_functions.object_version_number%TYPE;
l_seq_no NUMBER;
l_error_msg VARCHAR2 (4000);
CURSOR func
IS
SELECT ROWID, a.*
FROM BTC_pay_function_upload_t a
WHERE process_flag IS NULL
-- and name='BTC_DAYS_BETWEEN_F'
;
BEGIN
FOR i IN func
LOOP
DECLARE
BEGIN
DBMS_OUTPUT.put_line (' Creating formulas Function : ' || i.NAME);
ff_functions_api.create_function
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_name => i.NAME,
p_class => i.CLASS,
p_business_group_id => i.business_group_id,
p_legislation_code => i.legislation_code,
p_alias_name => i.alias_name,
p_data_type => i.data_type,
p_definition => i.definition,
p_description => i.description,
p_function_id => l_function_id,
p_object_version_number => l_object_version_number
);

UPDATE BTC_pay_function_upload_t
SET process_flag = 'Y',
function_id = l_function_id
WHERE ROWID = i.ROWID;

DBMS_OUTPUT.put_line ( 'Function : '


|| i.NAME
|| '::created with function ID::'
|| l_function_id
);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 3999);

INSERT INTO BTC_pay_function_upload_err_t


VALUES (i.seq_id, l_error_msg);

UPDATE BTC_pay_function_upload_t
SET process_flag = 'E'
WHERE ROWID = i.ROWID;

DBMS_OUTPUT.put_line
( 'Error Message while upoading Function : '
|| l_error_msg
);
END;
END LOOP;

COMMIT;
END;

PROCEDURE create_context_param_api
AS
l_function_id apps.ff_functions.function_id%TYPE;
l_sequence_number apps.ff_function_context_usages.sequence_number
%TYPE;
l_object_version_number
apps.ff_function_context_usages.object_version_number%TYPE;
l_context_id apps.ff_function_context_usages.context_id%TYPE;
l_error_msg VARCHAR2 (4000);

CURSOR c1
IS
SELECT ROWID, scp.*
FROM BTC_pay_contex_param_t scp
WHERE process_flag IS NULL
ORDER BY scp.sequence_number ASC;
BEGIN
FOR k IN c1
LOOP
-- DBMS_OUTPUT.put_line ('Function ID : '|| l_function_id);
DBMS_OUTPUT.put_line ('Context ID : ' || k.context_id);

DECLARE
BEGIN
SELECT ff.function_id
INTO l_function_id
FROM ff_functions ff
WHERE ff.business_group_id = g_business_group_id
AND UPPER (ff.NAME) = UPPER (k.function_name);

--AND creation_date >= g_effective_date;


DBMS_OUTPUT.put_line ('Function ID : ' || l_function_id);
--DBMS_OUTPUT.put_line ('context ID : '|| k.context_id);
ff_function_context_usg_api.create_context
(p_validate => FALSE,
p_function_id => l_function_id,
p_context_id => k.context_id,
-- context ID same for Instance we are use direct for
prev BG.
p_sequence_number => k.sequence_number,
p_object_version_number => l_object_version_number
);

UPDATE BTC_pay_contex_param_t
SET process_flag = 'Y'
WHERE ROWID = k.ROWID;

DBMS_OUTPUT.put_line
( 'upoading Function Contexts for Function : '
|| k.function_name
|| 'With Context ID'
|| k.context_id
);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 3999);

INSERT INTO BTC_pay_contex_param_err_t


VALUES (k.seq_id, l_error_msg);

UPDATE BTC_pay_contex_param_t
SET process_flag = 'E'
WHERE ROWID = k.ROWID;

DBMS_OUTPUT.put_line
( 'Error Message while upoading Function Contexts: '
|| l_error_msg
);
END;

COMMIT;
END LOOP;
END;

PROCEDURE create_func_parameter_api
AS
l_function_id apps.ff_functions.function_id%TYPE;
l_object_version_number apps.ff_function_parameters.object_version_number
%TYPE;
l_sequence_number apps.ff_function_parameters.sequence_number%TYPE;
l_seq_no NUMBER;
l_error_msg VARCHAR2 (4000);

CURSOR param
IS
SELECT ROWID, a.*
FROM BTC_pay_function_param_t a
WHERE process_flag IS NULL
-- and FUNCTION_NAME='BTC_DAYS_BETWEEN_F'
ORDER BY sequence_number;
BEGIN
FOR j IN param
LOOP
BEGIN
DBMS_OUTPUT.put_line ( 'Adding parametr for Function : '
|| j.function_name
);

SELECT ff.function_id
INTO l_function_id
FROM ff_functions ff
WHERE ff.business_group_id = g_business_group_id
AND ff.NAME = j.function_name;

-- AND creation_date >= g_effective_date;


ff_function_parameters_api.create_parameter
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_function_id => l_function_id,
p_class => j.CLASS,
p_data_type => j.data_type,
p_name => j.NAME,
p_optional => j.optional,
p_continuing_parameter => j.continuing_parameter,
p_sequence_number => j.sequence_number,
p_object_version_number => l_object_version_number
);

UPDATE BTC_pay_function_param_t
SET process_flag = 'Y'
WHERE ROWID = j.ROWID;

DBMS_OUTPUT.put_line ( ' Function parameter Added for : '


|| j.function_name
|| ':Name:'
|| j.NAME
);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 3999);

INSERT INTO BTC_pay_function_param_err_t


VALUES (j.seq_id, l_error_msg);

UPDATE BTC_pay_function_param_t
SET process_flag = 'E'
WHERE ROWID = j.ROWID;

DBMS_OUTPUT.put_line
( 'Error Message while upoading Function Parameter: '
|| l_error_msg
);
COMMIT;
END;
END LOOP;
END;

PROCEDURE create_balance_type_api
AS
l_balance_type_id apps.pay_balance_types.base_balance_type_id%TYPE;
l_object_version_number apps.pay_balance_types.object_version_number%TYPE;
l_error_msg VARCHAR2 (4000);

CURSOR c_pay_balance_type
IS
SELECT ROWID, a.*
FROM BTC_pay_balance_types_t a
WHERE process_flag IS NULL
--and balance_name='Employee Referral Overpaid
Total Amount'
;
BEGIN
FOR bal_type IN c_pay_balance_type
LOOP
BEGIN
DBMS_OUTPUT.put_line ( 'Creating Balance Type : '
|| bal_type.balance_name
);
pay_balance_types_api.create_bal_type
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_language_code => hr_api.userenv_lang,
p_balance_name => bal_type.balance_name,
p_balance_uom => bal_type.balance_uom,
p_business_group_id => bal_type.business_group_id,
p_legislation_code => bal_type.legislation_code,
p_currency_code => bal_type.currency_code,
p_assignment_remuneration_flag =>
bal_type.assignment_remuneration_flag,
p_comments => NULL,
p_legislation_subgroup =>
bal_type.legislation_subgroup,
p_reporting_name => bal_type.reporting_name,
p_attribute_category => bal_type.attribute_category,
p_attribute1 => bal_type.attribute1,
p_attribute2 => bal_type.attribute2,
p_attribute3 => bal_type.attribute3,
p_attribute4 => bal_type.attribute4,
p_attribute5 => bal_type.attribute5,
p_attribute6 => bal_type.attribute6,
p_attribute7 => bal_type.attribute7,
p_attribute8 => bal_type.attribute8,
p_attribute9 => bal_type.attribute9,
p_attribute10 => bal_type.attribute10,
p_attribute11 => bal_type.attribute11,
p_attribute12 => bal_type.attribute12,
p_attribute13 => bal_type.attribute13,
p_attribute14 => bal_type.attribute14,
p_attribute15 => bal_type.attribute15,
p_attribute16 => bal_type.attribute16,
p_attribute17 => bal_type.attribute17,
p_attribute18 => bal_type.attribute18,
p_attribute19 => bal_type.attribute19,
p_attribute20 => bal_type.attribute20,
p_jurisdiction_level => bal_type.jurisdiction_level,
p_tax_type => bal_type.tax_type,
p_balance_category_id => bal_type.balance_category_id

--*****
,
p_base_balance_type_id =>
bal_type.base_balance_type_id,
p_input_value_id => bal_type.input_value_id,
p_balance_type_id => l_balance_type_id,
p_object_version_number => l_object_version_number
);

UPDATE BTC_pay_balance_types_t
SET process_flag = 'Y'
WHERE ROWID = bal_type.ROWID;

COMMIT;
DBMS_OUTPUT.put_line ( 'Balance Type Created: '
|| bal_type.balance_name
|| ':With Balance Type ID:'
|| l_balance_type_id
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 3999);

INSERT INTO BTC_pay_balance_type_err_t


VALUES (bal_type.balance_type_id, l_error_msg);

UPDATE BTC_pay_balance_types_t
SET process_flag = 'E'
WHERE ROWID = bal_type.ROWID;

COMMIT;
DBMS_OUTPUT.put_line
( 'Error Message while Creating Balance Type: '
|| l_error_msg
);
END;
END LOOP;
END;

PROCEDURE create_element_type_api
AS
l_element_type_id apps.pay_element_types_f.element_type_id
%TYPE;
l_effective_start_date apps.pay_element_types_f.effective_start_date
%TYPE;
l_effective_end_date apps.pay_element_types_f.effective_end_date
%TYPE;
l_object_version_number
apps.pay_element_types_f.object_version_number%TYPE;
l_comment_id apps.pay_element_types_f.comment_id%TYPE;
l_error_msg VARCHAR2 (4000);
l_classification_id apps.pay_element_types_f.classification_id
%TYPE;
l_formula_id apps.pay_element_types_f.formula_id%TYPE;
l_processing_priority_warning BOOLEAN;
l_count NUMBER (3) := 0;
l_debug_msg VARCHAR2 (100);
l_event_group_id apps.pay_event_groups.event_group_id%TYPE;

CURSOR pay_element_types
IS
SELECT ROWID, bb.*
FROM BTC_pay_element_types_t bb
WHERE bb.process_flag IS NULL
-- and
ELEMENT_NAME= 'Business Leave Allowance AAH'
--and
bb.seq_id=15
;
BEGIN
-- v_formula_name := 'AE_ONCE_EACH_PERIOD SEHA';
FOR ele_type IN pay_element_types
LOOP
BEGIN
l_debug_msg := '0';
l_classification_id := NULL;
l_formula_id := NULL;

SELECT classification_id
INTO l_classification_id
FROM pay_element_classifications
WHERE UPPER (classification_name) =
UPPER (ele_type.classification_name)
AND legislation_code = 'AE';

l_debug_msg := '1-' || TO_CHAR (l_classification_id);

/*SELECT formula_id
INTO l_formula_id
FROM ff_formulas_f
WHERE UPPER (formula_name) = g_skip_formula
AND business_group_id = ele_type.business_group_id;

SELECT peg.event_group_id
INTO l_event_group_id
FROM pay_event_groups peg
WHERE UPPER (peg.event_group_name) = g_event_group_name;*/
BEGIN
SELECT petf.formula_id, petf.recalc_event_group_id
INTO l_formula_id, l_event_group_id
FROM apps.pay_element_types_f petf
WHERE reporting_name LIKE 'Basic Salary'
-- we are getting the all ready create Event group and Formula ID , New new
mugration than get in above sql from global
AND business_group_id = ele_type.business_group_id;
EXCEPTION
WHEN OTHERS
THEN
l_formula_id := NULL;
l_event_group_id := NULL;
END;

IF ele_type.recalc_event_group_id IS NULL
THEN
l_event_group_id := NULL;
END IF;

IF (NVL (ele_type.indirect_only_flag, 'N') = 'Y')


THEN
l_formula_id := NULL;
END IF;

DBMS_OUTPUT.put_line ( 'Event Group ID and formula ID:'


|| l_event_group_id
|| ' '
|| l_formula_id
);
DBMS_OUTPUT.put_line ( 'Business Group ID :'
|| ele_type.business_group_id
);
pay_element_types_api.create_element_type
(p_validate => FALSE,
p_effective_date => g_effective_date,
--ele_type.effective_start_date,
p_classification_id => l_classification_id,
p_element_name => ele_type.element_name,
p_input_currency_code =>
ele_type.input_currency_code,
p_output_currency_code =>
ele_type.output_currency_code,
p_multiple_entries_allowed_fla =>
ele_type.multiple_entries_allowed_flag,
p_processing_type => ele_type.processing_type,
p_business_group_id => ele_type.business_group_id,
p_legislation_code => NULL,
p_formula_id => l_formula_id,
p_benefit_classification_id => NULL,
p_additional_entry_allowed_fla =>
ele_type.additional_entry_allowed_flag,
--'N',
p_adjustment_only_flag =>
ele_type.adjustment_only_flag,
--'N',
p_closed_for_entry_flag => NVL

(ele_type.closed_for_entry_flag,
'N'
),
--'N',
p_reporting_name => ele_type.reporting_name,
p_description => ele_type.description,
p_indirect_only_flag => ele_type.indirect_only_flag,
p_multiply_value_flag =>
ele_type.multiply_value_flag,
p_post_termination_rule =>
ele_type.post_termination_rule,
p_process_in_run_flag =>
ele_type.process_in_run_flag,
p_processing_priority =>
ele_type.processing_priority,
p_standard_link_flag => ele_type.standard_link_flag,
-- 'N''
--Should always 'N'-- x.standard_link_flag,
p_comments => NULL,
p_third_party_pay_only_flag =>
ele_type.third_party_pay_only_flag,
p_iterative_flag => ele_type.iterative_flag,
p_iterative_formula_id => NULL,
p_iterative_priority => ele_type.iterative_priority,
p_creator_type => ele_type.creator_type,
p_retro_summ_ele_id => NULL,
--x.retro_summ_ele_id, --*****
p_grossup_flag => ele_type.grossup_flag,
p_process_mode => ele_type.process_mode,
p_advance_indicator => ele_type.advance_indicator,
p_advance_payable => ele_type.advance_payable,
p_advance_deduction => ele_type.advance_deduction,
p_process_advance_entry =>
ele_type.process_advance_entry,
p_proration_group_id => NULL,
p_proration_formula_id => NULL,
p_recalc_event_group_id => l_event_group_id,
--x.recalc_event_group_id,
--*****
p_legislation_subgroup =>
ele_type.legislation_subgroup,
--*****
p_qualifying_age => ele_type.qualifying_age,
p_qualifying_length_of_service =>
ele_type.qualifying_length_of_service,
p_qualifying_units => ele_type.qualifying_units,
p_attribute_category => ele_type.attribute_category,
--*****
p_attribute1 => ele_type.attribute1,
p_attribute2 => ele_type.attribute2,
p_attribute3 => ele_type.attribute3,
p_attribute4 => ele_type.attribute4,
p_attribute5 => ele_type.attribute5,
p_attribute6 => ele_type.attribute6,
p_attribute7 => ele_type.attribute7,
p_attribute8 => ele_type.attribute8,
p_attribute9 => ele_type.attribute9,
p_attribute10 => ele_type.attribute10,
p_attribute11 => ele_type.attribute11,
p_attribute12 => ele_type.attribute12,
p_attribute13 => ele_type.attribute13,
p_attribute14 => ele_type.attribute14,
p_attribute15 => ele_type.attribute15,
p_attribute16 => ele_type.attribute16,
p_attribute17 => ele_type.attribute17,
p_attribute18 => ele_type.attribute18,
p_attribute19 => ele_type.attribute19,
p_attribute20 => ele_type.attribute20,
p_element_information_category =>
ele_type.element_information_category,
p_element_information1 =>
ele_type.element_information1,
p_element_information2 =>
ele_type.element_information1,
p_element_information3 =>
ele_type.element_information3,
p_element_information4 =>
ele_type.element_information4,
p_element_information5 =>
ele_type.element_information5,
p_element_information6 =>
ele_type.element_information6,
p_element_information7 =>
ele_type.element_information7,
p_element_information8 =>
ele_type.element_information8,
p_element_information9 =>
ele_type.element_information9,
p_element_information10 =>
ele_type.element_information10,
p_element_information11 =>
ele_type.element_information11,
p_element_information12 =>
ele_type.element_information12,
p_element_information13 =>
ele_type.element_information13,
p_element_information14 =>
ele_type.element_information14,
p_element_information15 =>
ele_type.element_information15,
p_element_information16 =>
ele_type.element_information16,
p_element_information17 =>
ele_type.element_information17,
p_element_information18 =>
ele_type.element_information18,
p_element_information19 =>
ele_type.element_information19,
p_element_information20 =>
ele_type.element_information20,
p_default_uom => NULL,
p_once_each_period_flag => NVL

(ele_type.once_each_period_flag,
'N'
),
p_language_code => NULL,
p_time_definition_type => NULL,
p_time_definition_id => NULL,
p_element_type_id => l_element_type_id,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date,
p_object_version_number => l_object_version_number,
p_comment_id => l_comment_id,
p_processing_priority_warning =>
l_processing_priority_warning
);
l_debug_msg :=
'3'
|| TO_CHAR (l_element_type_id)
|| ' # '
|| ele_type.element_name;

UPDATE BTC_pay_element_types_t
SET process_flag = 'Y'
WHERE process_flag IS NULL AND ROWID = ele_type.ROWID;

l_debug_msg := '4' || 'Done';


COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 3999);

INSERT INTO BTC_pay_element_types_err_t


VALUES (ele_type.element_type_id, l_debug_msg,
l_error_msg);

UPDATE BTC_pay_element_types_t
SET process_flag = 'E'
WHERE process_flag IS NULL AND ROWID = ele_type.ROWID;

COMMIT;
DBMS_OUTPUT.put_line
( 'Error Message while Creating Element Type: '
|| l_error_msg
);
END;
END LOOP;
END create_element_type_api;
PROCEDURE create_input_values_api
AS
l_input_value_id apps.pay_input_values_f.input_value_id%TYPE;
l_object_version_number apps.pay_input_values_f.object_version_number%TYPE;
l_effective_start_date apps.pay_input_values_f.effective_start_date%TYPE;
l_effective_end_date apps.pay_input_values_f.effective_end_date%TYPE;
l_default_val_warning BOOLEAN;
l_min_max_warning BOOLEAN;
l_pay_basis_warning BOOLEAN;
l_formula_warning BOOLEAN;
l_assignment_id_warning BOOLEAN;
l_formula_message VARCHAR2 (1000);
l_error_msg VARCHAR2 (4000);
l_element_type_id apps.pay_element_types_f.element_type_id%TYPE;
l_uom VARCHAR2 (100) := NULL;
l_debug_msg VARCHAR2 (100);

CURSOR pay_input_values
IS
SELECT ROWID, bb.*
FROM BTC_pay_input_values_t bb
WHERE bb.process_flag IS NULL
-- AND bb.ELEMENT_name='Business Leave
Allowance AAH'
;
BEGIN
FOR y IN pay_input_values
LOOP
BEGIN
l_debug_msg := '';

/* fetching element type id*/


SELECT pet.element_type_id
INTO l_element_type_id
FROM pay_element_types_f pet
WHERE pet.business_group_id = y.business_group_id
AND UPPER (pet.element_name) = (TRIM (UPPER (y.element_name)));

l_debug_msg :=
'1' || ' ' || y.element_name || ' '
|| TO_CHAR (l_element_type_id);
pay_input_value_api.create_input_value
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_element_type_id => l_element_type_id,
p_name => y.NAME,
p_uom => y.uom,
p_lookup_type => y.lookup_type,
p_formula_id => NULL,
p_value_set_id => y.value_set_id,
p_display_sequence => y.display_sequence,
p_generate_db_items_flag => y.generate_db_items_flag,
p_hot_default_flag => y.hot_default_flag,
p_mandatory_flag => y.mandatory_flag,
p_default_value => y.DEFAULT_VALUE,
p_max_value => y.max_value,
p_min_value => y.min_value,
p_warning_or_error => y.warning_or_error,
p_input_value_id => l_input_value_id,
p_object_version_number => l_object_version_number,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date,
p_default_val_warning => l_default_val_warning,
p_min_max_warning => l_min_max_warning,
p_pay_basis_warning => l_pay_basis_warning,
p_formula_warning => l_formula_warning,
p_assignment_id_warning => l_assignment_id_warning,
p_formula_message => l_formula_message
);

UPDATE BTC_pay_input_values_t
SET process_flag = 'Y'
WHERE process_flag IS NULL AND ROWID = y.ROWID;

l_debug_msg := '2' || 'Done';


COMMIT;
DBMS_OUTPUT.put_line ( 'Input Values: '
|| y.NAME
|| ': Created for element :'
|| y.element_name
|| ': With Input Value ID :'
|| l_input_value_id
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 3999);

INSERT INTO BTC_pay_input_values_err_t


VALUES (y.element_type_id, y.input_value_id, l_debug_msg,
l_error_msg);

UPDATE BTC_pay_input_values_t
SET process_flag = 'E'
WHERE process_flag IS NULL AND ROWID = y.ROWID;

DBMS_OUTPUT.put_line
( 'Error Message while Creating Input Values: '
|| l_error_msg
);
END;
END LOOP;
/*Insert Query:

insert into BTC_pay_input_values


select *
from BTC_pay_input_values_v
where business_group_id = 82
and element_type_id in (393, 692, 384, 693)

*/
END create_input_values_api;

PROCEDURE create_balance_feeds_api
AS
l_balance_feed_id apps.pay_balance_feeds_f.balance_feed_id%TYPE;
l_effective_start_date apps.pay_balance_feeds_f.effective_start_date
%TYPE;
l_effective_end_date apps.pay_balance_feeds_f.effective_end_date
%TYPE;
l_exist_run_result_warning BOOLEAN;
l_object_version_number apps.pay_balance_feeds_f.object_version_number
%TYPE;
l_balance_type_id apps.pay_balance_types.balance_type_id%TYPE;
l_element_type_id apps.pay_element_types_f.element_type_id%TYPE;
l_input_value_id apps.pay_input_values.input_value_id%TYPE;
l_error_msg VARCHAR2 (4000);

CURSOR c_pay_balance_feeds
IS
SELECT ROWID, cc.*
FROM BTC_pay_balance_feeds_t cc
WHERE cc.process_flag IS NULL
-- and cc.balance_name='Administrative
Duties Overpayment Recovered Amount'
;
BEGIN
FOR x IN c_pay_balance_feeds
LOOP
BEGIN
SELECT bt.balance_type_id
INTO l_balance_type_id
FROM pay_balance_types bt
WHERE bt.balance_name = x.balance_name
AND bt.business_group_id = x.business_group_id;

SELECT pet.element_type_id, piv.input_value_id


INTO l_element_type_id, l_input_value_id
FROM pay_element_types_f pet, pay_input_values_f piv
WHERE pet.element_type_id = piv.element_type_id
AND pet.business_group_id = piv.business_group_id
AND g_effective_date BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND g_effective_date BETWEEN piv.effective_start_date
AND piv.effective_end_date
AND pet.element_name = x.element_name
AND piv.NAME = x.iv_name
AND pet.business_group_id = x.business_group_id;

DBMS_OUTPUT.put_line
( 'Preparing Balance Feed Parameter for Balance : '
|| x.balance_name
|| ': Element:'
|| x.element_name
|| ': with input value Id :'
|| l_input_value_id
|| ' :and Balance Type: '
|| l_balance_type_id
);
pay_balance_feeds_api.create_balance_feed
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_balance_type_id => l_balance_type_id
--*****
,
p_input_value_id => l_input_value_id
--*****
,
p_scale => x.scale,
p_business_group_id => x.business_group_id,
p_legislation_code => x.legislation_code,
p_legislation_subgroup => x.legislation_subgroup,
p_initial_feed => FALSE,
p_balance_feed_id => l_balance_feed_id,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date,
p_object_version_number => l_object_version_number,
p_exist_run_result_warning => l_exist_run_result_warning
);

UPDATE BTC_pay_balance_feeds_t
SET process_flag = 'Y'
WHERE process_flag IS NULL AND ROWID = x.ROWID;

--and input_value_id = x.input_value_id;


COMMIT;
DBMS_OUTPUT.put_line
( 'Creating Balance Feed For input value : '
|| l_input_value_id
|| ' :with Balance Type: '
|| l_balance_type_id
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 1999);

INSERT INTO BTC_pay_balace_feeds_err_t


VALUES (x.balance_name, x.element_name, x.iv_name,
x.input_value_id, l_error_msg);

UPDATE BTC_pay_balance_feeds_t
SET process_flag = 'E'
WHERE process_flag IS NULL AND ROWID = x.ROWID;

--and input_value_id = x.input_value_id;


COMMIT;
DBMS_OUTPUT.put_line
( 'Error Message while Creating Balance Feed: '
|| l_error_msg
);
END;
END LOOP;
/*
insert into BTC_pay_balance_feeds
(select v.* , null from BTC_pay_balance_feeds_api_v v
where balance_name='Basic Salary Overpaid Total Amount'
and business_group_id = 82)

*/
END create_balance_feeds_api;

PROCEDURE create_defined_bal_dim_api
AS
l_balance_type_id apps.pay_balance_types.balance_type_id%TYPE;
l_balance_dimension_id apps.pay_defined_balances.balance_dimension_id%TYPE;
l_error_msg VARCHAR2 (2000);

CURSOR c_bal_def
IS
SELECT ROWID, balance_name, dimension_name,
pay_defined_balances_s.NEXTVAL defined_balance_id,
business_group_id, legislation_code, balance_type_id,
balance_dimension_id, force_latest_balance_flag,
legislation_subgroup, last_update_date, last_updated_by,
last_update_login, created_by, creation_date,
object_version_number, grossup_allowed_flag,
save_run_balance, run_balance_status
FROM BTC_pay_balance_defined_t
WHERE process_flag IS NULL
-- and balance_name = 'Employee Referral
Overpaid Total Amount'
;
BEGIN
FOR x IN c_bal_def
LOOP
l_balance_type_id := 0;

BEGIN
SELECT balance_type_id
INTO l_balance_type_id
FROM pay_balance_types
WHERE balance_name = x.balance_name
AND business_group_id = x.business_group_id;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SQLERRM;
END;

BEGIN
SELECT pbd.balance_dimension_id
INTO l_balance_dimension_id
FROM pay_balance_dimensions pbd
WHERE pbd.dimension_name = x.dimension_name
AND pbd.legislation_code = 'AE';
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SQLERRM;
END;

DBMS_OUTPUT.put_line ( 'Uploading Defined Balances: '


|| ': For Balance :'
|| x.balance_name
|| ': Dimension Name:'
|| x.dimension_name
|| ':with balance type id:'
|| l_balance_type_id
|| ': And balance Dimension Id :'
|| l_balance_dimension_id
);
BEGIN
INSERT INTO pay_defined_balances
(defined_balance_id, business_group_id,
legislation_code, balance_type_id,
balance_dimension_id,
force_latest_balance_flag,
legislation_subgroup, last_update_date,
last_updated_by, last_update_login,
created_by, creation_date,
object_version_number, grossup_allowed_flag,
save_run_balance, run_balance_status
)
VALUES (x.defined_balance_id, x.business_group_id,
x.legislation_code, l_balance_type_id,
l_balance_dimension_id,
x.force_latest_balance_flag,
x.legislation_subgroup, x.last_update_date,
x.last_updated_by, x.last_update_login,
x.created_by, x.creation_date,
x.object_version_number, x.grossup_allowed_flag,
x.save_run_balance, x.run_balance_status
);

UPDATE BTC_pay_balance_defined_t
SET process_flag = 'Y'
WHERE ROWID = x.ROWID;

--dbms_output.put_line(x.balance_type_id ||' '||x.defined_balance_id);


COMMIT;
EXCEPTION
WHEN OTHERS
THEN
UPDATE BTC_pay_balance_defined_t
SET process_flag = 'E'
WHERE ROWID = x.ROWID;

l_error_msg := SUBSTR (SQLERRM, 1, 1999);

INSERT INTO BTC_pay_balance_defined_err_t


VALUES (x.balance_name, x.dimension_name, l_error_msg);

COMMIT;
DBMS_OUTPUT.put_line
( 'Error Message while uploading Defined Balances: '
|| l_error_msg
);
END;
END LOOP;
END create_defined_bal_dim_api;

PROCEDURE create_formula_results_api
AS
/*(A) for Process Rules */
l_status_processing_rule_id
apps.pay_status_processing_rules_f.status_processing_rule_id%TYPE;
l_effective_start_date
apps.pay_status_processing_rules_f.effective_start_date%TYPE;
l_effective_end_date
apps.pay_status_processing_rules_f.effective_end_date%TYPE;
l_object_version_number
apps.pay_status_processing_rules_f.object_version_number%TYPE;
l_formula_mismatch_warning BOOLEAN;
l_element_type_id apps.pay_element_types_f.element_type_id
%TYPE;
l_formula_id apps.ff_formulas.formula_id%TYPE;
l_error_msg VARCHAR2 (2000);
/*End(A) */

/*(B)For Formula Results */


l_formula_result_rule_id
apps.pay_formula_result_rules_f.formula_result_rule_id%TYPE;
l_rr_effective_start_date
apps.pay_formula_result_rules_f.effective_start_date%TYPE;
l_rr_effective_end_date
apps.pay_formula_result_rules_f.effective_end_date%TYPE;
l_rr_object_version_number
apps.pay_formula_result_rules_f.object_version_number%TYPE;
l_child_element_id apps.pay_element_types_f.element_type_id
%TYPE;
l_input_value_id apps.pay_input_values_f.input_value_id%TYPE;
l_rr_status_processing_rule_id
apps.pay_formula_result_rules_f.status_processing_rule_id%TYPE;
l_rr_message VARCHAR2 (2000);

/*End(B) */
CURSOR c_process_rules
IS
SELECT ROWID, a.*
FROM BTC_pay_formula_rules_t a
WHERE process_flag IS NULL
-- AND ELEMENT_NAME = 'New Hire Mobilization
AAH'
;

CURSOR c_run_results
IS
SELECT ROWID, b.*
FROM BTC_pay_ff_results_t b
WHERE process_flag IS NULL
-- and parent_element ='New Hire Mobilization
AAH'

;
BEGIN
/* Start >>>>> For Formula Process Rules <<<<< */
FOR x IN c_process_rules
LOOP
BEGIN
l_element_type_id := 0;
l_formula_id := 0;

SELECT pet.element_type_id
INTO l_element_type_id
FROM pay_element_types_f pet
WHERE element_name = x.element_name
AND g_effective_date BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND pet.business_group_id = x.business_group_id;

SELECT ff.formula_id
INTO l_formula_id
FROM ff_formulas_f ff
WHERE ff.formula_name = x.formula_name
AND g_effective_date BETWEEN ff.effective_start_date
AND ff.effective_end_date
AND ff.business_group_id = x.business_group_id;

DBMS_OUTPUT.put_line
( 'Creating Status Process Rule Api for Element : '
|| x.element_name
|| ': having formula : '
|| x.formula_name
|| ': with element type Id :'
|| l_element_type_id
|| ': and formula id :'
|| l_formula_id
);
pay_status_processing_rule_api.create_status_process_rule
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_element_type_id => l_element_type_id,
p_business_group_id => x.business_group_id,
p_legislation_code => x.legislation_code,
p_assignment_status_type_id => NULL,
p_formula_id => l_formula_id,
p_comments => NULL,
p_legislation_subgroup => NULL,
p_status_processing_rule_id => l_status_processing_rule_id,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date,
p_object_version_number => l_object_version_number,
p_formula_mismatch_warning => l_formula_mismatch_warning
);

UPDATE BTC_pay_formula_rules_t
SET process_flag = 'Y'
WHERE ROWID = x.ROWID;

COMMIT;
DBMS_OUTPUT.put_line
( ' Status Process Rule Api for Element Created for element : '
|| x.element_name
|| ': with status process rule id : '
|| l_status_processing_rule_id
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 1999);

INSERT INTO BTC_pay_formula_rules_err_t


VALUES (x.element_name, x.formula_name,
l_error_msg
|| ' '
|| l_element_type_id
|| ' '
|| l_formula_id
|| ' '
|| x.element_name);

UPDATE BTC_pay_formula_rules_t
SET process_flag = 'E'
WHERE ROWID = x.ROWID;

COMMIT;
DBMS_OUTPUT.put_line
( 'Error Message while creating Status Process Rule Api: '
|| l_error_msg
);
END;
END LOOP;

/* End >>>>> For Formula Process Rules <<<<< */

/* Start >>>>> For Formula Run Results <<<<< */


FOR r IN c_run_results
LOOP
BEGIN
l_child_element_id := NULL;
l_input_value_id := NULL;

BEGIN
SELECT pet.element_type_id, piv.input_value_id
INTO l_child_element_id, l_input_value_id
FROM pay_element_types_f pet, pay_input_values_f piv
WHERE pet.element_type_id = piv.element_type_id
AND pet.business_group_id = piv.business_group_id
AND g_effective_date BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND g_effective_date BETWEEN piv.effective_start_date
AND piv.effective_end_date
AND pet.element_name = r.child_element
AND piv.NAME = r.input_value_name
AND pet.business_group_id = r.business_group_id;
EXCEPTION
WHEN OTHERS
THEN
l_child_element_id := NULL;
l_input_value_id := NULL;
END;

BEGIN
SELECT spr.status_processing_rule_id
INTO l_rr_status_processing_rule_id
FROM pay_status_processing_rules_f spr,
ff_formulas_f ff,
pay_element_types_f pet
WHERE spr.business_group_id = ff.business_group_id
AND spr.formula_id = ff.formula_id
AND pet.element_type_id = spr.element_type_id
AND pet.business_group_id = spr.business_group_id
AND g_effective_date BETWEEN spr.effective_start_date
AND spr.effective_end_date
AND g_effective_date BETWEEN ff.effective_start_date
AND ff.effective_end_date
AND g_effective_date BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND pet.element_name = r.parent_element
AND pet.business_group_id = r.business_group_id;
EXCEPTION
WHEN OTHERS
THEN
l_rr_message := l_rr_message || 'Err: ' || SQLERRM;
END;

l_error_msg :=
r.result_name
|| ' '
|| r.result_rule_type
|| ' '
|| r.business_group_id
|| ' '
|| r.legislation_code
|| ' '
|| r.severity_level
|| ' '
|| l_child_element_id
|| ' '
|| l_input_value_id;
DBMS_OUTPUT.put_line ( 'Formula Result Rule Api for result: '
|| r.result_name
|| 'For element'
|| r.child_element
|| ': with element id:'
|| l_child_element_id
|| ': and input value ID :'
|| l_input_value_id
|| ': Process rule Id :'
|| l_rr_status_processing_rule_id
);
pay_formula_result_rule_api.create_formula_result_rule
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_status_processing_rule_id => l_rr_status_processing_rule_id,
--**
p_result_name => r.result_name,
p_result_rule_type => r.result_rule_type,
p_business_group_id => r.business_group_id,
--**
p_legislation_code => r.legislation_code,
p_element_type_id => l_child_element_id,
--**
p_legislation_subgroup => r.legislation_subgroup,
p_severity_level => r.severity_level, --**
p_input_value_id => l_input_value_id, --**
p_formula_result_rule_id => l_formula_result_rule_id,
p_effective_start_date => l_rr_effective_start_date,
p_effective_end_date => l_rr_effective_end_date,
p_object_version_number => l_rr_object_version_number
);

UPDATE BTC_pay_ff_results_t
SET process_flag = 'Y'
WHERE ROWID = r.ROWID;
-- and status_processing_rule_id = r.status_processing_rule_id;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_rr_message := SUBSTR (SQLERRM || l_error_msg, 1, 1999);

INSERT INTO BTC_pay_ff_results_err_t


VALUES (r.parent_element, r.child_element,
l_rr_status_processing_rule_id, l_rr_message);

UPDATE BTC_pay_ff_results_t
SET process_flag = 'E'
WHERE ROWID = r.ROWID;

--and status_processing_rule_id = r.status_processing_rule_id;


COMMIT;
DBMS_OUTPUT.put_line
( 'Error Message for Formula Result Rule Api : '
|| l_rr_message
);
END;
END LOOP;
/* End >>>>> For Formula Run Results <<<<< */

/* Insert Statements :

>>>For Formula Process :


insert into BTC_formula_process_rules
(select v.*, ' ' process_flag
from BTC_formula_process_rules_v v where v.business_group_id = 82
and v.element_type_id = 1032)

>>>For Run Results :


insert into BTC_ff_result_rules
(select v.*,null process_flag
from BTC_ff_result_rules_v v
where business_group_id = 82
and parent_element = 'Mobile Over Payment Recovery TWM')

*/
END create_formula_results_api;

PROCEDURE create_element_link_api
AS
l_element_link_id apps.pay_element_links_f.element_link_id%TYPE;
l_comment_id apps.pay_element_links_f.comment_id%TYPE;
l_object_version_number apps.pay_element_links_f.object_version_number%TYPE
:= 1;
l_effective_start_date apps.pay_element_links_f.effective_start_date%TYPE;
l_effective_end_date apps.pay_element_links_f.effective_end_date%TYPE;
l_element_type_id apps.pay_element_types_f.element_type_id%TYPE;
l_standard_flag VARCHAR2 (3);
l_error_msg VARCHAR2 (2000);
--Costing Variables
l_element_name VARCHAR2 (500);
l_costing_flag VARCHAR2 (10);
l_cost_segment1 VARCHAR2 (20);
l_cost_segment2 VARCHAR2 (20);
l_cost_segment3 VARCHAR2 (20);
l_cost_segment4 VARCHAR2 (20);
l_cost_segment5 VARCHAR2 (20);
l_cost_segment6 VARCHAR2 (20);
l_cost_segment7 VARCHAR2 (20);
l_bal_segment1 VARCHAR2 (20);
l_bal_segment2 VARCHAR2 (20);
l_bal_segment3 VARCHAR2 (20);
l_bal_segment4 VARCHAR2 (20);
l_bal_segment5 VARCHAR2 (20);
l_bal_segment6 VARCHAR2 (20);
l_bal_segment7 VARCHAR2 (20);

CURSOR c_element_links
IS
SELECT ROWID, ach.*
FROM BTC_pay_element_links_t ach
WHERE 1 = 1
and process_flag IS NULL
-- and ach.element_name='Business Leave Allowance AAH'
--and ach.FACILITY='Y';
;
BEGIN
FOR x IN c_element_links
LOOP
l_element_type_id := NULL;
l_standard_flag := NULL;

BEGIN
SELECT pet.element_type_id
INTOl_element_type_id
FROMpay_element_types_f pet
WHERE g_effective_date BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND pet.business_group_id = x.business_group_id
AND pet.element_name = x.element_name;

SELECT pet.standard_link_flag
INTO l_standard_flag
FROM pay_element_types_f pet
WHERE g_effective_date BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND pet.business_group_id = x.business_group_id
AND pet.element_name = x.element_name;

DBMS_OUTPUT.put_line ( 'Element Link Api for Element : '


|| x.element_name
|| ' :with elemtn type id :'
|| l_element_type_id
|| ': and standard flag is :'
|| l_standard_flag
);

--Costing Information
BEGIN
SELECT cst.element_name, costing_flag,
costing_1, costing_2,
costing_3, costing_4, costing_5,
costing_6, costing_7,
balance_1, balance_2,
balance_3, balance_4, balance_5,
balance_6, balance_7
INTO l_element_name, l_costing_flag,
l_cost_segment1, l_cost_segment2,
l_cost_segment3, l_cost_segment4, l_cost_segment5,
l_cost_segment6, l_cost_segment7,
l_bal_segment1, l_bal_segment2,
l_bal_segment3, l_bal_segment4, l_bal_segment5,
l_bal_segment6, l_bal_segment7
FROM pay_element_types_f pet,
BTC_api_element_link_cost_t cst
WHERE pet.business_group_id = x.business_group_id
AND pet.element_type_id = l_element_type_id
AND TRUNC (g_effective_date) BETWEEN pet.effective_start_date
AND pet.effective_end_date
AND UPPER (pet.element_name) = UPPER (cst.element_name)
AND pet.business_group_id = cst.business_group_id
AND cst.process_flag IS NULL;
EXCEPTION
WHEN OTHERS
THEN
l_costing_flag := 'N';
l_cost_segment1 := NULL;
l_cost_segment2 := NULL;
l_cost_segment3 := NULL;
l_cost_segment4 := NULL;
l_cost_segment5 := NULL;
l_cost_segment6 := NULL;
l_cost_segment7 := NULL;
l_bal_segment1 := NULL;
l_bal_segment2 := NULL;
l_bal_segment3 := NULL;
l_bal_segment4 := NULL;
l_bal_segment5 := NULL;
l_bal_segment6 := NULL;
l_bal_segment7 := NULL;
END;

DBMS_OUTPUT.put_line ( 'Element Link Api for Element : '


|| x.element_name
|| ' :with elemtn type id :'
|| l_element_type_id
|| ': and costing flag is :'
|| l_costing_flag
|| ':with segment details:'
|| l_cost_segment1
|| ':'
|| l_cost_segment2
|| ':'
|| l_cost_segment3
|| ':'
|| l_cost_segment4
|| ':'
|| l_cost_segment5
|| ':'
|| l_cost_segment6
|| ':'
|| l_cost_segment7
);
pay_element_link_api.create_element_link
(p_validate => FALSE,
p_effective_date => g_effective_date,
p_element_type_id => l_element_type_id,
p_business_group_id => x.business_group_id,
p_costable_type => l_costing_flag,
p_payroll_id => x.payroll_id,
p_job_id => x.job_id,
p_position_id => x.position_id,
p_people_group_id => x.people_group_id,
p_cost_allocation_keyflex_id => NULL, --Costing
p_organization_id => x.organization_id,
p_location_id => x.location_id,
p_grade_id => x.grade_id,
p_balancing_keyflex_id => NULL, --Costing
p_element_set_id => NULL,
--x.element_set_id,
p_pay_basis_id => x.pay_basis_id,
p_link_to_all_payrolls_flag =>
x.link_to_all_payrolls_flag,
p_standard_link_flag => x.standard_link_flag,
--Dont Change ; Should be 'N' ******
p_transfer_to_gl_flag => x.transfer_to_gl_flag,
--x.transfer_to_gl_flag,
p_comments => NULL, --****
p_employment_category => x.employment_category,
p_qualifying_age => NULL,
--x.qualifying_age,
p_qualifying_length_of_service => NULL,
--x.qualifying_length_of_service,
p_qualifying_units => NULL,
--x.qualifying_units,
p_attribute_category => NULL,
--x.attribute_category,
p_attribute1 => NULL,
p_attribute2 => NULL,
p_attribute3 => NULL,
p_attribute4 => NULL,
p_attribute5 => NULL,
p_attribute6 => NULL,
p_attribute7 => NULL,
p_attribute8 => NULL,
p_attribute9 => NULL,
p_attribute10 => NULL,
p_attribute11 => NULL,
p_attribute12 => NULL,
p_attribute13 => NULL,
p_attribute14 => NULL,
p_attribute15 => NULL,
p_attribute16 => NULL,
p_attribute17 => NULL,
p_attribute18 => NULL,
p_attribute19 => NULL,
p_attribute20 => NULL,
p_cost_segment1 => l_cost_segment1,
p_cost_segment2 => l_cost_segment2,
p_cost_segment3 => l_cost_segment3,
p_cost_segment4 => l_cost_segment4,
p_cost_segment5 => l_cost_segment5,
p_cost_segment6 => l_cost_segment6,
p_cost_segment7 => l_cost_segment7,
p_cost_segment8 => NULL,
p_cost_segment9 => NULL,
p_cost_segment10 => NULL,
p_cost_segment11 => NULL,
p_cost_segment12 => NULL,
p_cost_segment13 => NULL,
p_cost_segment14 => NULL,
p_cost_segment15 => NULL,
p_cost_segment16 => NULL,
p_cost_segment17 => NULL,
p_cost_segment18 => NULL,
p_cost_segment19 => NULL,
p_cost_segment20 => NULL,
p_cost_segment21 => NULL,
p_cost_segment22 => NULL,
p_cost_segment23 => NULL,
p_cost_segment24 => NULL,
p_cost_segment25 => NULL,
p_cost_segment26 => NULL,
p_cost_segment27 => NULL,
p_cost_segment28 => NULL,
p_cost_segment29 => NULL,
p_cost_segment30 => NULL,
p_balance_segment1 => l_bal_segment1,
p_balance_segment2 => l_bal_segment2,
p_balance_segment3 => l_bal_segment3,
p_balance_segment4 => l_bal_segment4,
p_balance_segment5 => l_bal_segment5,
p_balance_segment6 => l_bal_segment6,
p_balance_segment7 => l_bal_segment7,
p_balance_segment8 => NULL,
p_balance_segment9 => NULL,
p_balance_segment10 => NULL,
p_balance_segment11 => NULL,
p_balance_segment12 => NULL,
p_balance_segment13 => NULL,
p_balance_segment14 => NULL,
p_balance_segment15 => NULL,
p_balance_segment16 => NULL,
p_balance_segment17 => NULL,
p_balance_segment18 => NULL,
p_balance_segment19 => NULL,
p_balance_segment20 => NULL,
p_balance_segment21 => NULL,
p_balance_segment22 => NULL,
p_balance_segment23 => NULL,
p_balance_segment24 => NULL,
p_balance_segment25 => NULL,
p_balance_segment26 => NULL,
p_balance_segment27 => NULL,
p_balance_segment28 => NULL,
p_balance_segment29 => NULL,
p_balance_segment30 => NULL,
p_cost_concat_segments => NULL,
p_balance_concat_segments => NULL,
p_element_link_id => l_element_link_id,
p_comment_id => l_comment_id,
p_object_version_number => l_object_version_number,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date
);

UPDATE BTC_pay_element_links_t
SET process_flag = 'Y',
element_link_id = l_element_link_id
WHERE ROWID = x.ROWID;

UPDATE BTC_api_element_link_cost_t
SET process_flag = 'Y',
process_date = SYSDATE
WHERE element_name = l_element_name;

COMMIT;
DBMS_OUTPUT.put_line ( 'Element Link Created for Element : '
|| x.element_name
|| ' :with elemtn element link id :'
|| l_element_link_id
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 1999);

UPDATE BTC_pay_element_links_t
SET process_flag = 'E'
WHERE ROWID = x.ROWID;

INSERT INTO BTC_pay_element_links_err_t


VALUES (x.element_name, x.element_link_id, l_error_msg);

UPDATE BTC_api_element_link_cost_t
SET process_flag = 'E',
error_message = SUBSTR (l_error_msg, 1, 3999)
WHERE element_name = l_element_name;

COMMIT;
DBMS_OUTPUT.put_line ( 'Element Link Created for Element : '
|| l_error_msg
);
END;
END LOOP;
/*

insert into BTC_pay_element_links


(select *
from BTC_pay_element_links_v
where business_group_id = 82
and element_name = 'Mobile Allowance Leave Deduction Retro TWM')

*/
END create_element_link_api;

PROCEDURE compile_formula
IS
CURSOR ff_compile
IS
SELECT fft.formula_type_name, spft.new_formula_name
FROM BTC_pay_formulas_t spft, ff_formula_types fft
WHERE spft.formula_type_id = fft.formula_type_id;

l_request_id NUMBER;
l_retval BOOLEAN;
l_interval NUMBER := 05;
l_max_wait NUMBER;
l_phase VARCHAR2 (200);
l_status VARCHAR2 (200);
l_dev_phase VARCHAR2 (200);
l_dev_status VARCHAR2 (200);
l_message VARCHAR2 (200);
BEGIN
fnd_global.apps_initialize (g_user_id, g_resp_id, g_resp_appl_id);

FOR i IN ff_compile
LOOP
DBMS_OUTPUT.put_line ( 'Formula Type :'
|| i.formula_type_name
|| ' Formula Name :'
|| i.new_formula_name
);
l_request_id :=
fnd_request.submit_request
(application => 'FF',
program => 'SINGLECOMPILE',
description => 'Compile a single formula',
start_time => TRUNC (SYSDATE),
sub_request => FALSE,
argument1 => i.formula_type_name,
argument2 => i.new_formula_name
);
COMMIT;
l_retval :=
apps.fnd_concurrent.wait_for_request (l_request_id,
l_interval,
l_max_wait,
l_phase,
l_status,
l_dev_phase,
l_dev_status,
l_message
);
COMMIT;

IF l_retval = TRUE
THEN
DBMS_OUTPUT.put_line ( 'FORMULA COMPLILE REQUEST COMPLETED : '
|| l_request_id
);
ELSE
DBMS_OUTPUT.put_line ('WAIT FOR REQUEST FAILED - STATUS UNKNOWN');
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error in compile Fast formula : ' || SQLERRM);
END;

PROCEDURE run_apis
IS
CURSOR cur_err
IS
SELECT 'Create function ' error_in, fun.MESSAGE error_message
FROM BTC_pay_function_upload_err_t fun
UNION ALL
SELECT 'Create Function context Parameter ', contx.MESSAGE
FROM BTC_pay_contex_param_err_t contx
UNION ALL
SELECT 'Create function Parameter', parm.v_message
FROM BTC_pay_function_param_err_t parm
UNION ALL
SELECT 'Create Balance Type ', bal.MESSAGE
FROM BTC_pay_balance_type_err_t bal
UNION ALL
SELECT 'Create Balance Defined ', bal_defin.MESSAGE
FROM BTC_pay_balance_defined_err_t bal_defin
UNION ALL
SELECT 'Create Element Type ', ele.err_message
FROM BTC_pay_element_types_err_t ele
UNION ALL
SELECT 'Create Element Input Value ', ele_inp.err_message
FROM BTC_pay_input_values_err_t ele_inp
UNION ALL
SELECT 'Create Balance Input feed', bal_feed.MESSAGE
FROM BTC_pay_balace_feeds_err_t bal_feed
UNION ALL
SELECT 'Create Fast formula ', ff.ERROR_CODE
FROM BTC_pay_formulas_err_t ff
UNION ALL
SELECT 'Create Fast formula Rules ', ff_rule.MESSAGE
FROM BTC_pay_formula_rules_err_t ff_rule
UNION ALL
SELECT 'Create Fast Formula Results ', ff_result.MESSAGE
FROM BTC_pay_ff_results_err_t ff_result
UNION ALL
SELECT 'Create Element Link ', ele_link.MESSAGE
FROM BTC_pay_element_links_err_t ele_link;
BEGIN
DBMS_OUTPUT.put_line ( 'GLOBAL VARIABLE : '
|| g_business_group_id
|| ' '
|| g_effective_date
|| ' '
|| g_resp_id
);
fnd_global.apps_initialize (g_user_id, g_resp_id, g_resp_appl_id);
create_function_api;
create_context_param_api;
create_func_parameter_api;
create_balance_type_api;
create_defined_bal_dim_api;
create_element_type_api;
create_input_values_api;
create_balance_feeds_api;
create_formula_api;
compile_formula;
create_formula_results_api;
create_element_link_api;
BEGIN
FOR i IN cur_err
LOOP
DBMS_OUTPUT.put_line (i.error_in || '=====> ' || i.error_message);
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Other Error :====>' || SQLERRM);
END;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Others Error :' || SQLERRM);
END;

PROCEDURE BTC_delete_element_link_p (
p_business_group_id IN apps.pay_element_types_f.business_group_id%TYPE,
p_element_name IN apps.pay_element_types_f.element_name%TYPE,
p_effective_date IN DATE
)
IS
l_effective_start_date apps.pay_element_links_f.effective_start_date%TYPE;
l_effective_end_date apps.pay_element_links_f.effective_end_date%TYPE;
l_entries_warning BOOLEAN;
l_error_msg VARCHAR2 (2000);

CURSOR all_links
IS
SELECT pet.business_group_id, pel.element_link_id,
pel.object_version_number, pet.element_type_id,
pet.element_name
FROM apps.pay_element_links_f pel, apps.pay_element_types_f pet
WHERE pel.element_type_id = pet.element_type_id
AND pet.element_name LIKE p_element_name || '%'
AND pet.business_group_id = p_business_group_id
AND p_effective_date BETWEEN pel.effective_start_date
AND pel.effective_end_date
ORDER BY pel.business_group_id;
BEGIN
FOR del_link IN all_links
LOOP
BEGIN
pay_element_link_api.delete_element_link
(p_validate => FALSE,
p_effective_date => p_effective_date,
p_element_link_id => del_link.element_link_id,
p_datetrack_delete_mode => 'DELETE',
p_object_version_number => del_link.object_version_number,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date,
p_entries_warning => l_entries_warning
);
COMMIT;
DBMS_OUTPUT.put_line ( 'Element Link Delete For Element Name :'
|| del_link.element_name
|| ' ==> Business Group ID :'
|| del_link.business_group_id
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SQLERRM;
DBMS_OUTPUT.put_line ( 'Error to delete Element Name :'
|| del_link.element_name
|| ' ==> Business Group ID :'
|| del_link.business_group_id
|| ' Error Message :'
|| l_error_msg
);
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SQLERRM;
DBMS_OUTPUT.put_line ('Others Error :' || l_error_msg);
END BTC_delete_element_link_p;

PROCEDURE BTC_end_date_p (
p_table_name IN VARCHAR2,
p_column_name IN VARCHAR2,
p_business_group_id IN NUMBER,
p_effective_date IN DATE
)
AS
--------------------------------------USER TABLE
API(CREATE)-------------------------------------------
-------------custom table structure from where data'll uploaded----------
/*
CREATE TABLE BTC_NEW_USER_TABLE_VALUE_T
(
TABLE_NAME VARCHAR2(1000 BYTE),
COLUMN_NAME VARCHAR2(1000 BYTE),
ROW_NAME VARCHAR2(1000 BYTE),
USER_VALUE VARCHAR2(1000 BYTE),
BUSINESS_GROUP_ID NUMBER(20)
)
--------------------------------------------------
*/
l_effective_start_date DATE;
l_effective_end_date DATE;
l_object_version_number NUMBER (20);
l_error_msg VARCHAR2 (2000);

CURSOR update_data
IS
SELECT tab.user_table_name user_table_name,
col.user_column_name column_name,
user_row.row_low_range_or_name row_name,
val.VALUE user_table_value,
val.effective_start_date value_start_date,
val.effective_end_date value_end_date, tab.business_group_id,
val.object_version_number, val.user_column_instance_id
FROM pay_user_tables tab,
pay_user_columns col,
pay_user_rows_f user_row,
pay_user_column_instances_f val
WHERE tab.user_table_id = col.user_table_id
AND tab.user_table_id = user_row.user_table_id
AND col.user_column_id = val.user_column_id
AND user_row.user_row_id = val.user_row_id
AND tab.user_table_name = p_table_name
AND col.user_column_name = p_column_name
AND tab.business_group_id = p_business_group_id
AND p_effective_date BETWEEN val.effective_start_date
AND val.effective_end_date;
-- and user_row.row_low_range_or_name <> 'U-A-M-01B';
BEGIN
FOR i IN update_data
LOOP
l_object_version_number := i.object_version_number;

BEGIN
pay_user_column_instance_api.delete_user_column_instance
(p_validate => FALSE,
p_effective_date => p_effective_date
--
trunc(P_EFFECTIVE_DATE)--
,
p_user_column_instance_id => i.user_column_instance_id,
p_datetrack_update_mode => 'DELETE',
p_object_version_number => l_object_version_number,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date
);
COMMIT;
DBMS_OUTPUT.put_line ( ' Delete Row of Talbe and Column:'
|| i.user_table_name
|| ' '
|| i.column_name
|| ' ==>Row Name and value :'
|| i.row_name
|| ' '
|| i.user_table_value
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line
( ' Error to delete Row of Talbe and Column:'
|| i.user_table_name
|| ' '
|| i.column_name
|| ' ==>Row Name and value :'
|| i.row_name
|| ' '
|| i.user_table_value
);
DBMS_OUTPUT.put_line (' Eror Message : === > ' || l_error_msg);
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line ( ' Others Eror Message Delete Row: === > '
|| l_error_msg
);
END BTC_end_date_p;

PROCEDURE BTC_create_user_table_api_p (
p_table_name VARCHAR2,
p_business_group_id NUMBER,
p_effective_date DATE
)
AS
l_user_table_id NUMBER;
l_object_version_number NUMBER;
l_error_msg VARCHAR2 (1000);
BEGIN
DBMS_OUTPUT.put_line (' Crate User Table API : ' || p_table_name);
pay_user_table_api.create_user_table
(
--p_validate in
boolean default false
p_effective_date => p_effective_date,
--TO_DATE('1/jan/1950','dd/mon/yyyy'),
p_business_group_id => p_business_group_id,
p_user_key_units => 'T',
p_user_table_name => p_table_name,
p_user_table_id => l_user_table_id,
p_object_version_number => l_object_version_number
);
COMMIT;
DBMS_OUTPUT.put_line (' Table Created ===>' || p_table_name);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line ( ' Error to create table :'
|| p_table_name
|| ' Message:'
|| l_error_msg
);
END BTC_create_user_table_api_p;

PROCEDURE BTC_create_user_column_api_p (
p_table_name IN VARCHAR2,
p_column_name IN VARCHAR2,
p_name_of_formula IN VARCHAR2,
p_business_group_id IN NUMBER,
p_effective_date IN DATE
)
AS
l_user_table_id NUMBER (9);
l_formula_id NUMBER (9);
l_user_column_name VARCHAR2 (80);
l_user_column_id NUMBER (9);
l_object_version_number NUMBER (9);
l_error_msg VARCHAR2 (2000);
l_count NUMBER := 0;
/* CURSOR c_user_column
IS
SELECT DISTINCT column_name
FROM BTC_new_user_table_value_t--BTC_api_pay_user_table
WHERE upper(table_name) = upper(p_table_name)
-- and row_name<>1
ORDER BY column_name;
*/
BEGIN
DBMS_OUTPUT.put_line ('Create User Table Column : ' || p_column_name);

SELECT user_table_id
INTO l_user_table_id
FROM pay_user_tables
WHERE business_group_id = p_business_group_id
AND UPPER (user_table_name) = UPPER (p_table_name);

-- BTC_USER_TAB_LOG(2.01,P_TABLE_NAME||'--PROCESS --CREATE COLUMN','-user


user_table id--'||V_user_table_id);
SELECT COUNT (*)
INTO l_count
FROM ff_formulas_f
WHERE UPPER (formula_name) = UPPER (p_name_of_formula)
AND TO_DATE (p_effective_date) BETWEEN effective_start_date
AND effective_end_date;

-- BTC_USER_TAB_LOG(2.02,P_TABLE_NAME||'--PROCESS --CREATE COLUMN','-


V_count--'||V_count);
IF l_count <> 0
THEN
SELECT formula_id
INTO l_formula_id
FROM ff_formulas_f
WHERE UPPER (formula_name) = UPPER (p_name_of_formula)
AND TO_DATE (p_effective_date) BETWEEN effective_start_date
AND effective_end_date;
ELSE
l_formula_id := NULL;
END IF;

-- BTC_USER_TAB_LOG(2.03,P_TABLE_NAME||'--PROCESS --CREATE COLUMN','-


V_formula_id--'||V_formula_id);

-- FOR user_column IN c_user_column


-- LOOP
BEGIN
pay_user_column_api.create_user_column
(p_business_group_id => p_business_group_id,
p_user_table_id => l_user_table_id,
p_formula_id => l_formula_id,
p_user_column_name => p_column_name,
p_user_column_id => l_user_column_id,
p_object_version_number => l_object_version_number
);
COMMIT;
--BTC_USER_TAB_LOG(2.04,P_TABLE_NAME||'--PROCESS --CREATE
COLUMN',user_column.column_name||'-user column id--'||l_user_column_id);
DBMS_OUTPUT.put_line ( ' Column Created Table Name :'
|| p_table_name
|| ' Column name :'
|| p_column_name
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line ( ' :'
|| p_table_name
|| ' Column name :'
|| p_column_name
);
DBMS_OUTPUT.put_line ( 'Error to create Column :'
|| p_table_name
|| ' Column name :'
|| p_column_name
|| 'Message : '
|| l_error_msg
);
END;

--END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line
( 'Other Error Message to Create Table Column: '
|| l_error_msg
);
END BTC_create_user_column_api_p;

PROCEDURE BTC_user_row_api (
p_table_name IN VARCHAR2,
p_business_group_id IN NUMBER,
p_effective_date IN DATE
)
AS
l_user_table_id NUMBER (9);
l_row_low_range_or_name VARCHAR2 (80);
l_display_sequence NUMBER (9);
l_business_group_id NUMBER (9);
l_legislation_code VARCHAR2 (30);
l_row_high_range VARCHAR2 (30);
l_user_row_id NUMBER (9);
l_object_version_number NUMBER (9);
l_effective_start_date DATE;
l_effective_end_date DATE;
l_error_msg VARCHAR2 (1000);

CURSOR c_user_row
IS
SELECT DISTINCT row_name name_row
FROM BTC_new_user_table_value_t
WHERE UPPER (table_name) = UPPER (p_table_name)
-- and row_name<>1
ORDER BY row_name;
BEGIN
SELECT user_table_id
INTO l_user_table_id
FROM pay_user_tables
WHERE business_group_id = p_business_group_id
AND UPPER (user_table_name) = UPPER (p_table_name);

DBMS_OUTPUT.put_line ('Create Row for Table :' || p_table_name);


l_display_sequence := 0;

FOR user_row IN c_user_row


LOOP
BEGIN
l_display_sequence := l_display_sequence + 1;
pay_user_row_api.create_user_row
(p_effective_date => p_effective_date,
--TO_DATE('1/jan/1950','dd/mon/yyyy'),
p_user_table_id => l_user_table_id,
p_row_low_range_or_name => user_row.name_row,
p_display_sequence => l_display_sequence,
p_business_group_id => p_business_group_id,
p_user_row_id => l_user_row_id,
p_object_version_number => l_object_version_number,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date
);
COMMIT;
-- BTC_USER_TAB_LOG(3.01,P_TABLE_NAME||'--PROCESS --CREATE ROWS--'||
user_row.name_row,l_user_row_id||'--WITH SEQUENCE--'||l_display_sequence);
DBMS_OUTPUT.put_line ( 'Row Created for Table ==> :'
|| p_table_name
|| ' Row Name :'
|| user_row.name_row
);
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line ( 'Error Created for Row ==> :'
|| p_table_name
|| ' Row Name :'
|| user_row.name_row
);
END;
END LOOP;

-- return(flag);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line ( 'Other Error Message to Create ROW :'
|| l_error_msg
);
END BTC_user_row_api;
PROCEDURE BTC_user_values_api (
p_business_group_id IN NUMBER,
p_user_table IN VARCHAR2,
p_column_name IN VARCHAR2,
p_row_name IN VARCHAR2,
p_value IN VARCHAR2,
p_effective_date IN DATE
)
AS
l_user_row_id NUMBER (9);
l_user_column_id NUMBER (9);
l_user_table_id NUMBER (9);
l_user_column_instance_id NUMBER (9);
l_object_version_number NUMBER (9);
l_effective_start_date DATE;
l_effective_end_date DATE;
l_eff_date DATE;
l_error_msg VARCHAR2 (2000);
BEGIN
DBMS_OUTPUT.put_line ( 'Start Create RowValue :'
|| p_user_table
|| ' '
|| p_column_name
|| ' '
|| p_row_name
|| ' '
|| p_value
);

SELECT user_table_id
INTO l_user_table_id
FROM pay_user_tables
WHERE business_group_id = p_business_group_id
AND UPPER (user_table_name) = UPPER (p_user_table);

-- BTC_USER_TAB_LOG(4.01,p_user_table||p_column_name,'--l_user_table_id--'||
v_user_table_id||'--CREATE values');
SELECT user_row_id
INTO l_user_row_id
FROM pay_user_rows_f
WHERE business_group_id = p_business_group_id
AND user_table_id = l_user_table_id
AND UPPER (row_low_range_or_name) = UPPER (p_row_name)
AND TO_DATE (p_effective_date) BETWEEN effective_start_date
AND effective_end_date;

-- BTC_USER_TAB_LOG(4.02,p_user_table||p_column_name,'--l_user_row_id--'||
v_user_row_id||'--CREATE values');
SELECT user_column_id
INTO l_user_column_id
FROM pay_user_columns
WHERE business_group_id = p_business_group_id
AND user_table_id = l_user_table_id
AND UPPER (user_column_name) = UPPER (p_column_name);

-- BTC_USER_TAB_LOG(4.03,p_user_table||p_column_name,'--
l_user_column_id--'||v_user_column_id||'--CREATE values');
pay_user_column_instance_api.create_user_column_instance
(p_effective_date => p_effective_date,
--TO_DATE('1/jan/1950','dd/mon/yyyy'),
p_user_row_id => l_user_row_id,
p_user_column_id => l_user_column_id,
p_value => p_value,
p_business_group_id => p_business_group_id,
p_user_column_instance_id => l_user_column_instance_id,
p_object_version_number => l_object_version_number,
p_effective_start_date => l_effective_start_date,
p_effective_end_date => l_effective_end_date
);
COMMIT;
-- BTC_USER_TAB_LOG(4.04,p_user_table||p_column_name,'--
l_user_column_instance_id--'||l_user_column_instance_id||'--CREATE values');
-- DBMS_OUTPUT.put_line ('User Row Value Created ');
DBMS_OUTPUT.put_line ( 'Row Created -- back to calling function :'
|| p_user_table
|| ' '
|| p_column_name
|| ' '
|| p_row_name
|| ' '
|| p_value
);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
DBMS_OUTPUT.put_line ( 'Error Row Created -- Row :'
|| p_user_table
|| ' '
|| p_column_name
|| ' '
|| p_row_name
|| ' '
|| p_value
|| 'Mesage :'
|| l_error_msg
);
END BTC_user_values_api;

PROCEDURE BTC_user_column_values_api (
p_business_group_id IN NUMBER,
p_user_table IN VARCHAR2,
p_effective_date IN DATE
)
IS
l_user_row_id NUMBER (15);
l_user_column_id NUMBER (15);
l_user_table_id NUMBER (9);
l_value VARCHAR2 (20);
l_user_column_instance_id NUMBER (9);
l_object_version_number NUMBER (9);
l_effective_start_date DATE;
l_effective_end_date DATE;
l_count NUMBER DEFAULT 0;
l_row NUMBER DEFAULT 0;
l_column NUMBER DEFAULT 0;
l_error_msg VARCHAR2 (1000);
CURSOR c_user_column
IS
SELECT DISTINCT column_name name_column
FROM BTC_new_user_table_value_t
--BTC_api_pay_user_table
WHERE UPPER (table_name) = UPPER (p_user_table)
-- and row_name<>1
ORDER BY column_name;

CURSOR c_user_row
IS
SELECT DISTINCT row_name name_row
FROM BTC_new_user_table_value_t
--BTC_api_pay_user_table
WHERE UPPER (table_name) = UPPER (p_user_table)
-- and row_name<>1
ORDER BY row_name;
BEGIN
-- BTC_USER_TAB_LOG(5.0,'TABLE_NAME'||p_user_table,'--PROCESS --CREATE
values API');
DBMS_OUTPUT.put_line ('Create Row Value ==>' || p_user_table);

SELECT user_table_id
INTO l_user_table_id
FROM pay_user_tables
WHERE business_group_id = p_business_group_id
AND UPPER (user_table_name) = UPPER (p_user_table);

-- BTC_USER_TAB_LOG(5.01,'TABLE_NAME'||p_user_table,'v_user_table_id'||
v_user_table_id||'--PROCESS --CREATE values API');
COMMIT;

FOR user_column IN c_user_column


LOOP
BEGIN
l_column := l_column + 1;

SELECT user_column_id
INTO l_user_column_id
FROM pay_user_columns
WHERE business_group_id = p_business_group_id
AND user_table_id = l_user_table_id
AND user_column_name = user_column.name_column;

-- BTC_USER_TAB_LOG(5.02,'TABLE_NAME'||p_user_table,p_column||'--
v_user_column_id--'||v_user_column_id||'--PROCESS --CREATE values API');
FOR user_row IN c_user_row
LOOP
BEGIN
l_row := l_row + 1;

SELECT user_row_id
INTO l_user_row_id
FROM pay_user_rows_f
WHERE business_group_id = p_business_group_id
AND user_table_id = l_user_table_id
AND TO_DATE (p_effective_date) BETWEEN effective_start_date
AND effective_end_date
AND UPPER (row_low_range_or_name) =
UPPER (user_row.name_row);

-- BTC_USER_TAB_LOG(5.03,'TABLE_NAME'||p_user_table,p_row||'--
v_user_row_id--'||v_user_row_id||'--PROCESS --CREATE values API');
SELECT user_value
INTO l_value
FROM BTC_new_user_table_value_t tab
--BTC_api_pay_user_table
WHERE tab.table_name = p_user_table
AND UPPER (tab.row_name) = UPPER (user_row.name_row)
AND UPPER (tab.column_name) =
UPPER (user_column.name_column);

-- BTC_USER_TAB_LOG(5.04,'TABLE_NAME'||p_user_table,'v_value'||v_value||'--
PROCESS --CREATE values API');
DBMS_OUTPUT.put_line ( 'Call Seha User Value API==>'
|| p_user_table
|| ' Column Name :'
|| user_column.name_column
|| 'Row Name '
|| user_row.name_row
);
BTC_user_values_api (p_business_group_id,
p_user_table,
user_column.name_column,
user_row.name_row,
l_value,
p_effective_date
);
COMMIT;
DBMS_OUTPUT.put_line ( 'Row Created==>'
|| p_user_table
|| ' Column Name :'
|| user_column.name_column
|| 'Row Name '
|| user_row.name_row
);
EXCEPTION
WHEN OTHERS
THEN
NULL;
/*
l_error_msg := SUBSTR (SQLERRM, 1, 2000);

DBMS_OUTPUT.put_line ( 'Error for Row Created==>'


|| p_user_table
|| ' Column Name :'
|| user_column.name_column
|| 'Row Name '
|| user_row.name_row
|| 'Mesage '
|| l_error_msg
);
-- DBMS_OUTPUT.put_line ('Error Message :' ||
l_error_msg);
COMMIT;*/
END;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
-- BTC_USER_TAB_LOG(5.06,'TABLE_NAME'||p_user_table||'--PROCESS --CREATE
rows',v_error_msg);
DBMS_OUTPUT.put_line
( 'Other 1 Error Message to create row value :'
|| p_user_table
);
COMMIT;
END;
END LOOP;

l_count := l_count + 1;
DBMS_OUTPUT.put_line (l_count);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
l_error_msg := SUBSTR (SQLERRM, 1, 2000);
-- BTC_USER_TAB_LOG(5.07,'TABLE_NAME'||p_user_table||'--PROCESS --CREATE
rows',v_error_msg);
-- DBMS_OUTPUT.put_line ('Error Message :' || l_error_msg);
DBMS_OUTPUT.put_line
( 'Other 2 Error Message to create row value :'
|| p_user_table
);
END BTC_user_column_values_api;

PROCEDURE BTC_change_global_var (
p_business_group_id IN apps.pay_element_types_f.business_group_id%TYPE,
p_effective_date IN DATE,
p_responsibility_name IN apps.fnd_responsibility_tl.responsibility_name
%TYPE
)
IS
l_responsibility_id fnd_responsibility.responsibility_id%TYPE;
BEGIN
g_business_group_id := p_business_group_id;
g_effective_date := p_effective_date;

BEGIN
SELECT responsibility_id
INTO l_responsibility_id
FROM fnd_responsibility_tl frtl
WHERE frtl.responsibility_name LIKE p_responsibility_name
AND frtl.LANGUAGE = 'US';

g_resp_id := l_responsibility_id;
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
END;
END BTC_payroll_migration_pkg;

You might also like