Tuesday, 19 May 2015

How to print certain string based on the value in oracle


Requirement:- I want to Print the text Senior Manager when the text is Senior Manager. Division No:7

Solution:- select SUBSTR(NAME,0,INSTR(NAME,'.')-1) JOB from per_jobs

Output:-JOB

Deputy General Manager
Deputy Manager
General Manager
Manager
Managing Director
Senior Manager

Monday, 18 May 2015

How to change the date format as DD-MON-YYYY, when you are passing as parameter and printing in the output


How to change the date format as DD-MON-YYYY, when you are passing as parameter and printing in the output in XML PUBLISHER or BI PUBLISHER.

Requirement:- I want the date format to be printed as DD-MON-YYYY in the output. But the date is a parameter and  there is no database column for this one.

In the output the date was printing like this:
2015-01-01T00:00:00.000+05:30

I want this to be printed as 01-JAN-2015

When I use <?xdofx:to_char(trunc(P_FROM_DATE),'DD-MON-YYYY')?>
it was coming as 31-Dec-2014
that means - 1 date.

Solution:- The solution for this is:

<?format-date:P_FROM_DATE;'dd-MMM-yyyy';'Asia/Calcutta'?>

By using the above xml tag, I am able to print the date as 01-Jan-2015.

I got the solution in this way, I am happy if it helps to anyone by seeing my post.

Friday, 17 April 2015

How to find the concurrent program and concurrent program short name using the query

select fcpt.user_concurrent_program_name, fcp.concurrent_program_name from
fnd_concurrent_programs_tl fcpt,
fnd_concurrent_programs fcp
where
fcp.CONCURRENT_PROGRAM_ID= fcpt.CONCURRENT_PROGRAM_ID
and
fcpt.created_by =1706



Profile Value in oracle apps


If you want the query to display the data from different org_id's dont use org_id hardcoded in your query. Use Profile value for this.


SELECT  sum(AIA.invoice_amount)                       INVOICE_AMT
             ,sum(NVL(AIPA.amount,APSA.amount_remaining))   PAYMENT_AMT
            FROM
                   ap_invoices_all AIA
                  ,ap_checks_all ACA
                  ,ap_invoice_payments_all AIPA
                  ,ap_payment_schedules_all APSA
                  ,pa_projects_all PPA
             WHERE AIA.invoice_id = AIPA.invoice_id (+)
             AND APSA.invoice_id  = AIA.invoice_id
             AND AIA.vendor_id    = NVL(:P_SUPPLIER_NAME,AIA.vendor_id)
             AND AIA.vendor_site_id = NVL(:P_SUPPLIER_SITE_NAME, AIA.vendor_site_id)
             AND NVL(ACA.check_date,SYSDATE) >= NVL(:P_FROM_DATE,NVL(ACA.check_date,SYSDATE))
             AND NVL(ACA.check_date,SYSDATE) <= NVL(:P_TO_DATE,NVL(ACA.check_date,SYSDATE))
             AND AIPA.check_id = ACA.check_id (+)
             AND AIA.project_id = PPA.project_id (+)
             AND AIA.invoice_type_lookup_code = 'STANDARD'
           AND AIA.org_id = FND_PROFILE.value('ORG_ID')
             GROUP BY AIA.vendor_id, AIA.vendor_site_id,aia.org_id
             

Combination of replace and regexp_replace


The Combination of using replace and regexp_replace

SELECT    
         clause CLAUSE, regexp_replace(REPLACE(replace(replace(replace(replace(replace(tc_description,'<br>',chr(10)),'<br/>',chr(10)),'<br />',chr(10)),
          '</br>',chr(10)),'</ br>',chr(10)),'P_OP_MARGIN',NVL(:CP_OPERATING_MARGIN,'8')),'&', '\&'||'amp;') TC_DESCRIPTION
         FROM
         BRITANNIA_TERM_CONDTION_MSTR NTCM
         ,britannia_term_clause_mstr  NTCLM
         WHERE
         NTCM.status                 = 1
         AND NTCLM.status            = 1
         AND TC_TYPE                 = 15
         AND TC_NAME = 127
           AND NTCM.term_condition_id  = NTCLM.TERM_CONDITION_ID
         ORDER BY CLAUSE;

Items Uploading to MTL_SYSTEM_ITEMS_B

Items Uploading

1.     Prepare the Flex Data
2.     Prepare the Item Data
3.     Move the csv’s into the server.
4.     Go to BRITANNIA Inventory Super User Responsibility and run the concurrent program BRITANNIA ITEM FLEX LOADER
And BRITANNIA Item Flex Conversion.
5.     Check the Flex has been created or not using the query
select 
attribute1,attribute2,attribute3,description_attribute3,attribute4,description ,status
 from xxBRITANNIA_flex_item_stg
where trunc(creation_date)=trunc(sysdate)
and attribute1 ='99'
and status='PROCESSED';
6.     Run the BRITANNIA ITEM LOADER Concurrent Program and provide the path of the file in the Parameter.
7.     Run the BRITANNIA ITEM CONVERSION Concurrent Program and after that Run the IMPORT ITEMS Concurrent Program.
This has to be run in the Master Organization using Change Organization and the items have been loaded. Check using the Query.
select * from mtl_system_items_b
where trunc(creation_date)=trunc(sysdate)
and organization_id=84
8.     After that run the concurrent Program Assign Items to the Child Organization Concurrent Program and specify the Organization Id for uploading the items.
9.     After that Apply Item Category Assignment using the program.
*********************Item Category Assignment****************
DECLARE
x NUMBER := 0;
CURSOR lcu_items
IS
Select INVENTORY_ITEM_ID, category_id
from MTL_SYSTEM_ITEMS_B MSIB
,MTL_CATEGORIES MC
WHERE TRUNC(MSIB.CREATION_DATE) = TRUNC(SYSDATE)
AND ORGANIZATION_ID = 84
AND MC.segment1 = MSIB.segment1
AND MC.segment2 = MSIB.segment2;
BEGIN
FOR i IN lcu_items LOOP
x := x+1;
UPDATE inv.mtl_item_categories
set category_id = i.category_id
where inventory_item_id = i.inventory_item_id;
end loop;
dbms_output.put_line('Total Update: '||x);
--COMMIT;
END;


Wednesday, 15 April 2015

How to replace & with & amp; in oracle


I have a requirement to display the text in HTML Output. In the item description I was encountering an issue with &, whenever this symbol is present the concurrent program is completing with Warning.

To overcome this issue, we need to change the & symbol with &amp;

Solution:-

select regexp_replace(tc_description,'&', '\&'||'amp;') from xx_table;

The output of the query without replacing the description is:
Installation & Training (Small Library)

Now after changing the query, the output is

Installation &amp; Training (Small Library).


For my requirement the above query has given the result. 

Monday, 9 February 2015

Example on DBMS_XMLGEN in oracle apps using plsql procedure



First create a table and insert values into that table and press on Commit.

Step 1. Create a table
CREATE TABLE demo_products
(  product_code   NUMBER,
   product_name   VARCHAR2 (100));

Step 2. Insert Values

INSERT INTO demo_products
     VALUES (100, ‘TEST DATA’);

Step 3.Commit



Create a PL/SQL Package

-- Package Specification

Step 1. Create a Package Spec & Body with a single Procedure


CREATE OR REPLACE PACKAGE APPS.XX_REPORT_PKG

AS
   PROCEDURE REPORT (errbuf            OUT VARCHAR2,
                     retcode           OUT VARCHAR2,
                     p_product_id   IN     NUMBER);
END XX_REPORT_PKG;



-- Package Body:

CREATE OR REPLACE PACKAGE BODY APPS.XX_REPORT_PKG
AS
   PROCEDURE REPORT (errbuf            OUT VARCHAR2,
                     retcode           OUT VARCHAR2,
                     p_product_id   IN     NUMBER)
   IS
      l_qryCtx      DBMS_XMLGEN.ctxHandle;
      l_query       VARCHAR2 (32000);
      l_length      NUMBER (10);
      l_xmlstr      VARCHAR2 (32000);
      l_offset      NUMBER (10) := 32000;
      l_retrieved   NUMBER (10) := 0;
      l_result      CLOB;
      l_no_rows     NUMBER;
   BEGIN
      l_query := ‘SELECT product_code, product_name
         FROM demo_products
       WHERE product_code = ‘ || p_product_id;
      l_qryCtx := DBMS_XMLGEN.newContext (l_query);

      — set rowset tag to PRODUCTS and row tag to PRO_DETAILS
      DBMS_XMLGEN.setRowSetTag (l_qryCtx, ‘PRODUCTS’);
      DBMS_XMLGEN.setRowTag (l_qryCtx, ‘PRO_DETAILS’);

      — now get the result
      l_result := DBMS_XMLGEN.getXML (l_qryCtx);
      l_no_rows := DBMS_XMLGEN.GETNUMROWSPROCESSED (l_qryCtx);
      FND_FILE.put_line (FND_FILE.LOG, ‘No of rows processed= ‘ || l_no_rows);

      l_length := NVL (DBMS_LOB.getlength (l_result), 0);
      FND_FILE.put_line (FND_FILE.LOG, ‘Length= ‘ || l_length);

      LOOP
         EXIT WHEN l_length = l_retrieved;

         IF (l_length – l_retrieved) < 32000
         THEN
            SELECT SUBSTR (l_result, l_retrieved + 1) INTO l_xmlstr FROM DUAL;

            l_retrieved := l_length;
            fnd_file.put_line (fnd_file.output, l_xmlstr);
         ELSE
            SELECT SUBSTR (l_result, l_retrieved + 1, l_offset)
              INTO l_xmlstr
              FROM DUAL;

            l_retrieved := l_retrieved + l_offset;
            fnd_file.put_line (fnd_file.output, l_xmlstr);
         END IF;
      END LOOP;

      DBMS_XMLGEN.closeContext (l_qryCtx);
   EXCEPTION
      WHEN OTHERS THEN
         FND_FILE.PUT_LINE (FND_FILE.LOG, SQLERRM);
         raise_application_error (-20001, ‘Error in procedure XX_REPORT_PKG.report’);
   END REPORT;
END XX_REPORT_PKG;

Step 2. Define Executable

Navigation: Application Developer > Concurrent > Executable
Provide Executable, Short Name, Application, Description & also
Execution Method: PL/SQL Stored Procedure
Execution File Name: XX_REPORT_PKG.REPORT

Step 3. Define Concurrent Program

Navigation: Application Developer > Concurrent > Program

Provide Program, Short name, Application, Description & also
– Executable Name as defined in the above step

– Output Format should be XML
– Define a Parameter p_product_id
– Associate Concurrent Program to the Request Group.

Step 4. Create Data Definition

Navigation: XML Publisher Administrator -> Data Definitions -> Create Data Definition
The code should be exactly same as concurrent program short name.

Step 5. Create Template. Register Template with the XML Publisher

Navigation: XML Publisher Administrator -> Templates -> Create Template

RTF can be created using the XML file from the Output of the concurrent Program.

Step 6. Run the Concurrent Program to see the output

Developing sample XML Publisher Report with Executable Method as ‘PL/SQL Stored Procedure‘

In how many ways we can link the requisition to purchase order in oracle ebs

 In Oracle E-Business Suite (EBS) R12 / R12.2, a Purchase Requisition can be joined to a Purchase Order across 4 primary levels , depending ...