API to Create HR Organization and Cost Allocation Segment
DECLARE
p_effective_date DATE;
p_object_version_number NUMBER;
p_duplicate_org_warning BOOLEAN;
v_err VARCHAR2 (1000);
l_org_id NUMBER;
lb_record_status BOOLEAN;
lv_error_message VARCHAR2 (2400);
CURSOR c1
IS
SELECT *
FROM xxkq_org_cost_stg
WHERE 1 = 1 AND status IS NULL AND sno <= 400;
BEGIN
FOR i IN c1
LOOP
lb_record_status := TRUE;
lv_error_message := '';
BEGIN
SELECT org.organization_id, org.date_from, org.object_version_number
INTO l_org_id, p_effective_date, p_object_version_number
FROM hr_all_organization_units org
WHERE 1 = 1 AND NAME = TRIM (i.ORGANIZATION);
EXCEPTION
WHEN OTHERS
THEN
l_org_id := NULL;
END;
IF l_org_id IS NULL
THEN
lb_record_status := FALSE;
lv_error_message := 'Unable to find the Organization Details';
END IF;
IF lb_record_status = TRUE
THEN
BEGIN
hr_organization_api.update_organization
(p_validate => FALSE,
p_effective_date => p_effective_date,
p_organization_id => l_org_id,
p_segment1 => TO_CHAR (i.company),
p_segment2 => TO_CHAR (i.LOCATION),
p_segment3 => TO_CHAR
(i.cost_centre),
p_object_version_number => p_object_version_number,
p_duplicate_org_warning => p_duplicate_org_warning
);
UPDATE xxkq_org_cost_stg
SET status = 'S',
error_msg = ''
WHERE sno = i.sno;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
lv_error_message := SUBSTR (SQLERRM, 1, 239);
ROLLBACK;
UPDATE xxkq_org_cost_stg
SET status = 'E',
error_msg = lv_error_message
WHERE sno = i.sno;
END;
ELSE
UPDATE xxkq_org_cost_stg
SET status = 'E',
error_msg = lv_error_message
WHERE sno = i.sno;
COMMIT;
END IF;
END LOOP;
COMMIT;
END;
No comments:
Post a Comment