Wednesday 30 April 2014

Query to get EIT and SIT in HRMS

Query to get EIT and SIT in HRMS

Query to get Extra Information Types (EIT) and Special Information Types (SIT) values from HRMS Module:

Say 'Certification Course Details', 'Visa Information'...etc are SITs in HRMS. Below example is used to get 'Certification Course Details' of employees:

SELECT   papf.employee_number, papf.full_name, ppt.user_person_type emptype,
         SUBSTR (hsck.concatenated_segments,
                 1,
                 INSTR (hsck.concatenated_segments, '|') - 1
                ) company_name,
         paaf.effective_start_date,
         TO_CHAR (TO_DATE (pac.segment2, 'YYYY/MM/DD HH24:MI:SS'),
                  'DD-MON-YYYY'
                 ) paid_date,
         pac.segment3 amount, pac.segment4 amnt_type, pac.segment1 course
    FROM per_all_people_f papf,
         per_all_assignments_f paaf,
         hr_soft_coding_keyflex hsck,
         per_person_analyses ppa,
         fnd_id_flex_structures fifs,
         per_special_info_types psit,
         per_analysis_criteria pac,
         per_person_types ppt
   WHERE paaf.person_id = papf.person_id
     AND ppt.person_type_id = papf.person_type_id
     AND pac.id_flex_num = fifs.id_flex_num
     AND fifs.id_flex_structure_code = 'Certification Course Details'
     AND ppt.person_type_id(+) = papf.person_type_id
     AND psit.id_flex_num = pac.id_flex_num
     AND ppa.person_id (+) = papf.person_id
     AND pac.analysis_criteria_id (+) = ppa.analysis_criteria_id
     AND paaf.soft_coding_keyflex_id = hsck.soft_coding_keyflex_id(+)
     AND paaf.assignment_type = 'E'
     AND ppt.user_person_type <> 'Ex-employee'
     AND papf.business_group_id = :p_business_group_id
     AND SYSDATE BETWEEN papf.effective_start_date AND papf.effective_end_date
     AND SYSDATE BETWEEN paaf.effective_start_date AND paaf.effective_end_date
--and papf.effective_start_date between :p_from_date and :p_to_date
GROUP BY papf.full_name,
         papf.employee_number,
         ppt.user_person_type,
         paaf.effective_start_date,
         hsck.concatenated_segments,
         pac.segment2,
         pac.segment3,
         pac.segment4,
         pac.segment1;



Say 'Passport Details' is one the EITs in HRMS, then find the below query to get the passport information for particular employee

-- Data may have only in one field OR all fields
SELECT pei_information1,
       pei_information2,              
       pei_information3,
       pei_information4,
       pei_information5,
       pei_information6,
       pei_information7,
       pei_information8,
       pei_information9,
       pei_information10,
       pei_information11,
       pei_information12,
       pei_information13            
  FROM per_people_extra_info
 WHERE pei_information_category = 'Passport Details'    -- Could be any other EIT category
   AND person_id = :p_person_id;

HRMS API's

HRMS API's


Updating the Per_periods_of_service table using
hr_ex_employee_api.update_term_details_emp

Terminating using
hr_ex_employee_api.actual_termination_emp

Applying the final process in the shared instance using hr_ex_employee_api.final_process_emp

Re - Hire
hr_employee_api.re_hire_ex_employee

Updation On Already Existing Records
hr_person_api.update_us_person

New Hire
hr_employee_api.create_us_employee

Costing
pay_cost_allocation_api.create_cost_allocation

Load Update Assign
hr_assignment_api.update_us_emp_asg

Load Update Assign Criteria
hr_assignment_api.update_emp_asg_criteria

IF CONTACT PERSON ALREADY CREATED AND ONLY RELATION SHIP IS TO BE CREATED -
Note : Contact Person Id Is To Be Passed
hr_contact_rel_api.create_contact

If Contact Person Already Not Created
Note : Contact Person Id is passed as Null(default of API)
hr_contact_rel_api.create_contact

Load Phones
hr_phone_api.create_phone
hr_person_address_api.update_person_address

Load Addresses
hr_person_address_api.update_person_address
hr_person_address_api.create_person_address

Load Payment Methods
hr_personal_pay_method_api.create_us_personal_pay_method

Element Loading
py_element_entry_api.create_element_entry
py_element_entry_api.update_element_entry

Load Salaries
hr_upload_proposal_api.upload_salary_proposal

Approve Salary Proposal
hr_maintain_proposal_api.approve_salary_proposal

Starts To Validate/Load Federal Tax For A Person pay_federal_tax_rule_api.update_fed_tax_rule

State tax rules
pay_state_tax_rule_api.create_state_tax_rule
pay_state_tax_rule_api.update_state_tax_rule

County Tax Rules
pay_county_tax_rule_api.create_county_tax_rule
pay_county_tax_rule_api.update_county_tax_rule

City Tax Rules
pay_city_tax_rule_api.create_city_tax_rule
pay_city_tax_rule_api.update_city_tax_rule

Schools and Colleges
per_esa_upd.upd
per_esa_ins.ins

Performance Reviews
hr_perf_review_api.create_perf_review
hr_perf_review_api.update_perf_review

State Information Taxes
hr_sit_api.update_sit
hr_sit_api.create_sit

Qualifications
per_qualifications_api.create_qualification
per_qualifications_api.update_qualification

Locations
hr_location_api.update_location
hr_location_api.create_location

Organization
hr_organization_api.update_organization
hr_organization_api.create_org_classification

If any Change in Organization information.
if information2 = 'Y' then
hr_organization_api.enable_org_classification

If any Change in Organization information.
if information2 = 'N' then
hr_organization_api.disable_org_classification

If Organization does not exist in instance
hr_organization_api.create_organization api

Jobs
hr_job_api.update_job
hr_job_api.create_job

Positions
hr_position_api.update_position
hr_position_api.create_position

The query to get the list of HRMS API's in Oracle is as follows:

select *
from all_objects
where object_name like 'HR%\_API' escape '\'
and object_type = 'PACKAGE'
union
select *
from all_objects
where object_name like 'PAY%\_API' escape '\'
and object_type = 'PACKAGE'
union
select *
from all_objects
where object_name like 'PER%\_API' escape '\'
and object_type = 'PACKAGE'

Tuesday 15 April 2014

Deleting Value Set Values From Backend

DECLARE
   l_err_msg   VARCHAR2 (500) := NULL;
   CURSOR c1
   IS
      SELECT ffv.flex_value_id, ffv.flex_value
        FROM fnd_flex_value_sets ffvs,
             fnd_flex_values ffv,
             fnd_flex_values_tl ffvt
       WHERE     flex_value_set_name = 'testtest' -- Value Set Name
             AND ffv.flex_value_set_id = ffvs.flex_value_set_id
             AND ffvt.flex_value_id = ffv.flex_value_id
             AND ffvs.flex_value_set_id = ffv.flex_value_set_id
             AND ffvt.language = 'US'
             AND ffv.enabled_flag = 'Y'
             AND ffv.summary_flag = 'N';
BEGIN
   FOR i IN c1
   LOOP
      fnd_flex_values_pkg.delete_row (i.flex_value_id);
      COMMIT;
      DBMS_OUTPUT.put_line (i.flex_value_id || ' Deleted  Successfully !!!!');
   END LOOP;
EXCEPTION
   WHEN OTHERS
   THEN
      l_err_msg := SQLERRM;
      DBMS_OUTPUT.put_line ('Exception: ' || l_err_msg);

END;

Thursday 10 April 2014

Steps For Getting The Output in Excel Format in Oracle APPS

Steps For Getting The Output in Excel Format in Oracle APPS

Logon to Oracle Applications , use System Administrator Responsibility and Navigate as :-
Install -> Viewer Options
to open the Form “Viewer Options”

Then do the entry as shown below :-

File format - Mime Type --Description
-------------------------------------------
Text - application/msword - Microsoft Word(.doc)
Text - application/vnd.ms-excel - Excel (.xls)
Text - Notepad(.txt)

Ensure that the profile option
Viewer: Application for Text
is set to
BLANK
at the Site Level

Then ensure that the profile option
Viewer: Text
is set to
Browser
at the Site Level

Then restart the Concurrent Processing Server

Submit a Concurrent Request that generates Text Output File
Click on View Output
Button
You will see a LOV showing
Microsoft Word(.doc)
Excel (.xls)
Notepad(.txt)

When you choose Microsoft Word(.doc) , the Text File will be transferred using the Mime Type application/msword
, so the browser will open the Text File in Word

When you choose Excel (.xls) , the Text File will be transferred using the Mime Type application/vnd.ms-excel
, so the browser will open the Text File in Excel

When you choose Notepad(.txt) , the Text File will be transferred using the Mime Type text/plain
, so the browser will open the Text File in Notepad

Update using multiple conditions from multiple tables

update bom_operation_resources  set
usage_rate_or_amount = 0,
usage_rate_or_amount_inverse = 0
where exists (select c.usage_rate_or_amount,c.usage_rate_or_amount_inverse
from bom_operational_routings a,
bom_operation_sequences b,
bom_operation_resources c,
mtl_system_items d
where a.routing_sequence_id = b.routing_sequence_id
and b.operation_sequence_id = c.operation_sequence_id
and d.inventory_item_id = a.assembly_item_id
and a.organization_id = d.organization_id
and d.segment1 like 'FG%'
and bom_operation_resources.operation_sequence_id =c.operation_sequence_id)
--and c.operation_sequence_id = 3759) 

Tuesday 8 April 2014

get financial year from a date in oracle


SELECT    EXTRACT (YEAR FROM ADD_MONTHS (SYSDATE, -3))
       || '-'
       || EXTRACT (YEAR FROM ADD_MONTHS (SYSDATE, 9))
  FROM DUAL;

Wednesday 2 April 2014

Spell Number : Convert Number INTO Words

Spell Number : Convert Number INTO Words

How can you convert a number into words using Oracle Sql Query?
How can I spell number?
Means:
 12 = Twelve
102 = One Hundred Two
1020 = One Thousand Twenty
12.12 = twelve point twelve

Here’s a classy query which will convert number into words but this technique is havinglimitations which is discussed later in this topic .Please see the query below:

select to_char(to_date(:number,'j'),'jsp') from dual;
If I pass 134 in number, then the output will : one hundred thirty-four

SELECT TO_CHAR (TO_DATE (134, 'j'), 'jsp') FROM DUAL;
//Output: one hundred thirty-four

SELECT TO_CHAR (TO_DATE (34835, 'j'), 'jsp') FROM DUAL;
//Output: thirty-four thousand eight hundred thirty-five

SELECT TO_CHAR (TO_DATE (3447837, 'j'), 'jsp') FROM DUAL;
//Output: three million four hundred forty-seven thousand eight hundred thirty-seven

Understanding:
So how the query works?
If you look into the inner most part of the query to_date(:number,'j') the ‘j’ or J is the Julian Date(January 1, 4713 BC), basically this date is been used for astronomical studies.
So to_date(:number,'j') it take the number represented by number and pretend it is a julian date, convert into a date.
If you pass 3 to number, so it will convert date to 3rd Jan 4713 BC, it means 3 is added to the Julian date.
Now to_char(to_date(:number,'j'),'jsp'), jsp = Now; take that date(to_date(:number,'j')) and spell the julian number it represents


Limitation & workaround
There is a limitation while using Julian dates ,It ranges from 1 to 5373484. That’s why if you put the values after 5373484, it will throw you an error as shown below:
ORA-01854: julian date must be between 1 and 5373484
To cater the above problem ,create a function ,and with little trick with j->jsp ,you can fetch the desired result.


CREATE OR REPLACE FUNCTION spell_number (p_number IN NUMBER)
   RETURN VARCHAR2
AS
   TYPE myArray IS TABLE OF VARCHAR2 (255);

   l_str myArray
         := myArray ('',
                     ' thousand ',
                     ' million ',
                     ' billion ',
                     ' trillion ',
                     ' quadrillion ',
                     ' quintillion ',
                     ' sextillion ',
                     ' septillion ',
                     ' octillion ',
                     ' nonillion ',
                     ' decillion ',
                     ' undecillion ',
                     ' duodecillion ');

   l_num      VARCHAR2 (50) DEFAULT TRUNC (p_number);
   l_return   VARCHAR2 (4000);
BEGIN
   FOR i IN 1 .. l_str.COUNT
   LOOP
      EXIT WHEN l_num IS NULL;

      IF (SUBSTR (l_num, LENGTH (l_num) - 2, 3) <> 0)
      THEN
         l_return :=
            TO_CHAR (TO_DATE (SUBSTR (l_num, LENGTH (l_num) - 2, 3), 'J'),
                     'Jsp')
            || l_str (i)
            || l_return;
      END IF;

      l_num := SUBSTR (l_num, 1, LENGTH (l_num) - 3);
   END LOOP;

   RETURN l_return;
END;
/


SELECT spell_number (12345678904321) FROM DUAL;


Output:
Twelve trillion Three Hundred Forty-Five billion Six Hundred Seventy-Eight million Nine Hundred Four thousand Three Hundred Twenty-One

Limitation

Limitation of this function is decimal figure. This function is not catering decimal figures.
So I am writing simple program to cater decimal figure but It ranges from 1 to 5373484. L anyways later In this article I have shared the program which will cater decimal figures too.

CREATE OR REPLACE FUNCTION spell_number(P_NUMBER IN NUMBER) RETURN VARCHAR IS

    WORDS VARCHAR2(2000);
BEGIN

IF INSTR(P_NUMBER,'.') <> 0 THEN


        SELECT    INITCAP ((TO_CHAR (TO_DATE (SUBSTR (round(to_number(P_NUMBER),2), 1,
                                                      INSTR (P_NUMBER, '.', 1) - 1),
                                              'J'
                                             ),
                                     'JSP'
                                    )
                           )
                          )
               || ' Saudi Riyals '||'and '
               || INITCAP ((TO_CHAR (TO_DATE (SUBSTR (round(to_number(P_NUMBER),2), INSTR(P_NUMBER, '.', 1) + 1),
                                              'J'
                                             ),
                                     'JSP'
                                    )
                           )
                          )
               || ' Halalas' Curr into WORDS
          FROM DUAL;

ELSE

          SELECT    INITCAP ((TO_CHAR (TO_DATE (P_NUMBER,'J'),
                                     'JSP'
                                    )
                           )
                          )
               || ' Saudi Riyals and 00 Halalas'
                Curr into WORDS
          FROM DUAL;
       
END IF;
        RETURN WORDS;
     
Exception when others then return '00 Saudi Riyals and 00 Halalas';      

END;
/

Examples

select test_convert_num_to_words(0) from dual
//output 00 Saudi Riyals and 00 Halalas

select test_convert_num_to_words(10) from dual
//output Ten Saudi Riyals and 00 Halalas

select test_convert_num_to_words(10.12) from dual
//output Ten Saudi Riyals andTwelve Halalas

select test_convert_num_to_words(10.129) from dual
//output Ten Saudi Riyals and Thirteen Halalas
This function rounded the figure up to two decimal places


Now I am going to share the function which will cater decimal figure as well but its limitation will be 1 to999999999999.

CREATE OR REPLACE FUNCTION APPS.g5ps_spell_number(in_char  varchar2) RETURN varchar2 IS
--
-- *********************************************************************************
-- Function : Convert number to spell                                              *
-- Usage    : f_num_spelled('34567.88')                                            *
-- *********************************************************************************
--
   sub_char        varchar2(100);
   amt_with_cents     number(15,2);
   dollars           varchar2(100);
   len              number(2);
   c_num            number(18)    := to_number(in_char) ;
   cents            varchar2(100) := null ;
   full_amt         varchar2(100);
function F_SUB_1000 (in_char   varchar2 ) return varchar2 is
   len          number(1) := length(in_char);
   c_num        number    := null ;
   c1           number;
   c1_char      varchar2(50);
   c2           number;
   c2_char      varchar2(50);
   out_char     varchar2(100);
begin
      c_num  := to_number(in_char);
      if c_num > 0 and c_num < 1000 then
         out_char    := to_char(to_date(in_char, 'J'), 'JSP');
      else
         out_char    := null;
      end if;
      return(out_char) ;
end;
function F_SUB_1000000 (in_char   varchar2 ) return varchar2 is
   len          number(1) := length(in_char);
   c_num        number    := null ;
   c1           number;
   c1_char      varchar2(100);
   c2           number;
   c2_char      varchar2(100);
   out_char     varchar2(200);
begin
      c_num  := to_number(in_char);
      if ( c_num >= 1000 and c_num < 1000000 ) then
         c1       := FLOOR(c_num/1000);
         c1_char  := to_char(to_date(c1, 'J'), 'JSP');
         c2       := c_num - (c1 * 1000);
         if c2 > 0 then
            c2_char  := f_sub_1000(to_char(c2));
         else
            c2_char  := null;
         end if;
         out_char := c1_char||' THOUSAND '||c2_char ;
      else
         out_char := f_sub_1000(in_char) ;
      end if;
      return(out_char) ;
end;
function F_SUB_1000000000 (in_char   varchar2 ) return varchar2 is
   len          number(2) := length(in_char);
   c_num        number    := null ;
   c1           number;
   c1_char      varchar2(100);
   c2           number;
   c2_char      varchar2(100);
   out_char     varchar2(200);
begin
      c_num  := to_number(in_char);
      if ( c_num >= 1000000 and c_num < 1000000000 ) then
         c1       := FLOOR(c_num/1000000);
         c1_char  := to_char(to_date(c1, 'J'), 'JSP');
         c2       := c_num - (c1 * 1000000);
         if c2 > 0 then
            c2_char  := f_sub_1000000 (to_char(c2));
         else
            c2_char  := null;
         end if;
         out_char := c1_char||' MILLION '||c2_char ;
      else
         out_char  := f_sub_1000000 (in_char);
      end if;
      return(out_char) ;
end;
function F_SUB_1000000000000 (in_char   varchar2 ) return varchar2 is
   len          number(2)      := length(in_char);
   c_num        number(18)     := null ;
   c1           number;
   c1_char      varchar2(100);
   c2           number;
   c2_char      varchar2(100);
   out_char     varchar2(200);
begin
      c_num  := to_number(in_char);
      if ( c_num >= 1000000000 and c_num < 1000000000000 ) then
         c1       := FLOOR(c_num/1000000000);
         c1_char  := to_char(to_date(c1, 'J'), 'JSP');
         c2       := c_num - (c1 * 1000000000);
         if c2 > 0 then
            c2_char  := f_sub_1000000000 (to_char(c2));
         else
            c2_char  := null;
         end if;
         out_char := c1_char||' BILLION '||c2_char ;
      else
         out_char  := f_sub_1000000000 (in_char);
      end if;
      return(out_char) ;
end;
BEGIN
   if to_number(in_char) = 0 then
      return ('ZERO');
   end if;
   amt_with_cents := to_number(in_char);
   full_amt := to_char(amt_with_cents, '9999999999990.90');
   if to_number(substr(full_amt, 1, instr(full_amt, '.')-1)) <> 0 then
      dollars := to_char(to_number(substr(full_amt, 1, instr(full_amt, '.')-1)));
   else
      dollars := '0';
   end if;
   if to_number(substr(full_amt, instr(full_amt, '.')+1)) <> 0 then
--      cents := ' AND PAISA '||to_char(to_date(substr(full_amt, -2, 2), 'J'), 'JSP');
      cents := 'SAUDI RIYALS AND '||to_char(to_date(substr(full_amt, -2, 2), 'J'), 'JSP')||' HALALA(s) ONLY ';
   else
      cents := null;
   end if;
   len   := length(dollars);
   c_num := to_number(dollars);
   if dollars = '0' then
      return('ZERO '||cents);
   elsif c_num < 1000  and cents is null then
      return(f_sub_1000(dollars)||' SAUDI RIYALS ONLY'||cents);
   elsif c_num < 1000 then
      return(f_sub_1000(dollars)||' '||cents);
   elsif c_num >= 1000 and c_num < 1000000 and cents is null then
      return(f_sub_1000000(dollars)||' SAUDI RIYALS ONLY'||cents);
   elsif c_num >= 1000 and c_num < 1000000 then
      return(f_sub_1000000(dollars)||' '||cents);
   elsif c_num >= 1000000 and c_num < 1000000000 and cents is null then
      return(f_sub_1000000000(dollars)||' SAUDI RIYALS ONLY'||cents);
   elsif c_num >= 1000000 and c_num < 1000000000 then
      return(f_sub_1000000000(dollars)||' '||cents);
   elsif c_num >= 1000000000 and c_num < 1000000000000 and cents is null then
      return(f_sub_1000000000000(dollars)||' SAUDI RIYALS ONLY'||cents);
   elsif c_num >= 1000000000 and c_num < 1000000000000 then
      return(f_sub_1000000000000(dollars)||' '||cents);
   else
      return('the number is too large !');
   end if;
END;
/