Friday 11 December 2015

User Hooks In R12

User Hooks

Oracle has provided user hooks to implement custom logic or validation on standard processes.

For example:
Creating a element entry when creating an absence
validating the DFF segments in Absence before creating a absence.
Validation on creating EITs, Element entries, absence, termination of employee etc
Custom hook package (User Hook package) is a custom package where we write procedures for doing the customizations. The user hook procedure should have same parameters as standard API module procedure which invokes the user hook.

Now lets go through the steps to attach a user hook. I am assuming the user hook for create absence after process.

Step 1 :
Get the Module id from table HR_API_MODULES. In my case the module name is like 'CREATE%ABSENCE%'. Hence I query for the module using the below query.

SELECT * FROM hr_api_modules WHERE module_name LIKE 'CREATE%ABSENCE%';

I get the api_module_id as 1731.
---------------------------------------------------------------------------
Step 2:
Next I query for hook id in table hr_api_hooks for after process. Note that 'AP' means After Process hook and 'BP' is Before Process hook.

SELECT * FROM hr_api_hooks WHERE api_module_id = 1731;

 I get  the api_hook_id  as 3840

--------------------------------------------------------------------------
Step 3:
If you know the Module name , hook package name and hook procedure , you can use the script below .
Script for attaching the hook:

--set serveroutput on size 1000000
DECLARE
--
ln_api_hook_call_id            number;
ln_object_version_number       number;
ln_api_hook_id                 number;
--
BEGIN
   --
   select ahk.api_hook_id
     into ln_api_hook_id
     from hr_api_hooks ahk, hr_api_modules ahm
    where ahm.module_name = 'CREATE_PERSON_ABSENCE'
      and ahm.api_module_type = 'BP'
      and ahk.hook_package = 'HR_PERSON_ABSENCE_BK1'
      and ahk.hook_procedure = 'CREATE_PERSON_ABSENCE_A'
      and ahk.api_hook_type = 'AP'               -- After Process
      and ahk.api_module_id = ahm.api_module_id;
   --
   -- insert a row into HR_API_HOOK_CALLS
   --
   hr_api_hook_call_api.create_api_hook_call
      (p_effective_date        => to_date('14-MAR-2014','DD-MON-YYYY')
      ,p_api_hook_id           => ln_api_hook_id
      ,p_api_hook_call_type    => 'PP'
      ,p_sequence              => 3029
      ,p_enabled_flag          => 'Y'
      ,p_call_package          => 'XXMUD_DISCIPLINARY_ACTION_PKG'--Custom Hook PKG
      ,p_call_procedure        => 'CREATE_UNAUTHORIZED_ABS_ENTRY'--Procedure for creating entries
      ,p_api_hook_call_id      => ln_api_hook_call_id
      ,p_object_version_number => ln_object_version_number);
   --
   DBMS_OUTPUT.PUT_LINE('Registered HOOK...'|| ln_api_hook_call_id );
   --
EXCEPTION
   WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE(SUBSTR('Error: '||SQLERRM,1,255));
END;

-------------------------------------------------------
Step 4:
Next step is to run the pre-processor to the hook. Without running the pre-processor the user hook will not work.

DECLARE
l_module_id  NUMBER; --Pass the module id
BEGIN
hr_api_user_hooks_utility.create_hooks_one_module (1282);
END;

COMMIT;
--------------------------------------------------------
Step 5:
Next step is to verify if hook is registered.

SELECT * FROM hr_api_hook_calls
WHERE call_package = 'XXMUD_DISCIPLINARY_ACTION_PKG';

If STATUS column is 'V' (Stands for Valid) and ENABLED_FLAG = 'Y' then you have successfully registered the user hook.

----------------------------------------------------------------------------
Deleting User Hook:

DECLARE
ln_object_version_number       NUMBER;
ln_api_hook_call_id            NUMBER;
BEGIN

-- Get the api_hook_call_id and object_version_number
SELECT api_hook_call_id, object_version_number
  INTO ln_api_hook_call_id,ln_object_version_number
  FROM hr_api_hook_calls
 WHERE hook_call_package = 'XXMUD_DISCIPLINARY_ACTION_PKG'
   AND hook_procedure = 'CREATE_UNAUTHORIZED_ABS_ENTRY';

--API to delete the user hook
hr_api_hook_call_api.delete_api_hook_call
               (p_api_hook_call_id     =>    ln_api_hook_call_id, -- API_HOOK_CALL_ID
                p_object_version_number => ln_object_version_number );  -- Object_version_number
   DBMS_OUTPUT.PUT_LINE('DELETED HOOK...');
 
EXCEPTION
WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE(SUBSTR('Error: '||SQLERRM,1,255));
END;

Monday 26 October 2015

How to find Scheduled Concurrent Program Details

How to find Scheduled Concurrent Program Details

SELECT fcr.request_id
     , fcpt.user_concurrent_program_name|| NVL2(fcr.description, ' (' || fcr.description || ')', NULL) conc_prog
     , fu.user_name requestor
     , fu.description requested_by
     , fu.email_address
     , frt.responsibility_name requested_by_resp
     , trim(fl.meaning) status
     , fcr.phase_code
     , fcr.status_code
     , fcr.argument_text "PARAMETERS"
      , TO_CHAR(fcr.request_date, 'DD-MON-YYYY HH24:MI:SS') requested
     , TO_CHAR(fcr.requested_start_date, 'DD-MON-YYYY HH24:MI:SS') requested_start  
     , TO_CHAR((fcr.requested_start_date), 'HH24:MI:SS') start_time
     , DECODE(fcr.hold_flag, 'Y', 'Yes', 'N', 'No') on_hold
     , CASE
          WHEN fcr.hold_flag = 'Y'
             Then Substr(
                    fu.description
                  , 0
                  , 40
                 )
       END last_update_by
     , CASE
          WHEN fcr.hold_flag = 'Y'
             THEN fcr.last_update_date
       END last_update_date
     , fcr.increment_dates
     , CASE WHEN fcrc.CLASS_INFO IS NULL THEN
        'Yes: ' || TO_CHAR(fcr.requested_start_date, 'DD-MON-YYYY HH24:MI:SS')
       ELSE
        'n/a'
       END run_once
     , CASE WHEN fcrc.class_type = 'P' THEN
        'Repeat every ' ||
        substr(fcrc.class_info, 1, instr(fcrc.class_info, ':') - 1) ||
        decode(substr(fcrc.class_info, instr(fcrc.class_info, ':', 1, 1) + 1, 1),
               'N', ' minutes',
               'M', ' months',
               'H', ' hours',
               'D', ' days') ||
        decode(substr(fcrc.class_info, instr(fcrc.class_info, ':', 1, 2) + 1, 1),
               'S', ' from the start of the prior run',
               'C', ' from the completion of the prior run')
       ELSE
         'n/a'
       END set_days_of_week
       , CASE WHEN fcrc.class_type = 'S' AND instr(substr(fcrc.class_info, 33),'1',1) > 0 THEN
          'Days of week: ' ||
                  decode(substr(fcrc.class_info, 33, 1), '1', 'Sun, ') ||
                  decode(substr(fcrc.class_info, 34, 1), '1', 'Mon, ') ||
                  decode(substr(fcrc.class_info, 35, 1), '1', 'Tue, ') ||
                  decode(substr(fcrc.class_info, 36, 1), '1', 'Wed, ') ||
                  decode(substr(fcrc.class_info, 37, 1), '1', 'Thu, ') ||
                  decode(substr(fcrc.class_info, 38, 1), '1', 'Fri, ') ||
                  decode(substr(fcrc.class_info, 39, 1), '1', 'Sat ')
         ELSE
           'n/a'
         end  days_of_week
  FROM fnd_concurrent_requests fcr
     , fnd_user fu
     , fnd_concurrent_programs fcp
     , fnd_concurrent_programs_tl fcpt
     , fnd_printer_styles_tl fpst
     , fnd_conc_release_classes fcrc
     , fnd_responsibility_tl frt
     , fnd_lookups fl
 WHERE fcp.application_id = fcpt.application_id
   AND fcr.requested_by = fu.user_id
   AND fcr.concurrent_program_id = fcp.concurrent_program_id
   AND fcr.program_application_id = fcp.application_id
   AND fcr.concurrent_program_id = fcpt.concurrent_program_id
   AND fcr.responsibility_id = frt.responsibility_id
   AND fcr.print_style = fpst.printer_style_name(+)
   AND fcr.release_class_id = fcrc.release_class_id(+)
   AND fcr.status_code = fl.lookup_code
   AND fl.lookup_type = 'CP_STATUS_CODE'
   AND fcr.phase_code = 'P'
   AND 1=1
Order By Fu.Description, Fcr.Requested_Start_Date Asc;

How to Rollback SSHR Transaction in Oracle Self Service

How to Rollback SSHR Transaction in Oracle Self Service

How to Rollback SSHR Transaction in oracle apps.

begin
hr_transaction_api.rollback_transaction(p_transaction_id);
end;

commit;

Note:

p_transaction_id is the transaction_id that you will find in hr_api_transaction table.

After executing the above statement you will not find any record in hr_api_transaction

Monday 12 October 2015

HR Person API - Update Person (Employee and Contingent Worker)

HR Person API - Update Person (Employee and Contingent Worker)


//Update Employee and Contingent Worker API. Also help you for integration between Oracle ERP HR and SOA

DECLARE
   v_api_error                   VARCHAR2 (5000);
   v_error_msg                   VARCHAR2 (5000) := NULL;
   p_nationality                 VARCHAR2 (200);
   p_person_type_id              NUMBER;
   p_employee_number             NUMBER;
   p_person_id                   NUMBER;
   p_assignment_id               NUMBER;
   p_per_object_version_number   NUMBER:=19;
   p_asg_object_version_number   NUMBER;
   p_per_effective_start_date    DATE;
   p_per_effective_end_date      DATE;
   p_full_name                   VARCHAR2 (150);
   p_per_comment_id              NUMBER;
   p_assignment_sequence         NUMBER;
   p_assignment_number           VARCHAR2 (100);
   p_name_combination_warning    BOOLEAN;
   p_assign_payroll_warning      BOOLEAN;
   p_orig_hire_warning           BOOLEAN;
   p_business_group_id           NUMBER;
   p_object_version_number       NUMBER;
   p_validate                    BOOLEAN;
   p_effective_date              DATE;
   p_effective_start_date        DATE;
   p_effective_end_date          DATE;
   p_comment_id                  NUMBER;
   p_emp_num                     VARCHAR2 (50);
 
  BEGIN
         p_emp_num := '769123';
         p_validate := FALSE;
         p_effective_date := TRUNC (SYSDATE);
     
         hr_person_api.update_person
                    (p_email_address                 => 'k@b.com',
                     p_title                         => 'MR',
                     p_person_type_id                => 3186,
                     p_validate                      => p_validate,
                     p_effective_date                => p_effective_date,
                     p_datetrack_update_mode         => 'CORRECTION',
                     p_person_id                     => 221187,
                     p_object_version_number         => p_per_object_version_number,
                     p_employee_number               => p_emp_num,
                     p_full_name                     => p_full_name,
                     p_effective_start_date          => p_effective_start_date,
                     p_effective_end_date            => p_effective_end_date,
                     p_comment_id                    => p_comment_id,
                     p_name_combination_warning      => p_name_combination_warning,
                     p_assign_payroll_warning        => p_assign_payroll_warning,
                     p_orig_hire_warning             => p_orig_hire_warning
                    );
      EXCEPTION
         WHEN OTHERS
         THEN
            p_emp_num := NULL;
            p_validate := NULL;
            p_effective_date := NULL;
            p_person_id := NULL;
            p_effective_start_date := NULL;
            p_effective_end_date := NULL;
            p_comment_id := NULL;
 END;

Thursday 8 October 2015

How to get Net Entitlement of Leaves in Oracle HRMS Payroll

How to get Net Entitlement of Leaves in Oracle HRMS Payroll
How to get net entitlement of leaves of an employee on a specific date in oracle hrms??

Please refer to the function code below.





CREATE OR REPLACE FUNCTION CUST_GET_NET_ENTITLEMENT (
   P_ASSG_ID            IN   NUMBER,
   P_PAYROLL_ID         IN   NUMBER,
   P_CALCULATION_DATE   IN   DATE
)
   RETURN NUMBER
IS
   L_START_DATE         DATE;
   L_END_DATE           DATE;
   L_ACC_END_DATE       DATE;
   L_VALUE              NUMBER         := 0;
   L_NET_VALUE          NUMBER (15, 2);
   P_PLAN_ID            NUMBER;
--   L_CALCULATION_DATE   DATE;
BEGIN
   SELECT PAP.ACCRUAL_PLAN_ID
     INTO P_PLAN_ID
     FROM PAY_ACCRUAL_PLANS PAP
    WHERE UPPER (PAP.ACCRUAL_PLAN_NAME) LIKE
             (SELECT UPPER (PETF.ELEMENT_NAME)
                FROM PAY_ELEMENT_ENTRIES_F PEEF, PAY_ELEMENT_TYPES_F PETF
               WHERE PEEF.ELEMENT_TYPE_ID = PETF.ELEMENT_TYPE_ID
                 AND UPPER (PETF.ELEMENT_NAME) LIKE '%PLAN%'
                 AND PETF.PROCESSING_TYPE = 'R'
                 AND PEEF.ASSIGNMENT_ID = P_ASSG_ID
                 AND P_CALCULATION_DATE BETWEEN PEEF.EFFECTIVE_START_DATE
                                            AND PEEF.EFFECTIVE_END_DATE);

/* QUERY ABOVE AUTOMATICALLY GETS THE PLAN ID OF THE ACCRUAL PLAN ID ATTACHED AS ON CALCULATION DATE*/
   PER_ACCRUAL_CALC_FUNCTIONS.GET_NET_ACCRUAL
                           (P_ASSIGNMENT_ID               => P_ASSG_ID,
                            P_PLAN_ID                     => P_PLAN_ID,
                            P_PAYROLL_ID                  => P_PAYROLL_ID,
                            P_BUSINESS_GROUP_ID           => 81,   -- Kindly change your business group id accordingly
                            P_ASSIGNMENT_ACTION_ID        => -1,
                            P_CALCULATION_DATE            => TO_DATE
                                                               (P_CALCULATION_DATE
                                                                )
-- DATE YOU WANT TO CHECK THE NET ENTITLEMENT EX. TO_DATE('01-MAR-2009', 'DD-MON-YYYY')
   ,
                            P_ACCRUAL_START_DATE          => NULL,
                            P_ACCRUAL_LATEST_BALANCE      => NULL,
                            P_CALLING_POINT               => 'FRM',
                            P_START_DATE                  => L_START_DATE,
                            P_END_DATE                    => L_END_DATE,
                            P_ACCRUAL_END_DATE            => L_ACC_END_DATE,
                            P_ACCRUAL                     => L_VALUE,
                            P_NET_ENTITLEMENT             => L_NET_VALUE
                           );
   RETURN NVL (L_NET_VALUE, 0);
EXCEPTION
   WHEN OTHERS
   THEN
      RETURN 0;
END;
/

Friday 18 September 2015

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 1 September 2015

Hierarchical Queries using SYS_CONNECT_BY_PATH clause

Hierarchical Queries using SYS_CONNECT_BY_PATH clause


Purpose

SYS_CONNECT_BY_PATH is valid only in hierarchical queries. It returns the path of a column value from root to node, with column values separated by char for each row

returned by CONNECT BY condition.

Both column and char can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2. The string returned is of VARCHAR2 datatype and is in the same character set as

column.

Examples

The following example returns the path of employee names from employee KING to all employees of KING (and their employees):


SELECT LPAD (' ', 2 * LEVEL - 1) || SYS_CONNECT_BY_PATH (ename, '/') "Path"
      FROM scott.emp
START WITH ename = 'KING'
CONNECT BY PRIOR empno = mgr;

Path
---------------------------------------------------------------
  /KING
   /KING/JONES
     /KING/JONES/SCOTT
       /KING/JONES/SCOTT/ADAMS
     /KING/JONES/FORD
       /KING/JONES/FORD/SMITH
   /KING/BLAKE
     /KING/BLAKE/ALLEN
     /KING/BLAKE/WARD
     /KING/BLAKE/MARTIN
     /KING/BLAKE/TURNER
     /KING/BLAKE/JAMES
   /KING/CLARK
     /KING/CLARK/MILLER

Tuesday 21 July 2015

How to Get Privelege Leave Initial Balance Using Seeded Oracle Package

How to Get Privelege Leave Initial Balance Using Seeded Oracle Package


SELECT papf.person_id,
         paaf.assignment_id,
         papf.employee_number,
         papf.FULL_NAME,
         'Privelege Leave Initial Balance' element_name,
         per_accrual_calc_functions.Get_Other_Net_Contribution (
            paaf.assignment_id,
            1063,  --ACCRUAL_PLAN_ID from PAY_ACCRUAL_PLANS table
            '01-APR-2014',  --Calculation_Date
            '01-JAN-2014') --Start_Date
            Privelege_Leave_Initial_Bal
    FROM per_all_people_f papf, per_all_assignments_f paaf
   WHERE 1 = 1 AND papf.person_id = paaf.person_id
         AND TRUNC (SYSDATE) BETWEEN TRUNC (papf.EFFECTIVE_START_DATE)
                                 AND TRUNC (papf.EFFECTIVE_END_DATE)
         AND TRUNC (SYSDATE) BETWEEN TRUNC (paaf.EFFECTIVE_START_DATE)
                                 AND TRUNC (paaf.EFFECTIVE_END_DATE)
         AND EMPLOYEE_NUMBER IS NOT NULL
--and papf.employee_number='500015'
ORDER BY 1;

Saturday 18 April 2015

PO Approval and Hierarchy Details Script

PO Approval and Hierarchy Details Script


PO Approval and Hierarchy Details Script



PO Hierarchy Details Script

SELECT *
  FROM (SELECT POS_STRUCTURE_VERSION_ID,
               b.name structure_name,
               PARENT_POSITION_ID,
               (SELECT name
                  FROM hr_all_positions_f
                 WHERE position_id = PARENT_POSITION_ID)
                  PARENT_POSITION_NAME,
               SUBORDINATE_POSITION_ID,
               (SELECT name
                  FROM hr_all_positions_f
                 WHERE position_id = SUBORDINATE_POSITION_ID)
                  SUBORDINATE_POSITION_NAME
          --(select full_name from per_all_people_f where person_id in(select person_id from per_all_assignments_f where position_id=SUBORDINATE_POSITION_ID))
          FROM per_pos_structure_elements_v a, PER_POSITION_STRUCTURES b
         WHERE     1 = 1
               AND a.POS_STRUCTURE_VERSION_ID = b.POSITION_STRUCTURE_ID
               AND POS_STRUCTURE_VERSION_ID <> 0)
 WHERE STRUCTURE_NAME = 'XX_STRUTURE_NAME'          




PO Approval Group Details Script

SELECT decode(ppca.org_id,83,'XXORG_NAME',181,'XXORG_NAME') Org_Name,
--       ppca.position_id,
       (select name from per_positions where position_id=ppca.position_id)Position_Name,
--       ppca.job_id,
       (select name from per_jobs where job_id=ppca.job_id) Job_Name,
--       ppca.control_group_id,
--       ppca.control_function_id,
       control_function_name Document_Type,
       control_group_name Approval_Group
  FROM po_position_controls_all ppca,
       po_control_groups_all pcga,
       po_control_functions pcf
 WHERE     1 = 1
       AND ppca.control_group_id = pcga.control_group_id
       AND ppca.control_function_id = pcf.control_function_id;

Thursday 2 April 2015

Inventory Item Details Script

Inventory Item Details Script

SELECT
       a.ORGANIZATION_ID,
       a.ORGANIZATION_CODE,
       a.SUBINVENTORY_CODE,
       a.LOCATOR_ID,
       a.LOCATOR,
       a.INVENTORY_ITEM_ID,
       a.ITEM,
       a.ITEM_DESCRIPTION,
       a.UOM,
       sum(a.ON_HAND) ON_HAND_QTY,
       b.ITEM_COST,
       (sum(a.ON_HAND) *  b.ITEM_COST) Item_Value
  FROM mtl_onhand_total_mwb_v a
  ,cst_item_costs b
 WHERE a.ORGANIZATION_ID = 121
 and a.INVENTORY_ITEM_ID=b.INVENTORY_ITEM_ID(+)
 and a.ORGANIZATION_ID=b.ORGANIZATION_ID(+)
-- and INVENTORY_ITEM_ID=1381681
 group by a.ORGANIZATION_ID,
       a.ORGANIZATION_CODE,
       a.SUBINVENTORY_CODE,
       a.LOCATOR_ID,
       a.LOCATOR,
       a.INVENTORY_ITEM_ID,
       a.ITEM,
       a.ITEM_DESCRIPTION,
       a.UOM,
       b.ITEM_COST order by 6 desc;

Sunday 15 March 2015

Concurrent Program and Executable Details

Concurrent Program and Executable Details

The following SQL query provide you executable file name ,top name , etc...

--Oracle Applications Query to get the actual concurrent program file executable if we know the concurrent program name

SELECT b.user_concurrent_program_name,
       b.concurrent_program_name,
       a.user_executable_name,
       DECODE (a.execution_method_code,
               'I', 'PL/SQL Stored Procedure',
               'H', 'Host',
               'S', 'Immediate',
               'J', 'Java Stored Procedure',
               'K', 'Java concurrent program',
               'M', 'Multi Language Function',
               'P', 'Oracle reports',
               'B', 'Request Set Stage Function',
               'A', 'Spawned',
               'L', 'SQL*Loader',
               'Q', 'SQL*Plus',
               'E', 'Pearl concurrent Programm',
               'Unkown Type')
          TYPE,
       a.execution_file_name,
       a.execution_file_path,
       a.application_name,
       c.basepath,
       a.executable_id
  FROM fnd_executables_form_v a,
       fnd_concurrent_programs_vl b,
       fnd_application c
 WHERE     a.executable_id = b.executable_id
       AND a.application_id = c.application_id
--       AND EXECUTABLE_NAME = 'XX'
       AND b.user_concurrent_program_name like'XX%';

Friday 27 February 2015

Execute Immediate in Oracle Reports

Execute Immediate in Oracle Reports

Using this EXECUTE IMMEDIATE command directy in reports is not possible, if you tried to use, i.e. EXECUTE IMMEDIATE ‘drop TABLE TEST’,
this error message will occured,  “this feature is not supported in client-side programs”.
EXECUTE IMMEDIATE is only supported on the server side.,but you can
work around this by creating astored procedure in the database and then using this
procedure in reports.

The database stored procedure can be created as follows:

CREATE OR REPLACE PROCEDURE DYNAMIC_SQL(STMNT CHAR) IS
BEGIN
   BEGIN
     EXECUTE IMMEDIATE STMNT;
   EXCEPTION
     WHEN OTHERS THEN
       DBMS_OUTPUT.PUT_LINE('Error while executing dynamic sql');
   END;
END;

Now, this procedure can be called in Reports.
For Example:
In the BeforeParam Trigger,the procedure can be called as:
DYNAMIC_SQL('DROP TABLE TEST');
This will drop the table 'TEST' from the database.

Wednesday 25 February 2015

R12 Supplier Bank Accounts

R12 Supplier Bank Accounts Details

R12 Supplier Bank Accounts
In Release 12, Payables Supplier Bank Information is stored somewhere else instead of PO_VENDORS table as in 11i. The supplier (or External) bank account information are stored in the table called IBY_EXT_BANK_ACCOUNTS. The bank and bank branches information are stored in the table HZ_PARTIES. They are linked together through Relationships (in HZ_RELATIONSHIP).

There is a separate link for both Bank to Branch and also from Branch to Bank. Bank sites and Location information are stored in tables: HZ_PARTY_SITES and HZ_LOCATIONS. The bank_id and branch_id fields of IBY_EXT_BANK_ACCOUNTS table link the Bank Account to the relevant Bank and Branch Parties in the HZ_PARTIES table (IBY_EXT_BANK_ACCOUNTS.BANK_id = hz_paties.party_id).

Supplier (or External) bank accounts are created in Payables, in the Supplier Entry forms. Navigate to Suppliers -> Entry. Query or create your supplier. Click on Banking Details and then choose Create. After you have created the bank account, you can assign the bank account to the supplier site.

When the Bank is assigned to Vendors then it will be updated in a table called HZ_CODE_ASSIGNMENTS. Payment related details of supplier are also inserted in iby_external_payees_all as well as iby_ext_party_pmt_mthds.

The bank branch number can be found in the table: HZ_ORGANIZATION_PROFILES .The HZ_ORGANIZATION_PROFILES table stores a variety of information about a party. This table gets populated when a party of the Organization type is created. IBY_EXTERNAL_PAYEES_ALL stores payment-related attributes for the funds disbursement payment process for external party payees.

Queries:


SELECT  aps.vendor_name "VERDOR NAME",
        apss.vendor_site_code "VENDOR SITE CODE",
        ieb.bank_name "BANK NAME",
        iebb.bank_branch_name "BANK BRANCH NAME",
        iebb.branch_number "BRANCH NUMBER",
        ieba.BANK_ACCOUNT_NUM "BANK ACCOUNT NUMBER",
        ieba.BANK_ACCOUNT_NAME "BANK ACCOUNT NAME"
FROM    ap.ap_suppliers aps,
        ap.ap_supplier_sites_all apss,
        apps.iby_ext_bank_accounts ieba,
        apps.iby_account_owners iao,
        apps.iby_ext_banks_v ieb,
        apps.iby_ext_bank_branches_v iebb
WHERE   aps.vendor_id = apss.vendor_id
        and iao.account_owner_party_id = aps.party_id
        and ieba.ext_bank_account_id = iao.ext_bank_account_id
        and ieb.bank_party_id = iebb.bank_party_id
        and ieba.branch_id = iebb.branch_party_id
        and ieba.bank_id = ieb.bank_party_id;
Oracle PL/SQL


SELECT party_supp.party_name supplier_name
,      aps.segment1          supplier_number
,      ass.vendor_site_code  supplier_site
,      ieb.bank_account_num
,      ieb.bank_account_name
,      party_bank.party_name bank_name
,      branch_prof.bank_or_branch_number bank_number
,      party_branch.party_name branch_name
,      branch_prof.bank_or_branch_number branch_number
FROM   hz_parties party_supp
,      ap_suppliers aps
,      hz_party_sites site_supp
,      ap_supplier_sites_all ass
,      iby_external_payees_all iep
,      iby_pmt_instr_uses_all ipi
,      iby_ext_bank_accounts ieb
,      hz_parties party_bank
,      hz_parties party_branch
,      hz_organization_profiles bank_prof
,      hz_organization_profiles branch_prof
WHERE  party_supp.party_id = aps.party_id
AND    party_supp.party_id = site_supp.party_id
AND    site_supp.party_site_id = ass.party_site_id
AND    ass.vendor_id = aps.vendor_id
AND    iep.payee_party_id = party_supp.party_id
AND    iep.party_site_id = site_supp.party_site_id
AND    iep.supplier_site_id = ass.vendor_site_id
AND    iep.ext_payee_id = ipi.ext_pmt_party_id
AND    ipi.instrument_id = ieb.ext_bank_account_id
AND    ieb.bank_id = party_bank.party_id
AND    ieb.bank_id = party_branch.party_id
AND    party_branch.party_id = branch_prof.party_id
AND    party_bank.party_id = bank_prof.party_id
ORDER BY party_supp.party_name
,        ass.vendor_site_code;

Invoices in the status of 'Selected for Validation' after cancelling Invoice Validation Program

Invoices in the status of 'Selected for Validation' after cancelling Invoice Validation Program

Here we can segregate this issue into 2 Parts.

1. Invoices in status of Selected for validation when cancelled Invoice Validation Program it will be stamped with Validation_request_id.
2. Invoice Validation program keep on running from hours together and want to cancel the Request

When ever we cancel the invoice validation program when its running, it should roolback all the invoices back to its normal status but some/many times it will not rollback the invoices and it will stamp the cancelled request id on all the invoices under column VALIDATION_REQUEST_ID of AP_INVOICE_HEADERS_ALL.

What ever the invoices stamped with request_id can be get with this query to know the count or list of invoices.
SQL:
select * from ap_invoices_all where validation_request_id = 'XXXXX';-- or where validation_request_id is not null;

Once we extract these invoices we need to fix the invoices with the help of data-fix to rollback stamped invoices.

Solution: (Reference Patch#17428522)

1. Cancel the  request (If the request is not yet cancel the request)

A.  Cancel present child request #46981209

B.  Wait for few minutes to let parent request complete, it might initiate other new child requests in couple of minutes.

C.  If parent request do not initiate other child requests and parent request not completes in few minutes, cancel parent request as well.

2. Apply patch#17428522 and Run script: ap_inv_val_prb_sel.sql

Path: $AP_TOP/patch/115/sql/ ap_inv_val_prb_sel.sql

Temp Driver Table:
AP_TEMP_DATA_DRIVER_9327208

If you want to extract the invoices from the driver table use this query

select * from AP_TEMP_DATA_DRIVER_9327208

3. Run update statement:

update AP_TEMP_DATA_DRIVER_9327208
set process_flag=’N’
where validation_request_id is null;

commit;
/
4. Run fix script: ap_inv_val_prb_fix.sql

Path:$AP_TOP/patch/115/sql/ ap_inv_val_prb_fix.sql

Once the fix completed successfully, run the below again here you should get '0' records

Query:
select count(invoice_id) from ap_invoices_all where validation_request_id is not null;

Tuesday 24 February 2015

Submit a Concurrent Request from backend

/*********************************************************
*PURPOSE: To Submit a Concurrent Request from backend    *
*AUTHOR: Dilli Subramani                              *
*Date : 24/02/2015                        *
**********************************************************/
--
DECLARE
l_responsibility_id     NUMBER;
l_application_id        NUMBER;
l_user_id               NUMBER;
l_request_id            NUMBER;
BEGIN
  --
  SELECT DISTINCT fr.responsibility_id,
    frx.application_id
     INTO l_responsibility_id,
    l_application_id
     FROM apps.fnd_responsibility frx,
    apps.fnd_responsibility_tl fr
    WHERE fr.responsibility_id = frx.responsibility_id
  AND LOWER (fr.responsibility_name) LIKE LOWER('XXTest Resp');
  --
   SELECT user_id INTO l_user_id FROM fnd_user WHERE user_name = 'STHALLAM';
  --
  --To set environment context.
  --
  apps.fnd_global.apps_initialize (l_user_id,l_responsibility_id,l_application_id);
  --
  --Submitting Concurrent Request
  --
  l_request_id := fnd_request.submit_request (
                            application   => 'XXCUST',
                            program       => 'XXEMP',
                            description   => 'XXTest Employee Details',
                            start_time    => sysdate,
                            sub_request   => FALSE,
                argument1     => 'Smith'
  );
  --
  COMMIT;
  --
  IF l_request_id = 0
  THEN
     dbms_output.put_line ('Concurrent request failed to submit');
  ELSE
     dbms_output.put_line('Successfully Submitted the Concurrent Request');
  END IF;
  --
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('Error While Submitting Concurrent Request '||TO_CHAR(SQLCODE)||'-'||sqlerrm);
END;
/









========================================



Pre-requisites :
Step1: Data Definition and Template to be created
Step2: Concurrent program needs to be created

Steps To Create the PL/SQL package:

1. Initialize the  Session Specific variable using fnd_global.APPS_INITIALIZE
2. Set The BI publisher report layout Before submitting the concurrent program
3. Submit the Concurrent Program

Code: (Tested in R12.1.1 )

DECLARE
   l_user_id              fnd_user.user_id%TYPE;
   l_resp_id              fnd_responsibility.responsibility_id%TYPE;
   l_resp_appl_id         fnd_application.application_id%TYPE;
   l_set_layout           boolean;
   l_request_id           NUMBER;
   l_phase                VARCHAR2 (100);
   l_status               VARCHAR2 (100);
   l_dev_phase            VARCHAR2 (100);
   l_dev_status           VARCHAR2 (100);
   l_wait_for_request     boolean := FALSE;
   l_get_request_status   boolean := FALSE;
   Output_layout_failed EXCEPTION;
   request_submission_failed EXCEPTION;
   request_completion_abnormal EXCEPTION;
BEGIN
   l_request_id := NULL;

   --
   -- Get the Apps Intilization Variables
   --
   SELECT   fnd.user_id, fresp.responsibility_id, fresp.application_id
     INTO   l_user_id, l_resp_id, l_resp_appl_id
     FROM   fnd_user fnd, fnd_responsibility_tl fresp
    WHERE   fnd.user_name = 'OEAG'
            AND fresp.responsibility_name = 'Custom XML Reports';

   --
   --Initialize the Apps Variables
   --
   fnd_global.APPS_INITIALIZE (user_id        => l_user_id,
                               resp_id        => l_resp_id,
                               resp_appl_id   => l_resp_appl_id);

   COMMIT;

   --
   -- Set the Layout  for BI Publisher Report
   --

   l_set_layout :=
      fnd_request.add_layout (template_appl_name   => 'XXERP',
                              template_code        => 'XXORACLEERPAPPSGUIDE',
                              --Data Template Code
                              template_language    => 'en',
                              template_territory   => 'US',
                              output_format        => 'PDF');

   IF l_set_layout
   THEN
      -- Submit the Request

      l_request_id :=
         fnd_request.submit_request (application   => 'XXERP',
                                     program       => 'XXOEAG_PG',
                                     description   => '',
                                     start_time    => SYSDATE,
                                     sub_request   => FALSE,
                                     argument1     => l_person_id);

      COMMIT;

      IF l_request_id > 0
      THEN
         --
         --waits for the request completion
         --

         l_wait_for_request :=
            fnd_concurrent.wait_for_request (request_id   => l_request_id,
                                             interval     => 60,
                                             max_wait     => 0,
                                             phase        => l_phase,
                                             status       => l_status,
                                             dev_phase    => l_dev_phase,
                                             dev_status   => l_dev_status,
                                             MESSAGE      => l_messase);

         COMMIT;

         --
         -- Get the Request Completion Status.
         --
         l_get_request_status :=
            fnd_concurrent.get_request_status (
               request_id       => l_request_id,
               appl_shortname   => NULL,
               program          => NULL,
               phase            => l_phase,
               status           => l_status,
               dev_phase        => l_dev_phase,
               dev_status       => l_dev_status,
               MESSAGE          => l_messase
            );

         --
         --Check the status if It IS completed Normal Or Not
         --
         IF UPPER (l_dev_phase) != 'COMPLETED'
            AND UPPER (l_dev_status) != 'NORMAL'
         THEN
            RAISE request_completion_abnormal;
         END IF;
      ELSE
         RAISE request_submission_failed;
      END IF;
   ELSE
      RAISE Output_layout_failed;
   END IF;

   p_request_id := l_request_id;
EXCEPTION
   WHEN Output_layout_failed
   THEN
      DBMS_OUTPUT.put_line ('Out put Layout failed');
   WHEN request_submission_failed
   THEN
      DBMS_OUTPUT.put_line ('Concurrent request submission failed');
   WHEN request_completion_abnormal
   THEN
      DBMS_OUTPUT.put_line (
         'Submitted request completed with error' || l_request_id
      );
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line ('ERROR:' || SUBSTR (SQLERRM, 0, 240));
END;

/

You can Create this as PL/SQL Procedure and register into Concurrent Program also.



Concat rows values into single column

Concat rows values into single column

SQL>  select rtrim(xmlagg(xmlelement(e, empno || ',')).extract('//text()').extract('//text()') ,',') empnos from emp
/
EMPNOS                                                                        
--------------------------------------------------------------------------------
7369,7499,7521,7566,7654,7698,7782,7788,7839,7844,7876,7900,7902,7934  

Sunday 22 February 2015

Oracle Apps: Check file version

Oracle Apps: Check file version


Check version of the File
Two ways to check version of file.
1. Adident
2. Strings
ADIDENT Utility in ORACLE application is used to find version of any file.
1st Method
Syntax : adident Header filename.
e.g If you want to find out the version of appvndrb.pls
$ cd AP_TOP/patch/115/sql
$ adident Header appvndrb.pls
o/p :
appvndrb.pls:
$Header appvndrb.pls 120.78.12010000.83 2010/04/27 21:00:55 vinaik ship
2nd Method :
Using Strings:
Syntax : strings -a Top_name/location of file/filename | grep ‘$Header’
e.g $ strings -a $AP_TOP/patch/115/sql/appvndrb.pls | grep ‘$Header’
o/p : /* $Header: appvndrb.pls 120.78.12010000.83 2010/04/27 21:00:55 vinaik ship $ */
OR
$ cd $AP_TOP/patch/115/sql
$ strings -a appvndrb.pls | grep ‘$Header’

Tuesday 17 February 2015

REP-3000: Internal error starting Oracle Toolkit

No reports (PDF/XML) were running and it gave the below error in the log file.

 REP-3000: Internal error starting Oracle Toolkit

To resolve this issue Follow the below steps and it worked-out well.
1. Open the custom report in the Report Builder
2. Go to the property pallette of the Report
3. Remove the xml prologue value
4. Save the changes and move the report to server
5. Retest the issue

Status code and Phase code from fnd_concurrent_requests FND_CONCURRENT_REQUESTS

Status code and Phase code from fnd_concurrent_requests
FND_CONCURRENT_REQUESTS

STATUS_CODE Column:
A Waiting
B Resuming
C Normal
D Cancelled
E Error
F Scheduled
G Warning
H On Hold
I Normal
M No Manager
Q Standby
R Normal
S Suspended
T Terminating
U Disabled
W Paused
X Terminated
Z Waiting.

PHASE_CODE column.
C Completed
I Inactive
P Pending
R Running

Saturday 10 January 2015

Prepayment Status Report Custom Query

Prepayment Status Report Custom Query


/* Formatted on 10-01-2015 04:48:39 PM (QP5 v5.163.1008.3004) */
SELECT vendor_name,
       --       ACCOUNT_CODE,
       (SELECT segment4
          FROM gl_code_combinations_kfv
         WHERE code_combination_id = account_code)
          account_code,
       invoice_type_lookup_code,
       invoice_no,
       invoice_id,
       invoice_date,
       exchange_rate,
       invoice_currency_code,
       invoice_amount,
       --       (INVOICE_AMOUNT - PERPAY)/EXCHANGE_RATE,
       ( ( (invoice_amount - perpay) * exchange_rate) / exchange_rate)
          amount_remaining_cy,
       ( (invoice_amount - perpay) * exchange_rate) amount_remaining_aed,
       perpay,
       description
  FROM (  SELECT b.vendor_name vendor_name,
                 --c.vendor_site_id,
                 --c.PREPAY_CODE_COMBINATION_ID ACCOUNT_CODE,
                 d.dist_code_combination_id account_code,
                 a.invoice_type_lookup_code invoice_type_lookup_code,
                 a.invoice_num invoice_no,
                 a.invoice_id invoice_id,
                 a.invoice_date invoice_date,
                 a.invoice_currency_code invoice_currency_code,
                 NVL (a.exchange_rate, 1) exchange_rate,
                 SUM (d.amount) invoice_amount,
                 NVL (
                    (SELECT SUM (prepay_amount_applied)
                       FROM ap_view_prepays_fr_prepay_v
                      WHERE prepay_id = a.invoice_id
                            AND TO_DATE (accounting_date, 'DD-MON-RRRR') <=
                                   TO_DATE (:p_to_date, 'DD-MON-RRRR')),
                    0)
                    perpay,
                 a.description description
            FROM apps.ap_invoices_all a,
                 apps.ap_invoice_distributions_all d,
                 apps.ap_suppliers b,
                 apps.ap_supplier_sites_all c
           WHERE     a.invoice_id = d.invoice_id
                 AND a.vendor_id = b.vendor_id
                 AND b.vendor_id = c.vendor_id
                 AND a.vendor_site_id = c.vendor_site_id
                 AND a.invoice_type_lookup_code = 'PREPAYMENT'
                 AND a.org_id = NVL (:org_id, a.org_id)
                 AND b.vendor_name = NVL (:p_vendor_name, b.vendor_name)
                 --               and  d.DIST_CODE_COMBINATION_ID=2016--(233100)
                 AND TO_DATE (d.accounting_date, 'DD-MON-RRRR') <=
                        TO_DATE (:p_to_date, 'DD-MON-RRRR')
        GROUP BY b.vendor_name,
                 --c.vendor_site_id,
                 d.dist_code_combination_id,
                 a.invoice_type_lookup_code,
                 a.invoice_num,
                 a.invoice_id,
                 a.invoice_date,
                 a.invoice_currency_code,
                 NVL (a.exchange_rate, 1),
                 a.description)
 WHERE (invoice_amount - perpay) <> 0;

--       AND a.invoice_num = 'IPO-107253';





Supplier Statement Of Accounts Custom Report Query

/* Formatted on 10-01-2015 04:44:00 PM (QP5 v5.163.1008.3004) */
SELECT *
  FROM (SELECT vendor_name,
               invoice_date,
               gl_date,
               invoice_currency_code,
               name,
               document_type,
               supplier_reference,
               posting_status,
               narration,
               document_no,
               due_date,
               payment_status,
               DECODE (document_type,
                       'DEBIT', inv_amount,
                       (payment_amount + prepay_applied))
                  entered_dr,
               DECODE (document_type,
                       'STANDARD', inv_amount,
                       'CREDIT', inv_amount,
                       (payment_amount + prepay_applied))
                  entered_cr,
               --       INV_AMOUNT ENTERED_DR,
               --       (PAYMENT_AMOUNT + PREPAY_APPLIED) ENTERED_CR,
               (inv_amount - (payment_amount + prepay_applied))
                  entered_balance,
               DECODE (document_type,
                       'DEBIT', (inv_amount * exchange_rate),
                       ( (payment_amount + prepay_applied) * exchange_rate))
                  functional_dr,
               DECODE (document_type,
                       'STANDARD', inv_amount * exchange_rate,
                       'CREDIT', inv_amount * exchange_rate,
                       ( (payment_amount + prepay_applied) * exchange_rate))
                  functional_cr,
               --       (INV_AMOUNT * EXCHANGE_RATE) FUNCTIONAL_DR,
               --       ( (PAYMENT_AMOUNT + PREPAY_APPLIED) * EXCHANGE_RATE) FUNCTIONAL_CR,
               ( (inv_amount * exchange_rate)
                - ( (payment_amount + prepay_applied) * exchange_rate))
                  functional_balance
          FROM (  SELECT pv.vendor_name vendor_name,
                         aia.invoice_date invoice_date,
                         aia.gl_date gl_date,
                         aia.invoice_currency_code invoice_currency_code,
                         hou.name,
                         aia.invoice_type_lookup_code document_type,
                         --         AIA.INVOICE_ID,
                         aia.invoice_num supplier_reference,
                         ap_invoices_pkg.get_posting_status (aia.invoice_id)
                            posting_status,
                         NVL (aia.exchange_rate, 1) exchange_rate,
                         aia.description narration,
                         aia.doc_sequence_value document_no,
                         (SELECT MIN (apsa.due_date)
                            FROM ap.ap_payment_schedules_all apsa
                           WHERE apsa.invoice_id = aia.invoice_id)
                            due_date,
                         DECODE (aia.payment_status_flag,
                                 'N', 'Not Paid',
                                 'P', 'Partially Paid',
                                 'Y', 'Fully Paid')
                            payment_status,
                         SUM (aida.amount) inv_amount,
                         NVL (
                            (SELECT SUM (aipa.amount)
                               FROM ap_invoice_payments_all aipa
                              WHERE 1 = 1 AND aipa.invoice_id = aia.invoice_id
                                    AND TO_DATE (aipa.accounting_date,
                                                 'DD-MON-RRRR') <=
                                           TO_DATE (:p_as_of_date,
                                                    'DD-MON-RRRR')),
                            0)
                            payment_amount,
                         NVL (
                            (SELECT SUM (avp.prepay_amount_applied)
                               FROM ap_view_prepays_fr_prepay_v avp
                              WHERE 1 = 1 AND avp.invoice_id = aia.invoice_id
                                    AND TO_DATE (avp.accounting_date,
                                                 'DD-MON-RRRR') <=
                                           TO_DATE (:p_as_of_date,
                                                    'DD-MON-RRRR')),
                            0)
                            prepay_applied
                    FROM ap_invoices_all aia,
                         ap_invoice_distributions_all aida,
                         po_vendors pv,
                         hr_operating_units hou
                   WHERE     1 = 1
                         AND aia.invoice_id = aida.invoice_id
                         AND aia.vendor_id = pv.vendor_id
                         AND aia.org_id = hou.organization_id
                         AND aida.line_type_lookup_code IN
                                ('ITEM',
                                 'ACCRUAL',
                                 'ERV',
                                 'IPV',
                                 'FREIGHT',
                                 'MISCELLANEOUS')
                         AND aia.invoice_type_lookup_code <> 'PREPAYMENT'
                         AND ap_invoices_pkg.get_posting_status (
                                aia.invoice_id) = 'Y'
                         AND aia.org_id = NVL (:org_id, aia.org_id)
                         AND pv.vendor_name =
                                NVL (:p_vendor_name, pv.vendor_name)
                         AND TO_DATE (aida.accounting_date, 'DD-MON-RRRR') <=
                                TO_DATE (:p_as_of_date, 'DD-MON-RRRR')
                --         AND aia.vendor_id = 86014
                GROUP BY aia.invoice_id,
                         aia.vendor_id,
                         pv.vendor_name,
                         aia.invoice_date,
                         aia.gl_date,
                         aia.invoice_currency_code,
                         hou.name,
                         aia.description,
                         aia.exchange_rate,
                         aia.doc_sequence_value,
                         aia.payment_status_flag,
                         aia.invoice_type_lookup_code,
                         aia.invoice_num)
        UNION ALL
        -- =========== PREPAYMENT QUERY ================= --

        SELECT vendor_name,
               invoice_date,
               gl_date,
               invoice_currency_code,
               name,
               document_type,
               supplier_reference,
               posting_status,
               narration,
               document_no,
               due_date,
               payment_status,
               inv_amount entered_cr,
               prepay_applied entered_dr,
               (inv_amount - prepay_applied) entered_balance,
               (inv_amount * exchange_rate) functional_cr,
               (prepay_applied * exchange_rate) functional_dr,
               ( (inv_amount * exchange_rate)
                - (prepay_applied * exchange_rate))
                  functional_balance
          FROM (  SELECT aps.vendor_name vendor_name,
                         aia.invoice_date invoice_date,
                         aia.gl_date gl_date,
                         aia.invoice_currency_code invoice_currency_code,
                         hou.name,
                         aia.invoice_type_lookup_code document_type,
                         aia.invoice_num supplier_reference,
                         ap_invoices_pkg.get_posting_status (aia.invoice_id)
                            posting_status,
                         NVL (aia.exchange_rate, 1) exchange_rate,
                         aia.description narration,
                         aia.doc_sequence_value document_no,
                         (SELECT MIN (apsa.due_date)
                            FROM ap.ap_payment_schedules_all apsa
                           WHERE apsa.invoice_id = aia.invoice_id)
                            due_date,
                         DECODE (aia.payment_status_flag,
                                 'N', 'Not Paid',
                                 'P', 'Partially Paid',
                                 'Y', 'Fully Paid')
                            payment_status,
                         SUM (aipa.amount) inv_amount,
                         0 payment_amount,
                         NVL (
                            (SELECT SUM (prepay_amount_applied)
                               FROM ap_view_prepays_fr_prepay_v
                              WHERE prepay_id = aia.invoice_id
                                    AND TO_DATE (accounting_date,
                                                 'DD-MON-RRRR') <=
                                           TO_DATE (:p_as_of_date,
                                                    'DD-MON-RRRR')),
                            0)
                            prepay_applied
                    FROM apps.ap_invoices_all aia,
                         --APPS.AP_INVOICE_DISTRIBUTIONS_ALL AIDA,
                         apps.ap_invoice_payments_all aipa,
                         apps.ap_suppliers aps,
                         apps.ap_supplier_sites_all apsa,
                         apps.hr_operating_units hou
                   WHERE     aia.invoice_id = aipa.invoice_id
                         --AND AIDA.INVOICE_ID = AIPA.INVOICE_ID
                         AND aia.vendor_id = aps.vendor_id
                         AND aps.vendor_id = apsa.vendor_id
                         AND aia.vendor_site_id = apsa.vendor_site_id
                         AND aia.org_id = hou.organization_id
                         AND aia.invoice_type_lookup_code = 'PREPAYMENT'
                         AND ap_invoices_pkg.get_posting_status (
                                aia.invoice_id) = 'Y'
                         AND aia.org_id = NVL (:org_id, aia.org_id)
                         AND aps.vendor_name =
                                NVL (:p_vendor_name, aps.vendor_name)
                         --AND TO_DATE (AIDA.ACCOUNTING_DATE, 'DD-MON-RRRR') <=
                         --     TO_DATE (:P_AS_OF_DATE, 'DD-MON-RRRR')
                         AND TO_DATE (aipa.accounting_date, 'DD-MON-RRRR') <=
                                TO_DATE (:p_as_of_date, 'DD-MON-RRRR')
                GROUP BY aps.vendor_name,
                         --AIDA.DIST_CODE_COMBINATION_ID,
                         aia.invoice_type_lookup_code,
                         aia.invoice_num,
                         aia.invoice_id,
                         aia.invoice_date,
                         aia.gl_date,
                         hou.name,
                         aia.invoice_currency_code,
                         NVL (aia.exchange_rate, 1),
                         aia.doc_sequence_value,
                         aia.payment_status_flag,
                         aia.description))
 WHERE functional_balance <> 0;

Convert Number to Words Using PL/SQL Function

Convert Number to Words Using PL/SQL Function


/* Formatted on 2013/03/07 18:40 (Formatter Plus v4.8.8) */
CREATE OR REPLACE FUNCTION spell_number (p_amt IN NUMBER, POH_CURRENCY_CODE in varchar2)
   RETURN VARCHAR2
IS
   m_main_amt_text     VARCHAR2 (2000);
   m_top_amt_text      VARCHAR2 (2000);
   m_bottom_amt_text   VARCHAR2 (2000);
   m_decimal_text      VARCHAR2 (2000);
   m_top               NUMBER (20, 5);
   m_main_amt          NUMBER (20, 5);
   m_top_amt           NUMBER (20, 5);
   m_bottom_amt        NUMBER (20, 5);
   m_decimal           NUMBER (20, 5);
   m_amt               NUMBER (20, 5);
   m_text              VARCHAR2 (2000);
   r_val               VARCHAR2 (10)   := 'Dollar ';
   v_curr varchar2(10);
BEGIN
   m_main_amt := NULL;
   m_top_amt_text := NULL;
   m_bottom_amt_text := NULL;
   m_decimal_text := NULL;
   -- To get paise part
   m_decimal := p_amt - TRUNC (p_amt);

   IF m_decimal > 0
   THEN
      m_decimal := m_decimal * 100;
   END IF;

   m_amt := TRUNC (p_amt);
   m_top := TRUNC (m_amt / 100000);
   m_main_amt := TRUNC (m_top / 100);
   m_top_amt := m_top - m_main_amt * 100;
   m_bottom_amt := m_amt - (m_top * 100000);
   m_top_amt_text := TO_CHAR (TO_DATE (m_amt, 'J'), 'JSP');

   /*IF m_main_amt > 0
   THEN
      m_main_amt_text := TO_CHAR (TO_DATE (m_amt, 'J'), 'JSP');

     /* IF m_main_amt = 1
      THEN
         m_main_amt_text := m_main_amt_text || ' CRORE ';
      ELSE
         m_main_amt_text := m_main_amt_text || ' CRORES ';
      END IF;
   END IF;

   IF m_top_amt > 0
   THEN
      m_top_amt_text := TO_CHAR (TO_DATE (m_amt, 'J'), 'JSP');

      IF m_top_amt = 1
      THEN
         m_top_amt_text := m_top_amt_text || ' LAKH ';
      ELSE
         m_top_amt_text := m_top_amt_text || ' LAKHS ';
      END IF;
   END IF;*/

   IF m_bottom_amt > 0
   THEN
      m_bottom_amt_text := TO_CHAR (TO_DATE (m_bottom_amt, 'J'), 'JSP')
                           || ' ';
   END IF;

   IF m_decimal > 0  
   THEN  
      IF NVL (m_bottom_amt, 0) + NVL (m_top_amt, 0) > 0
      THEN
          --          srw.message(111,'m_bottom_amt is '||m_bottom_amt);
          --    srw.message(111,'m_top_amt is '||m_top_amt);
      BEGIN
         
          if (POH_CURRENCY_CODE = 'EUR') then
                 v_curr := 'Cents';
          elsif (POH_CURRENCY_CODE = 'USD') then
                 v_curr := 'Cents';
          elsif (POH_CURRENCY_CODE = 'OMR') then
                 v_curr := 'Baisa';
          elsif (POH_CURRENCY_CODE = 'AED') then
                 v_curr := 'Fils';    
          else
                v_curr := 'Paisa';
           end if;
         
            --m_decimal_text := ' AND ' || TO_CHAR (TO_DATE (m_decimal, 'J'), 'JSP')|| ' Cent ';
            m_decimal_text := ' AND ' ||' '||v_curr||' '|| TO_CHAR (TO_DATE (m_decimal, 'J'), 'JSP');
           
         END;
      ELSE
              if (POH_CURRENCY_CODE = 'EUR') then
                 v_curr := 'Cents';
          elsif (POH_CURRENCY_CODE = 'USD') then
                 v_curr := 'Cents';
          elsif (POH_CURRENCY_CODE = 'OMR') then
                 v_curr := 'Baisa';
          elsif (POH_CURRENCY_CODE = 'AED') then
                 v_curr := 'Fils';    
          else
                v_curr := 'Paisa';
           end if;
         
         --m_decimal_text :=  TO_CHAR (TO_DATE (m_decimal, 'J'), 'JSP') || ' Cent ';
         m_decimal_text := 'AND'||' '||v_curr||' '||  TO_CHAR (TO_DATE (m_decimal, 'J'), 'JSP');
       
         r_val := '';
      END IF;
   END IF;

   m_text :=
    --     r_val
    --  || LOWER (   m_main_amt_text
                (m_top_amt_text
                || m_decimal_text
               )
      || ' ONLY';
 
   --   dbms_output.put_line('m_text is '||m_text);
 --  m_text := UPPER (SUBSTR (m_text, 1, 1)) || SUBSTR (m_text, 2);  252345.36
--   m_text := SUBSTR (m_text, 2);
 --  m_text := ' ' || m_text;
   RETURN (REPLACE(UPPER(m_text),'-',' '));
END ;

Example:

SELECT spell_number(:AMOUNT,'USD') FROM DUAL;

==========================================================


/* Formatted on 10-01-2015 03:20:54 PM (QP5 v5.163.1008.3004) */
CREATE OR REPLACE FUNCTION MONEY_TO_WORDS (P_MONEY IN NUMBER)
   RETURN VARCHAR2
AS
   W_RETURN   VARCHAR2 (255);
BEGIN
   IF P_MONEY < 0
   THEN
      W_RETURN := 'Negative number is not allowed!';
   ELSIF P_MONEY = 0
   THEN
      W_RETURN := 'Zero Euro and zero cents';
   ELSE
      IF (TRUNC (P_MONEY) = 0)
      THEN
         W_RETURN := 'Zero Euros';
      ELSIF (TRUNC (P_MONEY) = 1)
      THEN
         W_RETURN := 'One Euro';
      ELSE
         W_RETURN := TO_CHAR (TO_DATE (TRUNC (P_MONEY), 'J'), 'JSP');
      END IF;

      IF ( (P_MONEY - TRUNC (P_MONEY)) = 0)
      THEN
         W_RETURN := W_RETURN || ' Exactly';
      ELSIF ( (P_MONEY - TRUNC (P_MONEY)) * 100 = 1)
      THEN
         W_RETURN := W_RETURN || ' and one cent';
      ELSE
         W_RETURN :=
            W_RETURN || 'and'
            || TO_CHAR (TO_DATE ( (P_MONEY - TRUNC (P_MONEY)) * 100, 'J'),
                        'JSP')
            || 'cents';
      END IF;
   END IF;

   RETURN W_RETURN;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.PUT_LINE ('Error : ' || SQLERRM);
      RETURN 'CAN NOT CONVERT YOUR INPUT TO WORDS!';
END;
/


Example:
SELECT MONEY_TO_WORDS(0) FROM DUAL;