DECLARE
p_effective_date DATE;
v_err VARCHAR2 (1000);
p_object_version_number NUMBER;
p_cost_allocation_keyflex_id NUMBER;
p_balancing_keyflex_id NUMBER;
p_cost_concat_segments_out VARCHAR2 (250);
p_balance_concat_segments_out VARCHAR2 (250);
p_effective_start_date DATE;
p_effective_end_date DATE;
-------------------------------
p_cost_segment1 VARCHAR2 (50) := NULL;
p_cost_segment2 VARCHAR2 (50) := NULL;
p_balance_segment1 VARCHAR2 (50) := NULL;
p_balance_segment2 VARCHAR2 (50) := NULL;
CURSOR c1
IS
(SELECT *
FROM xx_update_link_costing_nol xx
WHERE xx.valid_flag = 'N' AND xx.element_type_id IS NOT NULL)
FOR UPDATE;
v_c1 c1%ROWTYPE;
BEGIN
INSERT INTO fnd_sessions
VALUES (USERENV ('SESSIONID'), TRUNC (SYSDATE));
OPEN c1;
LOOP
FETCH c1
INTO v_c1;
EXIT WHEN c1%NOTFOUND;
FOR i IN (SELECT element_link_id
FROM pay_element_links_f lnk
WHERE lnk.business_group_id = v_c1.business_group_id
AND lnk.element_type_id = v_c1.element_type_id
AND lnk.effective_end_date =
TO_DATE ('31/12/4712', 'DD/MM/YYYY'))
LOOP
BEGIN
SELECT lnk.effective_start_date, lnk.object_version_number
INTO p_effective_date, p_object_version_number
FROM pay_element_links_f lnk
WHERE lnk.business_group_id = v_c1.business_group_id
AND lnk.element_link_id = i.element_link_id
AND lnk.effective_end_date =
TO_DATE ('31/12/4712', 'DD/MM/YYYY');
BEGIN
IF v_c1.cost_company = 'Not exist'
THEN
p_cost_segment1 := NULL;
p_cost_segment2 := NULL;
ELSE
p_cost_segment1 := NVL (v_c1.cost_company, '0000');
p_cost_segment2 := NVL (v_c1.cost_cost_center, '0000');
END IF;
p_balance_segment1 := NVL (v_c1.balance_company, '0000');
p_balance_segment2 := NVL (v_c1.balance_cost_center, '0000');
-------------
pay_element_link_api.update_element_link
(p_validate => FALSE,
p_effective_date => p_effective_date,
p_element_link_id => i.element_link_id,
p_datetrack_mode => 'CORRECTION',
p_transfer_to_gl_flag => 'Y',
p_costable_type => 'C',
p_cost_segment1 => p_cost_segment1,
p_cost_segment2 => p_cost_segment2,
p_balance_segment1 => p_balance_segment1,
p_balance_segment2 => p_balance_segment2,
p_object_version_number => p_object_version_number,
p_cost_allocation_keyflex_id => p_cost_allocation_keyflex_id,
p_balancing_keyflex_id => p_balancing_keyflex_id,
p_cost_concat_segments_out => p_cost_concat_segments_out,
p_balance_concat_segments_out => p_balance_concat_segments_out,
p_effective_start_date => p_effective_start_date,
p_effective_end_date => p_effective_end_date
);
UPDATE xx_update_link_costing_nol xx
SET xx.err = 'Done',
xx.valid_flag = 'Y'
WHERE CURRENT OF c1;
EXCEPTION
WHEN OTHERS
THEN
p_cost_segment1 := NULL;
p_cost_segment2 := NULL;
p_balance_segment1 := NULL;
p_balance_segment2 := NULL;
p_effective_date := NULL;
p_object_version_number := NULL;
p_cost_allocation_keyflex_id := NULL;
p_balancing_keyflex_id := NULL;
p_cost_concat_segments_out := NULL;
p_balance_concat_segments_out := NULL;
p_effective_start_date := NULL;
p_effective_end_date := NULL;
v_err := NULL;
v_err := (SQLERRM);
UPDATE xx_update_link_costing_nol xx
SET xx.err = v_err,
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
EXCEPTION
WHEN OTHERS
THEN
p_cost_segment1 := NULL;
p_cost_segment2 := NULL;
p_balance_segment1 := NULL;
p_balance_segment2 := NULL;
p_effective_date := NULL;
p_object_version_number := NULL;
p_cost_allocation_keyflex_id := NULL;
p_balancing_keyflex_id := NULL;
p_cost_concat_segments_out := NULL;
p_balance_concat_segments_out := NULL;
p_effective_start_date := NULL;
p_effective_end_date := NULL;
v_err := NULL;
UPDATE xx_update_link_costing_nol xx
SET xx.err = 'Element Link Select Error',
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
END LOOP;
END LOOP;
CLOSE c1;
COMMIT;
END;
p_effective_date DATE;
v_err VARCHAR2 (1000);
p_object_version_number NUMBER;
p_cost_allocation_keyflex_id NUMBER;
p_balancing_keyflex_id NUMBER;
p_cost_concat_segments_out VARCHAR2 (250);
p_balance_concat_segments_out VARCHAR2 (250);
p_effective_start_date DATE;
p_effective_end_date DATE;
-------------------------------
p_cost_segment1 VARCHAR2 (50) := NULL;
p_cost_segment2 VARCHAR2 (50) := NULL;
p_balance_segment1 VARCHAR2 (50) := NULL;
p_balance_segment2 VARCHAR2 (50) := NULL;
CURSOR c1
IS
(SELECT *
FROM xx_update_link_costing_nol xx
WHERE xx.valid_flag = 'N' AND xx.element_type_id IS NOT NULL)
FOR UPDATE;
v_c1 c1%ROWTYPE;
BEGIN
INSERT INTO fnd_sessions
VALUES (USERENV ('SESSIONID'), TRUNC (SYSDATE));
OPEN c1;
LOOP
FETCH c1
INTO v_c1;
EXIT WHEN c1%NOTFOUND;
FOR i IN (SELECT element_link_id
FROM pay_element_links_f lnk
WHERE lnk.business_group_id = v_c1.business_group_id
AND lnk.element_type_id = v_c1.element_type_id
AND lnk.effective_end_date =
TO_DATE ('31/12/4712', 'DD/MM/YYYY'))
LOOP
BEGIN
SELECT lnk.effective_start_date, lnk.object_version_number
INTO p_effective_date, p_object_version_number
FROM pay_element_links_f lnk
WHERE lnk.business_group_id = v_c1.business_group_id
AND lnk.element_link_id = i.element_link_id
AND lnk.effective_end_date =
TO_DATE ('31/12/4712', 'DD/MM/YYYY');
BEGIN
IF v_c1.cost_company = 'Not exist'
THEN
p_cost_segment1 := NULL;
p_cost_segment2 := NULL;
ELSE
p_cost_segment1 := NVL (v_c1.cost_company, '0000');
p_cost_segment2 := NVL (v_c1.cost_cost_center, '0000');
END IF;
p_balance_segment1 := NVL (v_c1.balance_company, '0000');
p_balance_segment2 := NVL (v_c1.balance_cost_center, '0000');
-------------
pay_element_link_api.update_element_link
(p_validate => FALSE,
p_effective_date => p_effective_date,
p_element_link_id => i.element_link_id,
p_datetrack_mode => 'CORRECTION',
p_transfer_to_gl_flag => 'Y',
p_costable_type => 'C',
p_cost_segment1 => p_cost_segment1,
p_cost_segment2 => p_cost_segment2,
p_balance_segment1 => p_balance_segment1,
p_balance_segment2 => p_balance_segment2,
p_object_version_number => p_object_version_number,
p_cost_allocation_keyflex_id => p_cost_allocation_keyflex_id,
p_balancing_keyflex_id => p_balancing_keyflex_id,
p_cost_concat_segments_out => p_cost_concat_segments_out,
p_balance_concat_segments_out => p_balance_concat_segments_out,
p_effective_start_date => p_effective_start_date,
p_effective_end_date => p_effective_end_date
);
UPDATE xx_update_link_costing_nol xx
SET xx.err = 'Done',
xx.valid_flag = 'Y'
WHERE CURRENT OF c1;
EXCEPTION
WHEN OTHERS
THEN
p_cost_segment1 := NULL;
p_cost_segment2 := NULL;
p_balance_segment1 := NULL;
p_balance_segment2 := NULL;
p_effective_date := NULL;
p_object_version_number := NULL;
p_cost_allocation_keyflex_id := NULL;
p_balancing_keyflex_id := NULL;
p_cost_concat_segments_out := NULL;
p_balance_concat_segments_out := NULL;
p_effective_start_date := NULL;
p_effective_end_date := NULL;
v_err := NULL;
v_err := (SQLERRM);
UPDATE xx_update_link_costing_nol xx
SET xx.err = v_err,
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
EXCEPTION
WHEN OTHERS
THEN
p_cost_segment1 := NULL;
p_cost_segment2 := NULL;
p_balance_segment1 := NULL;
p_balance_segment2 := NULL;
p_effective_date := NULL;
p_object_version_number := NULL;
p_cost_allocation_keyflex_id := NULL;
p_balancing_keyflex_id := NULL;
p_cost_concat_segments_out := NULL;
p_balance_concat_segments_out := NULL;
p_effective_start_date := NULL;
p_effective_end_date := NULL;
v_err := NULL;
UPDATE xx_update_link_costing_nol xx
SET xx.err = 'Element Link Select Error',
xx.valid_flag = 'N'
WHERE CURRENT OF c1;
END;
END LOOP;
END LOOP;
CLOSE c1;
COMMIT;
END;