Monday, February 24, 2014

How to programmatically create HR Job Codes Key Flexfield using HR_JOB_API

-- Following is a sample code to create/populate HR Jobs in Oracle HRMS module
-- API Name: HR_JOB_API.CREATE_JOB
-- Parameters:
--   p_bg_id - Business_Group_Id
--   p_job_code - Job Code populated into Segment1 of Job Key Flexfield
--   p_job_code - Job Title populated into Segment2 of Job Key Flexfield
DECLARE
   op_job_id                  NUMBER;
   op_object_version_number   NUMBER;
   x_job_definition_id        NUMBER;
   op_name                    VARCHAR2 (1000);
   lv_job_group_id            per_job_groups.job_group_id%TYPE;
   lv_business_group_id       NUMBER := &p_bg_id;
   lv_job_code                VARCHAR2 (60) := '&p_job_code';
   lv_job_title               VARCHAR2 (60) := '&p_job_title';
BEGIN
   ---------------------------------------------------
   -->> JOB GROUP ID <<--
   ---------------------------------------------------
   SELECT job_group_id
     INTO lv_job_group_id
     FROM per_job_groups
    WHERE 1=1
      AND displayed_name LIKE 'Setup Business Group'
      AND internal_name = 'HR_81';

   hr_job_api.create_job (
      p_business_group_id          => lv_business_group_id,
      p_date_from                  => '01-JAN-1950',
      p_job_group_id               => lv_job_group_id,
      p_segment1                   => lv_job_code,                  --JOB_CODE
      p_segment2                   => lv_job_title,                --JOB_TITLE
      p_job_id                     => op_job_id,
      p_object_version_number      => op_object_version_number,
      p_job_definition_id          => x_job_definition_id,
      p_job_information_category   => 'US',
      p_name                       => op_name);

   DBMS_OUTPUT.PUT_LINE ('OUTPUT JOB NAME CREATED : ' || op_name);
   DBMS_OUTPUT.PUT_LINE ('OUTPUT JOB ID CREATED : ' || op_job_id);
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.PUT_LINE ('Error Message Is: ' || SQLERRM);
END;

No comments:

Post a Comment