Wednesday, February 19, 2020

PL/SQL Scripts to Register Concurrent Program, Executable, Parameters using API


Using API (FND_PROGAM)  you will create a concurrent program, executable, and add parameters to existing program.

Also delete a concurrent program and executable using API


Below are sample PLSQL scripts. 
--1) Register an Executable

DECLARE
    lc_executable_name      VARCHAR2(240)  := 'Daily Claim Report';
    lc_short_name                VARCHAR2(50)    := 'XX007CLAIM';
    lc_application_name     VARCHAR2(240)   := 'XXPO';  -- Short name
    lc_description                 VARCHAR2(240)   := 'Claim Report';
    lc_executable_method   VARCHAR2(240)  := 'PL/SQL Stored Procedure';
    lc_execution_file_name VARCHAR2(45)    := 'XX007_Claim.main';
    lc_language_code           VARCHAR2(5)       := 'US';   -- Default Value is 'US'  
    ln_executable_id              NUMBER            := 0;
BEGIN
       FND_PROGRAM.EXECUTABLE
                          (executable                     => lc_executable_name,
                           application                     => lc_application_name,
                           short_name                   => lc_short_name,
                           description                     => lc_description,
                           execution_method       => lc_executable_method,
                           execution_file_name    => lc_execution_file_name,
                           subroutine_name         => NULL,
                           icon_name                     => NULL,
                           language_code              => lc_language_code
                           );
        COMMIT;
        --
        -- To check whether Concurrent Executable is registered or not
        --
        BEGIN
    SELECT executable_id INTO ln_executable_id
            FROM fnd_executables
   WHERE executable_name = 'XX007CLAIM'
        AND application_id = (SELECT application_id FROM fnd_application
                                      WHERE application_short_name = 'XXPO');
        EXCEPTION
        WHEN others THEN
dbms_output.put_line('Error in Executable: '||SQLERRM);
END;
        --
--
EXCEPTION
        WHEN others THEN
        dbms_output.put_line('Error: '||SQLERRM);
END;
/



--2) Register a Concurrent Program


DECLARE 
  --
  lc_program                            VARCHAR2(240);
  lc_application                        VARCHAR2(10);
  lc_enabled                             VARCHAR2(5);
  lc_short_name                       VARCHAR2(30);
  lc_description                        VARCHAR2(240);
  lc_executable_short_name    VARCHAR2(30);
  lc_executable_application     VARCHAR2(10);
  lc_save_output                       VARCHAR2(5);
  lc_print                                  VARCHAR2(5);
  lc_style_required                   VARCHAR2(5);
  lc_use_in_srs                         VARCHAR2(5);
  lc_allow_disabled_values     VARCHAR2(5);
  lc_run_alone                          VARCHAR2(5);
  lc_output_type                       VARCHAR2(30);
  lc_enable_trace                      VARCHAR2(5);
  lc_restart                                VARCHAR2(5);
  lc_nls_compliant                    VARCHAR2(5);
  lc_language_code                  VARCHAR2(20);
  ln_executable_id                    NUMBER;
  lc_check                                 VARCHAR2(5) := NULL;
  --
BEGIN
  --
  lc_program                            := 'Daily Claim Report XX007';
  lc_application                        := 'XXPO';
  lc_enabled                             := 'Y';
  lc_short_name                       := 'XX007CLAIM';
  lc_description                        := 'OracleAppsDNA Test Program';
  lc_executable_short_name    := 'XX007CLAIM';
  lc_executable_application     := 'XXPO';
  lc_save_output                      := 'Y';
  lc_print                                  := 'Y';
  lc_style_required                   := 'N';
  lc_use_in_srs                         := 'Y';
  lc_allow_disabled_values     := 'N';
  lc_run_alone                          := 'N';
  lc_output_type                      := 'TEXT';
  lc_enable_trace                     := 'Y';
  lc_restart                               := 'Y';
  lc_nls_compliant                   := 'Y';
  lc_language_code                 := 'US';
  ln_executable_id                  := 0;
 --
 -- Executable is mandatory to create  Concurrent Program:
    BEGIN
                SELECT executable_id INTO ln_executable_id
                FROM fnd_executables
                WHERE executable_name = 'XX007CLAIM'
                  AND application_id = (SELECT application_id FROM fnd_application
                                                        WHERE application_short_name = 'XXPO');
    EXCEPTION
                  WHEN others THEN
                  dbms_output.put_line('Error in Executable: '||SQLERRM);
    END;
 --
 --Calling API to create concurrent program definition
 --
 apps.fnd_program.register
        (program                         => lc_program,
         application                     => lc_application,
         enabled                          => lc_enabled,
         short_name                    => lc_short_name,
         description                     => lc_description,
         executable_short_name => lc_executable_short_name,
         executable_application  => lc_executable_application,
         execution_options          => NULL,
         priority                           => NULL,
         save_output                   => lc_save_output,
         print                              => lc_print,
         cols                               => NULL,
         ROWS                          => NULL,
         STYLE                         => NULL,
         style_required               => lc_style_required,
         printer                           => NULL,
         request_type                  => NULL,
         request_type_application  => NULL,
         use_in_srs                      => lc_use_in_srs,
         allow_disabled_values   => lc_allow_disabled_values,
         run_alone                      => lc_run_alone,
         output_type                   => lc_output_type,
         enable_trace                  => lc_enable_trace,
         restart                            => lc_restart,
         nls_compliant                 => lc_nls_compliant,
         icon_name                     => NULL,--
         language_code                 => lc_language_code,
         mls_function_short_name   => NULL,
         mls_function_application   => NULL,
         incrementor                   => NULL,
         refresh_portlet               => NULL
         ); 
  --
  COMMIT;
  --To check whether Concurrent Program is registered or not
  --
         BEGIN
             SELECT 'Y'
             INTO lc_check
             FROM fnd_concurrent_programs
             WHERE concurrent_program_name = 'XX007CLAIM'
                  AND application_id = (SELECT application_id FROM fnd_application
                                                   WHERE application_short_name = 'XXPO');
             --
             DBMS_OUTPUT.put_line ('Concurrent Program Registered Successfully');
             --
        EXCEPTION
             WHEN NO_DATA_FOUND THEN
             dbms_output.put_line ('Concurrent Program Registration Failed');
        END;
END;

/



--3) Add parameters to created Concurrent Program.

       BEGIN
             FND_PROGRAM.PARAMETER
                    (program_short_name     => 'XX007CLAIM',
                     application               => 'XXPO',
                     sequence                  => 10,
                     parameter                 => 'Claim_Num',
                     description               => 'Claim Number',   --DEFAULT NULL,
                     enabled                     => 'Y',                       --DEFAULT 'Y',
                     value_set                  => '15 Characters',    -- this is existing value set name
                      default_type             => NULL,             -- DEFAULT NULL,
                     default_value           => NULL,             -- DEFAULT NULL,
                     required                    => 'N',                   -- DEFAULT 'N',
                     enable_security        => 'N',                   -- DEFAULT 'N',
                     range                        => NULL,             --DEFAULT NULL,
                     display                     => 'Y',                    --DEFAULT 'Y',
                     display_size             => 15,
                     description_size       => 50,
                     concatenated_description_size => 25,
                     prompt                   => 'Claim_Num',      --DEFAULT NULL,
                     token                      => NULL                  --DEFAULT NULL
                  );
              COMMIT;
       EXCEPTION
              WHEN others THEN
              dbms_output.put_line('Parameter not added.');
       END;
       /



--4) Delete a concurrent Program and Executable using API:

DECLARE
   v_short_name   VARCHAR2 (50) := 'XX007CLAIM';
   v_app_full_name VARCHAR2(80) := 'Custom PO';
BEGIN
   --
   -- API call to delete Concurrent Program:
   --
     fnd_program.delete_program ( v_short_name,v_app_full_name);
     dbms_output.put_line ('Concurrent Program successfully Deleted: ' || v_short_name);
   --
   --API call to delete Executable
   --
     fnd_program.delete_executable (v_short_name, v_app_full_name);
     dbms_output.put_line ('Executable successfully Deleted: ' || v_short_name);
   
END;
/

Sunday, February 16, 2020

Using Trigger restrict to drop table


Using BEFORE DROP Trigger you will restrict to drop database objects.

When a user connected as XX tries to drop a database object, the database fires the trigger before dropping the object.

Example:
    
       1) Create table:
       
          Create Table xx.xx_test_007
               (emp_no NUMBER,
                emp_name VARCHAR2(200),
                doj DATE
               );

       Output: table XX.XX_TEST_007 created.

      2) Create Trigger   

          Schema Name:  XX
     
         CREATE OR REPLACE TRIGGER drop_trigger
         BEFORE DROP ON XX.SCHEMA
         BEGIN
            RAISE_APPLICATION_ERROR (
               num => -20000,
               msg => 'Cannot drop object');
         END;
        /
   
      Output: TRIGGER DROP_TRIGGER compiled

      3) Try to drop table PO.XX_TEST_007
   
        DROP TABLE XX.XX_TEST_007;

      Output:

               SQL Error: ORA-00604: error occurred at recursive SQL level 1
               ORA-20000: Cannot drop object
               ORA-06512: at line 2
               00604. 00000 -  "error occurred at recursive SQL level %s"
               *Cause:    An error occurred while processing a recursive SQL statement
                          (a statement applying to internal dictionary tables).
               *Action:   If the situation described in the next error on the stack
                          can be corrected, do so; otherwise contact Oracle Support.


Calling JAVA class using Oracle database


--1) JAVA Class use in PLSQL block using Function:

       Using PLSQL you can run Java stored procedures in the same way as PLSQL stored procedures.
       In oracle database, Java is usually invoked through PLSQL interface.
     
       -- 1) Create Java class

              CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Technical" AS
              public class Technical
             {
                public static String test007()
               {
                return "Oracle Technical";
               }
            };
            /

       -- 2) Create PLSQL Function to call Java class

             CREATE OR REPLACE FUNCTION Technicaltest007
             RETURN VARCHAR2 AS
                LANGUAGE JAVA NAME 'Technical.test007 () return java.lang.String';
             /

      -- 3) Write PLSQL Block to call created Function
     
             SET SERVEROUTPUT ON;
             DECLARE
                   lc_string VARCHAR2(300);
             BEGIN
                   lc_string := Technicaltest007();
                   dbms_output.put_line('The value of the string is:'||lc_string);
             END;
           /

Saturday, February 15, 2020

PLSQL script to find out all Weekends of the Year

 FIND ALL SATURDAY AND SUNDAY OF YEAR

 Example:

     DECLARE
         ln_year NUMBER := &YEAR;
         ld_day  DATE;
     BEGIN
         ld_day := TO_DATE('01-JAN-'||TO_CHAR(ln_year), 'DD-MON-YYYY');
         WHILE ld_day < TO_DATE('31-DEC-'||TO_CHAR(ln_year), 'DD-MON-YYYY')
LOOP
           IF TO_CHAR(ld_day, 'D') IN (1,7) THEN
              dbms_output.put_line(TO_CHAR(ld_day));
           END IF;
           ld_day := ld_day + 1;
         END LOOP;
     END;
     /

Display row data in column using SQL query

By using Union ALL you will display row format records in column.

Below is an Example:
Follow below steps to convert row in column-

Step 1) Create Table and insert record:

         CREATE TABLE xx_emp_data ( emp_name VARCHAR2(50)
                                                              , emp_number VARCHAR2(50)
                                                              , salary NUMBER
                                                             );

          INSERT INTO xx_emp_data VALUES ('Sunil', 'EMP_007', 60000);
          COMMIT;

          SELECT * FROM xx_emp_data;

          Output:

         -------------------------------------------------------------
         EMP_NAME      EMP_NUMBER      SALARY
  -------------------------------------------------------------
          Sunil                    EMP_007                 60000
          -------------------------------------------------------------

Step 2) Using Union ALL you convert row into column

         SELECT 'Emp_Name' AS ColName,
                          Emp_name AS COLVALUE
          FROM xx_emp_data
          UNION ALL
          SELECT 'Emp_Number' AS ColName,
                          Emp_Number AS COLVALUE
          FROM xx_emp_data
          UNION ALL
          SELECT 'Salary' as ColName,
                          CAST(Salary AS VARCHAR(50)) AS COLVALUE
          FROM xx_emp_data;

        Output:

        ---------------------------------------
        COLNAME        COLVALUE
        ---------------------------------------
        Emp_Name           Sunil
        Emp_Number       EMP_007
        Salary                    60000
        ---------------------------------------

Friday, February 14, 2020

Create Blanket Sales Agreement with multiple lines using API in Oracle

Blanket Sales Agreement (BSA):
              BSA's are used when you have specific feature or quality to a purchasing BSA between a Supplier and a Customer.
              These features include the date range of the agreement, the items details included, the price of items, quantity of each item, etc.

Before create BSA we need to create Sales Agreement transaction types, create Document sequence.

Here we will create BSA using API:

Example: PLSQL Script to create BSA with Active status.

SET SERVEROUTPUT ON SIZE 999999;
DECLARE
   -- Input Variables
       l_hdr_rec                 OE_Blanket_PUB.header_Rec_type;
       l_hdr_val_rec          OE_Blanket_PUB.header_val_Rec_type;
       l_line_tbl                 OE_Blanket_PUB.line_tbl_Type;
       l_line_val_tbl          OE_Blanket_PUB.line_Val_tbl_Type;
       l_line_rec                OE_Blanket_PUB.line_rec_Type;
       l_line_val_rec         OE_Blanket_PUB.line_val_rec_Type;
       l_control_rec           OE_Blanket_PUB.Control_rec_type;
   -- Output Variables
       x_line_tbl                 OE_Blanket_PUB.line_tbl_Type;
       x_header_rec           OE_Blanket_PUB.header_Rec_type;
       x_msg_count           NUMBER;
       x_msg_data             VARCHAR2(2000);
       x_return_status        VARCHAR2(30);
   -- Incremental variables
       i                             NUMBER;
       j                             NUMBER; 
       x                            NUMBER;
    ------
    -- First cursor to get header data.
    -- As per requirement you will change cursor query or use any custom table to provide valid data to API to create BSA.
    -- 1st Cursor
    --
    CURSOR lcur_bsa_header
    IS
          SELECT *
          FROM oe_blanket_headers_all hdr
          WHERE hdr.header_id = 1218952;    -- I took for testing purpose.
 
    -- This cursor related provide line level records to API
    -- 2nd Cursor
    --
    CURSOR lcur_bsa_line (p_header_id IN NUMBER)
    IS
          SELECT *
          FROM oe_blanket_lines_all HL
          WHERE hl.HEADER_ID = p_header_id;
    --
BEGIN
       dbms_output.put_line('Start to creating New BSA:-->'); 
       x := 1;
       fnd_global.apps_initialize (23432, 5456, 254);
                 -- Replace with valid values
       MO_GLOBAL.INIT('ONT'); -- MOAC 

   FOR lreq_hdr IN lcur_bsa_header
   LOOP
       l_hdr_rec                                   := oe_blanket_pub.g_miss_header_rec;
       l_hdr_val_rec                            := oe_blanket_pub.g_miss_header_val_rec;
       l_hdr_rec.operation                   := oe_globals.g_opr_create; -- header operation
       l_hdr_rec.sold_to_org_id          := lreq_hdr.sold_to_org_id;
       l_hdr_rec.order_type_id            := lreq_hdr.order_type_id;
       l_hdr_rec.ship_to_org_id          := lreq_hdr.ship_to_org_id;
       l_hdr_rec.invoice_to_org_id     := lreq_hdr.invoice_to_org_id;
       l_hdr_rec.attribute1                   := 'TEST007';    -- This is reference field, optional
       l_hdr_rec.start_date_active       := SYSDATE ;
       l_hdr_rec.end_date_active        := NULL;
  --
      FOR lreq_line IN lcur_bsa_line(lreq_hdr.header_id)
      LOOP
      --
         l_line_rec                             := oe_blanket_pub.g_miss_blanket_line_rec;
         l_line_val_rec                         := oe_blanket_pub.g_miss_blanket_line_val_rec;
         l_line_rec.operation                   := oe_globals.g_opr_create;
         l_line_rec.sold_to_org_id              := lreq_line.sold_to_org_id;
         l_line_rec.inventory_item_id           := lreq_line.inventory_item_id;
         l_line_rec.order_quantity_uom          := lreq_line.order_quantity_uom;
         l_line_tbl(x)                             := l_line_rec;
         l_line_val_tbl (x)                     := l_line_val_rec;
         x:=x+1;
       --
      END LOOP;

      DBMS_OUTPUT.put_line('line count=' || l_line_tbl.count);
      oe_msg_pub.initialize;
      --
      -- Call API to create BSA
      --
      OE_Blanket_PUB.Process_Blanket(
             p_org_id                  => lreq_hdr.org_id
            ,p_operating_unit     => NULL
            ,p_api_version_number => 1.0
            ,x_return_status      => x_return_status
            ,x_msg_count          => x_msg_count
            ,x_msg_data           => x_msg_data
            ,p_header_rec         => l_hdr_rec 
            ,p_header_val_rec     => l_hdr_val_rec
            ,p_line_tbl              => l_line_tbl
            ,p_line_val_tbl       => l_line_val_tbl
            ,p_control_rec        => l_control_rec
            ,x_header_rec         => x_header_rec
            ,x_line_tbl              => x_line_tbl
            );
--
        FOR K IN 1 .. x_msg_count
        LOOP
            x_msg_data := oe_msg_pub.get( p_msg_index => k, p_encoded => 'F');
            dbms_Output.put_line('Message :'||x_msg_data);
        END LOOP;
        --
        IF x_return_status <> fnd_api.g_ret_sts_success THEN
            dbms_output.put_line('Error in Process blanket.');
            Rollback;
        ELSE
            dbms_output.put_line('New Sales Agreement Number is :'
                                            ||x_header_rec.order_number
                                            ||'(Header ID : '
                                            ||x_header_rec.header_id
                                            ||')'
                                          );
  --
  -- Typical error: Blanket Sales Agreement created in Entered status.
          -- For create BSA in Active status we need to call Workflow API of Submit Draft.
          --
      IF (x_header_rec.order_number IS NOT NULL) THEN
    oe_blanket_wf_util.Submit_Draft(p_header_id   => x_header_rec.header_id,
                            p_transaction_phase_code  => x_header_rec.transaction_phase_code,
                            x_return_status           => x_return_status,
                            x_msg_count               => x_msg_count,
                            x_msg_data                => x_msg_data );
      END IF;
       --
          END IF;
   --
   END LOOP;
   COMMIT;
END;
/

Once script executed successfully then check records in base table using HEADER_ID or BSA Number:

-- Header Table
SELECT * FROM oe_blanket_headers_all
WHERE header_id = 679963;

-- Line Table
SELECT * FROM oe_blanket_lines_all
WHERE header_id = 679963;


Thanks....

Thursday, February 13, 2020

PLSQL package/procedure to get query result in an Excel format

-- PLSQL package/procedure to get query result in an Excel format

You will get query output in an Excel format using PLSQL package/procedure.
For this you need to follow below steps and get an Excel output:

Also need Oracle application to register created package/procedure.

--Step 01) Write a query:

      Here I have wrote Employee Details related query.
     Below query used in Cursor of procedure.

  Exmaple Query:

    SELECT fu.user_name
                 , emp.title
                 , emp.first_name
                 , emp.last_name
                 , emp.full_name
                 , pptt.user_person_type
                 , pbg.name business_group_name
                 , emp.person_id
                 , emp.effective_start_date
                 , emp.effective_end_date
                 , emp.email_address
                 , emp.date_of_birth
                 , emp.employee_number
                 , emp.internal_location
            FROM per_all_people_f emp
                 , fnd_user fu
                 , per_person_types_tl pptt
                 , per_business_groups pbg
            WHERE emp.person_type_id    = pptt.person_type_id
              AND emp.business_group_id = pbg.business_group_id
              AND emp.person_id         = fu.employee_id
              AND pptt.language         = 'US'
              AND (pbg.date_to IS NULL OR pbg.date_to > SYSDATE)
              AND (fu.end_date IS NULL OR fu.end_date > SYSDATE)
              AND emp.person_id   = NVL(p_employee_number,emp.person_id);

Note:    p_employee_number -- is a optional Parameter, used in Concurrent Program.
                                                -- If you need to get data of employee wise then enter employee number.
                                               -- Otherwise you will get data of all active employees.

--Step 02) Write Package Specification:

    CREATE OR REPLACE PACKAGE xx_excel_utility_pkg
    IS
        PROCEDURE print_header_tag_proc(p_mode IN VARCHAR2);
        PROCEDURE print_worksheet_tags_proc(p_mode      IN VARCHAR2,
                                            p_col_count IN NUMBER,
                                            p_sheetname IN VARCHAR2
                                          );
        PROCEDURE begin_row_proc;
        PROCEDURE end_row_proc;
        PROCEDURE print_data_proc(p_datatype IN VARCHAR2,
                                  p_data     IN VARCHAR2,
                                  p_mode     IN VARCHAR2 DEFAULT 'N'
                               );
        PROCEDURE print_doc_properties_tag_proc;
        PROCEDURE print_workbook_tag_proc;
        PROCEDURE print_style_proc;
        PROCEDURE print_style1_proc;
    --
    PROCEDURE xx_employee_data_excel_proc(errbuf   OUT VARCHAR2,
                                              retcode  OUT NUMBER,
      p_employee_number IN VARCHAR2
                                            );
    END xx_excel_utility_pkg;
    /

--Step 03) Write Package Body:

    CREATE OR REPLACE PACKAGE BODY xx_excel_utility_pkg
    IS
        g_file      UTL_FILE.file_type;
        g_report_output VARCHAR2(10):= 'EXCEL';
        g_delimiter     VARCHAR2(1) := '|';
        PROCEDURE print_header_tag_proc(p_mode IN VARCHAR2)
        IS
          BEGIN
            IF (p_mode = 'H')
            THEN
              fnd_file.put_line(fnd_file.output,'<?xml version="1.0"?>');
              fnd_file.put_line(fnd_file.output,'<?mso-application progid="Excel.Sheet"?>');
              fnd_file.put_line(fnd_file.output,'<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"');
              fnd_file.put_line(fnd_file.output,'xmlns:o="urn:schemas-microsoft-com:office:office"');
              fnd_file.put_line(fnd_file.output,'xmlns:x="urn:schemas-microsoft-com:office:excel"');
              fnd_file.put_line(fnd_file.output,'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"');
              fnd_file.put_line(fnd_file.output,'xmlns:html="http://www.w3.org/TR/REC-html40">');
            ELSE
              fnd_file.put_line (fnd_file.output,'</Workbook>');
            END IF;
          END;
        -------------------------------
        PROCEDURE print_worksheet_tags_proc(
                  p_mode      IN VARCHAR2,
                  p_col_count IN NUMBER,
                  p_sheetname IN VARCHAR2
                 )
        IS
        BEGIN
          IF p_mode = 'H' THEN
             fnd_file.put_line(fnd_file.output,'<Worksheet ss:Name="' || p_sheetname || '">');
             fnd_file.put_line(fnd_file.output,'<Table ss:ExpandedColumnCount="'
                                || p_col_count|| '" x:FullColumns="1" x:FullRows="1">'
                               );
          ELSE
             fnd_file.put_line(fnd_file.output, '</Table>');
             fnd_file.put_line(fnd_file.output, '</Worksheet>');
          END IF;
        END;
        -------------------------------
        PROCEDURE begin_row_proc
        IS
        BEGIN
           IF g_report_output = 'EXCEL'
           THEN
              fnd_file.put_line (fnd_file.output, '<Row>');
           END IF;
        END;   
        -------------------------------
        PROCEDURE end_row_proc
        IS
        BEGIN
           IF g_report_output = 'EXCEL'
           THEN
              fnd_file.put_line (fnd_file.output, '</Row>');
           ELSE
              fnd_file.new_line (fnd_file.output);
           END IF;
        END;
        -------------------------------
        PROCEDURE print_data_proc (
           p_datatype   IN   VARCHAR2,
           p_data       IN   VARCHAR2,
           p_mode       IN   VARCHAR2 DEFAULT 'N'
        )
        IS
        BEGIN
           IF g_report_output = 'EXCEL' THEN
              IF p_mode = 'N' THEN
                fnd_file.put_line (fnd_file.output, '<Cell><Data ss:Type="'
                                   || p_datatype
                                   || '">' || TRANSLATE (p_data, '<>', '()')
                                   || '</Data></Cell>'
                                  );
              ELSE
                IF p_mode = 'S2' THEN
                   fnd_file.put_line (fnd_file.output,
                                         '<Cell ss:StyleID="s21"><Data ss:Type="'
                                      || p_datatype || '">'
                                      || TRANSLATE (p_data, '<>', '()')
                                      || '</Data></Cell>'
                                     );
                ELSE
                   fnd_file.put_line (fnd_file.output,
                                         '<Cell ss:StyleID="s24"><Data ss:Type="'
                                      || p_datatype || '">'
                                      || TRANSLATE (p_data, '<>', '()')
                                      || '</Data></Cell>'
                                     );
                END IF;
              END IF;
           ELSE
             fnd_file.put (fnd_file.output, p_data || g_delimiter);
           END IF;
        END;
        --------------------------------------------------------------------------------------------------------------------
        PROCEDURE print_doc_properties_tag_proc
        IS
          v_user_name   VARCHAR2 (240);
        BEGIN
          BEGIN
             SELECT full_name INTO v_user_name
               FROM per_all_people_f
              WHERE person_id = fnd_global.employee_id;
          EXCEPTION
             WHEN OTHERS THEN
                v_user_name := NULL;
          END;
          --
          fnd_file.put_line (fnd_file.output,
              '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">'
             );
          fnd_file.put_line (fnd_file.output, '<Author>'
                             ||v_user_name||' ,'
                             ||fnd_global.user_name
                             ||'</Author>'
                            );
          fnd_file.put_line (fnd_file.output, '<LastAuthor>'
                             ||v_user_name|| ' ,'
                             ||fnd_global.user_name
                             ||'</LastAuthor>'
                            );
          fnd_file.put_line (fnd_file.output, '<Created>'
                             ||TO_CHAR (SYSDATE, 'YYYY-MM-DD')
                             ||'T'
                             ||TO_CHAR (SYSDATE, 'HH24:MI:SS')
                             ||'Z'
                             ||'</Created>'
                            );
          fnd_file.put_line (fnd_file.output, '<Company>Cummins Inc.</Company>');
          fnd_file.put_line (fnd_file.output,
                                '<Description>'
                             || 'Report run on '
                             || SYSDATE
                             || ' by '
                             || v_user_name
                             || '</Description>'
                            );
          fnd_file.put_line (fnd_file.output, '<Version>11.5606</Version>');
          FND_FILE.PUT_LINE (FND_FILE.OUTPUT, '</DocumentProperties>');
        END;
        ------------------------------------------------------------------------------------------------------------------
        PROCEDURE print_workbook_tag_proc
        IS
        BEGIN
          fnd_file.put_line
                (fnd_file.output,
                 '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">'
                );
          fnd_file.put_line (fnd_file.output, '<WindowHeight>9855</WindowHeight>');
          fnd_file.put_line (fnd_file.output, '<WindowWidth>15180</WindowWidth>');
          fnd_file.put_line (fnd_file.output, '<WindowTopX>480</WindowTopX>');
          fnd_file.put_line (fnd_file.output, '<WindowTopY>45</WindowTopY>');
          fnd_file.put_line (fnd_file.output, '<ActiveSheet>1</ActiveSheet>');
          fnd_file.put_line (fnd_file.output,
                             '<ProtectStructure>False</ProtectStructure>'
                            );
          fnd_file.put_line (fnd_file.output,
                             '<ProtectWindows>False</ProtectWindows>'
                            );
          fnd_file.put_line (fnd_file.output, '</ExcelWorkbook>');
        END;
        ------------------------------------------------------------------------------------------------------------------
        PROCEDURE print_style_proc
        IS
        BEGIN
          fnd_file.put_line (fnd_file.output,'<Styles>');
          fnd_file.put_line (fnd_file.output,'<Style ss:ID="Default" ss:Name="Normal">');
          fnd_file.put_line (fnd_file.output,'<Alignment ss:Vertical="Bottom"/>');
          fnd_file.put_line (fnd_file.output,'<Borders/>');
          fnd_file.put_line (fnd_file.output,'<Font/>');
          fnd_file.put_line (fnd_file.output,'<Interior/>');
          fnd_file.put_line (fnd_file.output,'<NumberFormat/>');
          fnd_file.put_line (fnd_file.output,'<Protection/>');
          fnd_file.put_line (fnd_file.output,'</Style>');
          fnd_file.put_line (fnd_file.output,'<Style ss:ID="s23">');
          fnd_file.put_line (fnd_file.output,'<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>');
          fnd_file.put_line (fnd_file.output,'<Font x:Family="Swiss" ss:Bold="1"/>' );
          --  fnd_file.put_line (fnd_file.output,'<Font ss:FontName="Times New Roman" x:Family="Roman" ss:SIZE="25" ss:Bold="1"/>');
          fnd_file.put_line (fnd_file.output,'<Interior ss:Color="#ffb3b3" ss:Pattern="Solid"/>');
          fnd_file.put_line (fnd_file.output,'</Style>');
          fnd_file.put_line (fnd_file.output,'<Style ss:ID="s21">');
          fnd_file.put_line (fnd_file.output,'<Font ss:SIZE="9"/>');
          fnd_file.put_line (fnd_file.output,'</Style>');
          FND_FILE.PUT_LINE (FND_FILE.OUTPUT,'</Styles>');
        END;
        -------------------------------------------------------------------------------------------------------------------
        PROCEDURE print_style1_proc
        IS
        BEGIN
          fnd_file.put_line(fnd_file.output,'<Styles>');
          fnd_file.put_line(fnd_file.output,'<Style ss:ID="Default" ss:Name="Normal">');
          fnd_file.put_line(fnd_file.output,'<Alignment ss:Vertical="Bottom"/>');
          fnd_file.put_line(fnd_file.output,'<Borders/>');
          fnd_file.put_line(fnd_file.output,'<Font/>');
          fnd_file.put_line(fnd_file.output,'<Interior/>');
          fnd_file.put_line(fnd_file.output,'<NumberFormat/>');
          fnd_file.put_line(fnd_file.output,'<Protection/>');
          fnd_file.put_line(fnd_file.output,'</Style>');
          fnd_file.put_line(fnd_file.output,'<Style ss:ID="s24">');
          fnd_file.put_line(fnd_file.output,'<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>');
          fnd_file.put_line(fnd_file.output,'<Font x:Family="Swiss" ss:Bold="1"/>');
          fnd_file.put_line(fnd_file.output,'<Interior ss:Color="#ffb3b3" ss:Pattern="Solid"/>');
          fnd_file.put_line(fnd_file.output,'</Style>');
          fnd_file.put_line(fnd_file.output,'<Style ss:ID="s21">');
          fnd_file.put_line(fnd_file.output,'<Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>');
          fnd_file.put_line(fnd_file.output,'<Font x:Family="Swiss" ss:Bold="1"/>');
          fnd_file.put_line(fnd_file.output,'<Interior ss:Color="#9999CC" ss:Pattern="Solid"/>');
          fnd_file.put_line(fnd_file.output,'</Style>');
          FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'</Styles>');
        END;
        --
        PROCEDURE xx_employee_data_excel_proc
                                   (errbuf   OUT VARCHAR2,
                                    retcode  OUT NUMBER,
            p_employee_number IN VARCHAR2
                                   )
        IS
            CURSOR lcur_employee_details
            IS
                SELECT fu.user_name
                     , emp.title
                     , emp.first_name
                     , emp.last_name
                     , emp.full_name
                     , pptt.user_person_type
                     , pbg.name business_group_name
                     , emp.person_id
                     , emp.effective_start_date
                     , emp.effective_end_date
                     , emp.email_address
                     , emp.date_of_birth
                     , emp.employee_number
                     , emp.internal_location
                FROM per_all_people_f emp
                     , fnd_user fu
                     , per_person_types_tl pptt
                     , per_business_groups pbg
                WHERE emp.person_type_id    = pptt.person_type_id
                  AND emp.business_group_id = pbg.business_group_id
                  AND emp.person_id         = fu.employee_id
                  AND pptt.language         = 'US'
                  AND (pbg.date_to IS NULL OR pbg.date_to > SYSDATE)
                  AND (fu.end_date IS NULL OR fu.end_date > SYSDATE)
                  AND emp.person_id   = NVL(p_employee_number,emp.person_id);
        --
        BEGIN
          apps.fnd_file.put_line(apps.fnd_file.LOG,'------- Employee Details Report ---------');
          apps.fnd_file.put_line(apps.fnd_file.LOG,' ');
          apps.fnd_file.put_line(apps.fnd_file.LOG,'Report Run Date and Time : '|| TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS'));
     
          xx_excel_utility_pkg.print_header_tag_proc ('H');
          xx_excel_utility_pkg.print_doc_properties_tag_proc;
          xx_excel_utility_pkg.print_workbook_tag_proc;
          xx_excel_utility_pkg.print_style1_proc;
          xx_excel_utility_pkg.print_worksheet_tags_proc ('H', 500, 'REPORT_DATA');
          xx_excel_utility_pkg.begin_row_proc;
             xx_excel_utility_pkg.print_data_proc ('String', 'User Name', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Title', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'First Name', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Last Name', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Full Name', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'User Person Type', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Business Group Name', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Person ID', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Effective Start Date', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Effective End Date', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Email Address', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Date Of Birth', 'S');
             xx_excel_utility_pkg.print_data_proc ('String', 'Internal Location','S');
          xx_excel_utility_pkg.end_row_proc;

            FOR lreq_rec IN lcur_employee_details
            LOOP
       fnd_file.put_line(fnd_file.LOG,'Employee Number: '||p_employee_number);
               xx_excel_utility_pkg.begin_row_proc;
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.user_name);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.title);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.first_name);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.last_name);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.full_name);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.user_person_type);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.business_group_name);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.person_id);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.effective_start_date);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.effective_end_date);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.email_address);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.date_of_birth);
                 xx_excel_utility_pkg.print_data_proc ('String', lreq_rec.internal_location);
               xx_excel_utility_pkg.end_row_proc;
            END LOOP;
    --
           xx_excel_utility_pkg.print_worksheet_tags_proc ('F', NULL, 'REPORT_DATA');
           xx_excel_utility_pkg.print_header_tag_proc ('F');
        END xx_employee_data_excel_proc;
    END xx_excel_utility_pkg;
    /

    Note: Compile Package specification and body without error and register in Oracle application.

--Step 04) Create Concurrent Executable, Program and attach to respected responsibility Group to Run program:

  --1) Create Executable:
   
     
  --2) Create Program:


         Note: Program Output is HTML

  --3) Program assign to Responsibility Group.

  --4) Run Program and check program Output.


Thanks....

Steps to get ZPL code output using Zebra viewer - Online

Introduction ZPL is a print language used by many label printers. A print language is a set of commands that can be used to draw elements li...