Friday, January 24, 2014

LEFT OUTER JOIN: Oracle HR Employee Phones


If you ever worked with PER_PHONES table in Oracle EBS to get the employee phones, you must have seen that PER_PHONES table contains multiple lines for different phone types for an employee.

For example, if I run the following query for an employee whose PERSON_ID is 1444, I get three records:

SELECT *
  FROM PER_PHONES p
 WHERE p.parent_id = 1444;





You can run the following query to get the meaning of the phone types:

SELECT lookup_type,
       lookup_code,
       meaning
  FROM HR_LOOKUPS
 WHERE enabled_flag = 'Y'
   AND lookup_type  = 'PHONE_TYPE';















Now the problem is, when you connect this PER_PHONES (parent_id) table with PER_ALL_PEOPLE_F (person_id) table , you end up with multiple rows. In the above example, it will return three rows.

Now of course, the client will never want to see more than one row per employee. In my case, the client specifically asked for a condition which goes like: pick up Mobile Phone of the employee first; if Mobile Phone is NULL, then pick up Home Phone; if Home Phone is NULL, then pick up Work Phone, and so on.

I assumed that there would already be a view for this from Oracle. Since I did not find any, I had to come up with a query (to create a custom view) to avoid multiple rows per employee, using LEFT OUTER JOIN function.


SELECT
       pp.parent_id      parent_id,
       pp.parent_table   parent_table,
       --
       ppm.phone_number  mobile_phone,
       pph.phone_number  home_phone,
       ppw.phone_number  work_phone,
       ppo.phone_number  other_phone
  FROM
       (SELECT DISTINCT
               parent_id,
               parent_table
          FROM per_phones
       ) pp
  -- mobile phone
  LEFT OUTER JOIN per_phones  ppm
    ON (     ppm.phone_type   = 'M'
         AND ppm.parent_id    = pp.parent_id
         AND ppm.parent_table = pp.parent_table
       )
  -- home phone
  LEFT OUTER JOIN per_phones  pph
    ON (     pph.phone_type   = 'H1'
         AND pph.parent_id    = pp.parent_id
         AND pph.parent_table = pp.parent_table
       )
  -- work phone
  LEFT OUTER JOIN per_phones  ppw
    ON (     ppw.phone_type   = 'W1'
         AND ppw.parent_id    = pp.parent_id
         AND ppw.parent_table = pp.parent_table
       )
  -- other phone
  LEFT OUTER JOIN per_phones  ppo
    ON (     ppo.phone_type   = 'O'
         AND ppo.parent_id    = pp.parent_id
         AND ppo.parent_table = pp.parent_table
       )
 WHERE 1 = 1;





Hopefully, this is helpful. However, if there is any other query which may be useful, I would certainly love to hear or know about it.

Monday, January 06, 2014

BI Publisher Bursting


The following article, written by Gareth Roberts, is probably one of the best and most elaborate articles I have ever come across for BI Publisher's bursting feature. Very well written, step by step with screenshots and explanations.

http://garethroberts.blogspot.com/2008/03/bi-publisher-ebs-bursting-101.html

Thursday, December 19, 2013

Oracle R12 EB-Tax SQL Query


Following is a link for all EB-Tax related tables:

http://oracleappscommunity.com/oracle/blog/1181/e-business-tax-tables


I found another useful query at Oracle Apps Knowledge Sharing website, which I have updated for my own requirement.

http://www.shareoracleapps.com/2013/04/e-business-tax-query-taxrate-based-on-operating-unit-r12-oracleapps.html


SELECT hou.organization_id            org_id,
       led.name                       ledger,
       hou.name                       operating_unit,
       --
       zxr.tax_regime_code            tax_regime_code,
       zxr.tax                        tax_code,
       zxr.tax_status_code            tax_status_code,
       zxr.tax_rate_code              tax_rate_code,
       zxr.tax_jurisdiction_code      tax_jurisdiction_code,
       --
       zxr.rate_type_code             rate_type_code,
       zxr.percentage_rate            percentage_rate,
       zxr.effective_from             rate_effective_from,
       zxr.effective_to               rate_effective_to,
       --
       acc.tax_account_ccid           tax_account_ccid,
       gcc.concatenated_segments      tax_account
  FROM
       zx_rates_vl                  zxr,
       zx_accounts                  acc,
       hr_operating_units           hou,
       gl_ledgers                   led,
       xxrl_gl_code_combinations_v  gcc
 WHERE
       1=1
   --
   -- AND zxr.tax_regime_code = 'UK VAT'
   -- AND zxr.tax_rate_code = 'UK_AR_DOM'
   --
   AND acc.tax_account_entity_code = 'RATES'
   AND zxr.active_flag = 'Y'
   AND TRUNC (SYSDATE) BETWEEN
          TRUNC (zxr.effective_from) AND
          NVL (TRUNC (zxr.effective_to), TRUNC (SYSDATE) + 1)
   --
   AND led.ledger_id = hou.set_of_books_id
   AND gcc.code_combination_id = acc.tax_account_ccid
   AND hou.organization_id = acc.internal_organization_id
   AND acc.tax_account_entity_id = zxr.tax_rate_id
   --
   ;
  

Concurrent Programs Warning-Error: ERRBUFF and RETCODE


The ERRBUFF can be returned with any message.

The RETCODE can be returned with one of three values:

   0  -- Success
   1  -- Warning
   2  -- Error

Below is an example of a package where I can pass an employee number and it can return its full name. If no data found for the employee number passed, the concurrent program will turn YELLOW with the message 'No Employee Found'. If there is any other error occurs, it will turn RED with SQLERRM message.

----------------------------------------------------------
-- Package Specification
----------------------------------------------------------
CREATE OR REPLACE PACKAGE apps.emp_test_pkg
IS
   FUNCTION emp_name (
      errbuff       OUT  NOCOPY  VARCHAR2,
      retcode       OUT  NOCOPY  VARCHAR2,
      p_emp_number  IN           NUMBER)
      RETURN  VARCHAR2;
    
END emp_test_pkg;

/

----------------------------------------------------------
-- Package Body
----------------------------------------------------------
CREATE OR REPLACE PACKAGE BODY apps.emp_test_pkg
IS
 
   FUNCTION emp_name (
      errbuff       OUT  NOCOPY  VARCHAR2,
      retcode       OUT  NOCOPY  VARCHAR2,
      p_emp_number  IN           NUMBER)
      RETURN  VARCHAR2
   IS
      lv_emp_name   VARCHAR2(300DEFAULT  NULL;
    
   BEGIN
       
      SELECT (papf.first_name || ' ' || papf.last_name)
        INTO lv_emp_name
        FROM per_all_people_f  papf
       WHERE 1=1
         AND papf.employee_number = p_emp_number;
    
      RETURN (lv_emp_name);
    
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         errbuff := 'No employee found for ' || p_emp_number;
         retcode := '1';        -- warning
       
         fnd_file.put_line(fnd_file.log, errbuff);
         RETURN (lv_emp_name);
       
      WHEN OTHERS THEN
       
         errbuff := SQLERRM;
         retcode := '2';        -- error
       
         fnd_file.put_line(fnd_file.log, errbuff);
         RETURN (lv_emp_name);
 
   END emp_name;
 
END emp_test_pkg;
/


Wednesday, December 18, 2013

Oracle HR related API List


Recently I had to work on lot of HR related interfaces, which use Oracle APIs. While I was working on the interfaces, I came across with the following website by Puneet Rajkumar, which I thought a very good resource for all HRMS related APIs. He provided some easy good examples.

https://blogs.oracle.com/prajkumar/entry/oracle_hrms_apis


You can also refer to Oracle article for more information:
Note: 179243.1 - Application Programmatic Interfaces (APIs) in Oracle HRMS


Or, you can run the following query:

SELECT SUBSTR (ds.owner, 1, 20)   owner,
       SUBSTR (ds.name, 1, 30)    object_name,
       SUBSTR (ds.type, 1, 20)    object_type,
       SUBSTR (do.status, 1, 10)  status,
       do.last_ddl_time           last_ddl
  FROM dba_source  ds,
       dba_objects do
 WHERE 1 = 1
   --
   AND ds.name = do.object_name
   AND ds.type = do.object_type
   --
   AND ds.text LIKE '%Header%'
   AND ds.type = 'PACKAGE BODY'
   AND ds.name LIKE 'HR_%API%'
   --
 ORDER BY ds.owner, ds.name;