Tuesday, 21 March 2017

Oracle Apps: Sample Concurrent Program Shell script to call multiple SQL scripts

In one of my project, the client to wanted to have a Host Concurrent Program, which calls multiple sql statements. It was easy to create one shell script which calls multiple sql statements. But the client wanted the concurrent program to fail (complete in ERROR status), if any of the sql statements fail (not just the last one).

A sample code which we used in this scenario:
 #!/bin/ksh  
 
 #Do whatever you want here  
 echo Connecting to apps...  
 
 sql_output=`sqlplus -s /nolog <<EOF  
 
 connect apps/$PASSWORD  
 
 prompt getting sysdate value into a variable...  
 COLUMN today NOPRINT NEW_VALUE g_today  
 SELECT to_char(sysdate,'DD-MON-YYYY') today  
 FROM dual;  
 
 set serveroutput on size 1000000  
 
 prompt get the count from debug table...  
 select count(*) from xxaj_debug;  
 
 prompt truncate debug table...  
 truncate table xxaj_debug1;  
 
 prompt populate temporary table...  
 insert into xxaj_debug values (xxaj_seq.nextval, 'Anoop', sysdate);   
 
 update xxaj_debug  
 set msg = 'Anoop Johny';  
 
 COLUMN old_count NOPRINT NEW_VALUE g_old_count  
 select count(*) old_count from xxaj_debug;  
 delete from xxaj_debug;  
 
 EOF`  
 
 if [ `echo "$sql_output" | egrep 'ORA-[0-9]{5}:' | wc -l` -ne 0 ]   
 then   
 echo "$sql_output"   
 exit 1   
 else   
 echo "$sql_output"   
 exit 0  
 fi   
The above script with exit with status 0 if every sql statement is success.

Now if any of the statement fails, it will return with status 1.



Feel free to point out if anything is missing/wrong in this blog.

Friday, 17 March 2017

Oracle Apps: Organization Hierarchy Query to get the organizations in a specific Hierarchy

The below query can be used to get the Organizations which belongs to a hierarchy which is defined in the Organization Hierarchy.

Thanks to Sajeer Omar.

Replace the below hardcoded values before executing :
Business group ID
Organization Hierarchy Name
Top Organization Name

If you want to get only the organization as a specific level, uncomment the commented whereclause.
 select (lpad(' ', (lvl - 1) * 5, ' ') || haou_c.name) org_name  
        ,org_hier.*  
 from  hr_all_organization_units haou_c  
      ,(select hier.organization_id_parent  
              ,hier.organization_id_child  
              ,level lvl  
              ,sys_connect_by_path(hier.organization_id_child, '/') org_level  
              ,sys_connect_by_path(level, '/')                      hier_level  
        from  per_org_structure_elements hier  
             ,(select vers.org_structure_version_id  
               from  per_organization_structures_v struct  
                    ,per_org_structure_versions_v  vers  
               where struct.business_group_id = 0 -- Business group ID  
               and  struct.name = 'AJ Hierarchy' -- Organization Hierarchy Name  
               and  struct.organization_structure_id = vers.organization_structure_id  
               and  struct.business_group_id = vers.business_group_id  
               and  SYSDATE BETWEEN vers.date_from and nvl(vers.date_to, sysdate)  
               and  rownum = 1) orgstr  
        where hier.org_structure_version_id = orgstr.org_structure_version_id  
        and  hier.business_group_id = 0 -- Business group ID  
        start with hier.organization_id_parent =  
                                                (select a.organization_id  
                                                 from  hr_all_organization_units a  
                                                 where a.name = 'AJ Pty Ltd (Australia)') -- Top Organization Name  
              and  hier.org_structure_version_id = orgstr.org_structure_version_id  
              and  hier.business_group_id = 0 -- Business group ID  
        connect by prior organization_id_child = organization_id_parent) org_hier  
 where haou_c.organization_id = org_hier.organization_id_child  
 --and  org_hier.lvl = 2 -- If you want to get only a specific level values  
 order by org_hier.org_level;  


Feel free to point out if anything is missing/wrong in this blog.




Tuesday, 7 March 2017

OAF: oracle.apps.fnd.framework.OAException: oracle.jbo.NameClashException: JBO-25001: Name LOV_oracle_apps_xx_xxx_server_XXXXXXXAM of object type ApplicationModule already exists

In one of my project, the client was getting the below error when opening an OA Page. Since the issue was not a straight forward case, I thought of adding the issue to the blogpost.

Error when opening the OA Page:
 oracle.apps.fnd.framework.OAException: oracle.jbo.NameClashException: JBO-25001: Name LOV_oracle_apps_xx_xxx_server_XXXXXXXAM of object type ApplicationModule already exists  
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1247)  
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(OAPageErrorHandler.java:1435)  
         at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2736)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1963)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:557)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:439  
         at _OA._jspService(_OA.java:213)  
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)  
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)  
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)  
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)  
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)  
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)  
         at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)  
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)  
         at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:429)  
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:642)  
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)  
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:911)  
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458)  
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)  
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)  
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)  
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)  
         at java.lang.Thread.run(Thread.java:745)  
 ## Detail 0 ##  
 oracle.apps.fnd.framework.OAException: oracle.jbo.NameClashException: JBO-25001: Name LOV_oracle_apps_xx_xxx_server_XXXXXXXAM of object type ApplicationModule already exists  
         at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:912)  
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1169)  
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(OAPageErrorHandler.java:1435)  
         at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2736)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1963)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:557)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:439)  
         at _OA._jspService(_OA.java:213)  
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)  
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)  
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)  
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)  
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)  
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)  
         at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)  
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)  
         at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:429)  
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:642)  
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)  
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:911)  
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458)  
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)  
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)  
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)  
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)  
         at java.lang.Thread.run(Thread.java:745)  
 oracle.apps.fnd.framework.OAException: oracle.jbo.NameClashException: JBO-25001: Name LOV_oracle_apps_xx_xxx_server_XXXXXXXAM of object type ApplicationModule already exists  
         at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:912)  
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1169)  
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(OAPageErrorHandler.java:1435)  
         at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2736)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1963)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:557)  
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:439)  
         at _OA._jspService(_OA.java:213)  
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)  
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:390)  
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)  
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)  
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)  
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)  
         at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)  
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)  
         at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:429)  
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:642)  
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:391)  
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:911)  
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:458)  
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)  
         at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)  
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)  
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)  
         at java.lang.Thread.run(Thread.java:745)  

In this case : 

Problem : The specified AM,  oracle.apps.xx.xxx.server.XXXXXXXAM, ( which was an AM associated with an external LOV region in the page) was substituted in the Application for another page. AM Substitution is like a site level Personalization as it applies to all the pages where the AM is referenced.

Solution : Remove the AM Substitution.

Note: In this specific case, we were able to replace the AM Substitution with just VO Substitution.

I have seen several cases, where AM Substitution is done, things start failing in the page. Especially, if there is a LOV in the page, you might get different types of errors which will be difficult to debug.



Feel free to point out if anything is missing/wrong in this blog.

Saturday, 4 March 2017

PL/SQL: Some helpful SQL queries -2

Continuation of PL/SQL: Some helpful SQL queries -1

#7. How to convert Multiple Columns into Rows (Unpivot multiple columns). 
Source Data


Expected output

 with t as  
 (select '1001' emp_no,'Anoop' emp_first_name, 'Johny' emp_last_name
        ,'Developer' job_role, 'Senior Developer' new_job_role  
        ,'150000'    salary  , '175000'           new_salary 
        ,'Australia' country , 'Australia'        new_country  
  from dual  
  union  
  select '1002' emp_no,'Sajeer' emp_first_name, 'Omar' emp_last_name
       ,'Senior Developer' job_role, 'Developer' new_job_role  
       ,'105000'           salary  , '100000'    new_salary 
       ,'Australia'        country , 'Australia' new_country   
  from dual  
 )
 select (case when row_number() over (partition by emp_no order by emp_no ) = 1    
              then emp_no   
         end) emp_no  
       ,(case when row_number() over (partition by emp_no order by emp_no ) = 1    
              then emp_first_name   
         end) emp_first_name  
       ,(case when row_number() over (partition by emp_last_name order by emp_no ) = 1    
              then emp_last_name   
         end) emp_last_name   
       ,col     detail  
       ,val     old_value  
       ,new_val new_value  
 from t    
 unpivot include nulls ((val,new_val) for col in ((job_role,new_job_role) as 'Job Role'  
                                                 ,(salary,new_salary)     as 'Salary'  
                                                 ,(country,new_country)   as 'Country'));  

Refer:
PIVOT and UNPIVOT Operators in Oracle Database 11g Release 
Pivot and Unpivot


Feel free to point out if anything is missing/wrong in this blog.