Tuesday, July 22, 2014

Create/Update Organization - HRMS APIs

-----------------------------------
--Create Organization
-----------------------------------
declare
l_validate_mode          BOOLEAN := TRUE;
l_begin_date             DATE    := SYSDATE;
l_end_date               DATE    := hr_general.end_of_time;
l_business_group_id      NUMBER  := 101;
l_orgname                hr_all_organization_units.name%TYPE := 'Test Org';
l_intl_extl              fnd_lookup_values.meaning%TYPE;
l_organization_id        hr_all_organization_units.organization_id%TYPE;
l_object_version_number  hr_all_organization_units.object_version_number%TYPE;
l_duplicate_org_warning  BOOLEAN;
begin
  apps.hr_organization_api.create_organization
  (
     p_validate                    => l_validate_mode
    ,p_effective_date           => l_begin_date --Reference date for validating lookup values
    ,p_business_group_id    => l_business_group_id
    ,p_date_from                => l_begin_date --Date the organization takes effect
    ,p_name                        => l_orgname
    ,p_location_id                => null
    ,p_date_to                     => l_end_date
    ,p_internal_external_flag  => l_intl_extl--'INT' --Internal/External org flag
    ,p_internal_address_line  => null
    ,p_type                           => null  --Org type -- Lookup Type ORG_TYPE
    ,p_comments                   => null
    ,p_attribute_category       => null
    ,p_attribute1                    => null
    ,p_attribute2                    => 'Test Org'
    ,p_attribute3                    => null
    ,p_attribute4                    => null
    ,p_attribute5                    => null
    --Out Variables
    ,p_organization_id                 => l_organization_id
    ,p_object_version_number      => l_object_version_number
    ,p_duplicate_org_warning       => l_duplicate_org_warning
    );

   if l_organization_id is null or l_object_version_number is null then
      dbms_output.put_line('hr_organization_api.update_organization API Error: '||sqlerrm);
      rollback;
   elsif l_duplicate_org_warning then
      dbms_output.put_line('Warning: Duplicate Organization');
      rollback;
   else
      commit;
   end if;  
--
exception
  when others then
     dbms_output.put_line('hr_organization_api.create_organization API failed with error :'||sqlerrm);
     rollback;
end;

-----------------------------------
-----------------------------------
--Update Organization
-----------------------------------

declare
l_validate_mode          BOOLEAN := TRUE;
l_begin_date             DATE    := SYSDATE;
l_end_date               DATE    := hr_general.end_of_time;
l_organization_id        hr_all_organization_units.organization_id%TYPE := 104;
l_orgname                hr_all_organization_units.name%TYPE := 'Test Org';
l_object_version_number  hr_all_organization_units.object_version_number%TYPE;
l_duplicate_org_warning  BOOLEAN;
begin
   --
   hr_organization_api.update_organization
      (
        p_validate                  => l_validate_mode
       ,p_effective_date         => l_begin_date --Reference date for validating lookup values
       ,p_date_from               => l_begin_date --Date the organization takes effect
       ,p_date_to                   => l_end_date
       ,p_organization_id        => l_organization_id
       ,p_name                      => l_orgname
       ,p_attribute_category    => null
       ,p_attribute1                => null
       ,p_attribute2                => 'Test Org'
       --Out Variables
       ,p_object_version_number    => l_object_version_number
       ,p_duplicate_org_warning     => l_duplicate_org_warning
      );

   if l_object_version_number is null then
      dbms_output.put_line('hr_organization_api.update_organization API Error: '||sqlerrm);
      rollback;
   elsif l_duplicate_org_warning then
      dbms_output.put_line('Warning: Duplicate Organization');
      rollback;
   else
      commit;
   end if;
--
exception
  when others then
     dbms_output.put_line('hr_organization_api.update_organization API failed with error :'||sqlerrm);
     rollback;
end;

No comments:

Post a Comment