Sunday, 17 June 2018

How to create org id by using api Oracle apps R12

--------------API TO CREATE BUSINESS GROUP IN BACK END.
CREATE OR REPLACE package body APPS.test_pkg1 is

procedure create_org(errbuff out varchar2,retcode out number) is
--Cursor to fetch the information stored inside the XX_ORG TABLE
cursor org_info is
select org.org_name,bg_name,loc,dt_start,dt_end
from
xx_org org;
 --Cursor to fetch the information stored inside the
        --hr_all_organization_units by passing the name of the business group.
cursor org_bg(cp_bg_name varchar2) is
select organization_id,date_from from hr_all_organization_units where name=cp_bg_name;

ln_bg_id number default null;
ld_bg_stdt date default sysdate;
lv_succ_status  varchar2(10) default 'SUCCESS';
lv_error_status  varchar2(10) default 'ERROR';
lv_error_msg    varchar2(500) default null;
lv_status      varchar2(10);
ln_org_id       number default 0;
ln_obj_ver_no   number default 0;
lb_org_warning  boolean default false;
begin
fnd_file.put_line(1,'Begin Process...');
--Opening the cursor Org_info to fetch the records into org_rec variable
for org_rec in org_info
loop
lv_error_msg:=null;
ln_org_id:=0;
ln_obj_ver_no:=0;
lb_org_warning:=false;
ln_bg_id:=null;
ld_bg_stdt:=sysdate;
lv_status:=lv_succ_status;
fnd_file.put_line(1,'Begin creating organization : '||org_rec.org_name);

 --Opening the cursor org_bg by passing the business group name from the above cursor variable.
   open org_bg(cp_bg_name => org_rec.bg_name);
     --Fetching the records into two different variables from the above cursor Org_info
        fetch org_bg into ln_bg_id,ld_bg_stdt;
        -- Close the cursor org_bg
   close org_bg;
fnd_file.put_line(1,'               BG ID : '||ln_bg_id);
fnd_file.put_line(1,'               BG start dt : '||to_char(ld_bg_stdt,'dd-mon-yyyy'));     
fnd_file.put_line(1,'               org start dt : '||to_char(org_rec.dt_start,'dd-mon-yyyy'));
fnd_file.put_line(1,'              1 error status : '||lv_status);

 --Passing the variable Business Group ID and verifying that whether it is an existing Business Group or Not.
         --If the Business Group Id is NULL then it will enter into the if condition and
         --updates the error msgs in the pqr_org_load table.


   if ln_bg_id is null then
        lv_status:=lv_error_status;
        lv_error_msg:='Business group does not exists';
   end if;
fnd_file.put_line(1,'             2 error status : '||lv_status);


--Passing the variable Business Group Start Date and verifying that whether it is greater then the
--Organization start date or not.

        if ld_bg_stdt > org_rec.dt_start then
        lv_status:=lv_error_status;
        lv_error_msg:=lv_error_msg||' Business group start date is after org start date';
   end if;
   fnd_file.put_line(1,'             3 error status : '||lv_status);
 
--If the above condition is satisfied then we will create the Organization for that particular Business Group.
   
   if lv_status<>lv_error_status then
 
   hr_organization_api.create_organization( p_validate                  => false
                                           ,p_effective_date            => sysdate
                                           ,p_business_group_id         => ln_bg_id
                                           ,p_date_from                 => org_rec.dt_start
                                           ,p_name                      => org_rec.org_name
                                           ,p_organization_id           => ln_org_id
                                           ,p_object_version_number     => ln_obj_ver_no
                                           ,p_duplicate_org_warning     => lb_org_warning);
fnd_file.put_line(1,'               created Organization : '||ln_org_id);                                           
        update xx_org set status=lv_succ_status,error_msg='Organization '||org_rec.org_name||' created with org id : '||ln_org_id
        where org_name=org_rec.org_name;
                                             
   else
        update xx_org set status=lv_error_status,error_msg=lv_error_msg
        where org_name=org_rec.org_name;
fnd_file.put_line(1,' Error message  : '||lv_error_msg);           
   end if;
 fnd_file.put_line(1,'Completion of org creation : '||org_rec.org_name);     

end loop;
commit;
exception
when others then
fnd_file.put_line(1,'exception occured '||SQLERRM);


end create_org;
end test_pkg1;
/

Payables invoice prepayment query in Oracle Apps R12


SELECT   pv.vendor_name C_vendor_name,
         pvs.address_line1 C_address_line1,
         pvs.address_line2 C_address_line2,
         pvs.address_line3 C_address_line3,
            DECODE (pvs.city, '', '', pvs.city || ', ')
         || DECODE (pvs.state, '', '', pvs.state || ' ')
         || pvs.zip
            C_city_state_zip,
         pvs.country C_country,
         aipp.last_update_date C_application_date,
         aipp.prepayment_amount_applied C_amount_applied,
         inv.invoice_currency_code C_currency_code,
         pp.invoice_num C_prepay_num,
         inv.invoice_num C_invoice_num,
         NVL (inv.invoice_amount, 0) - NVL (inv.amount_paid, 0)
            C_amt_remaining
  FROM   ap_suppliers pv,
         ap_supplier_sites_all pvs,
         ap_invoices_all inv,
         ap_invoices_all pp,
         ap_invoice_prepays_all aipp
 WHERE       aipp.invoice_id = inv.invoice_id
         AND aipp.prepay_id = pp.invoice_id
         AND inv.vendor_id = pp.vendor_id
         AND inv.vendor_id = pv.vendor_id
         AND pv.vendor_id = pvs.vendor_id
         AND pvs.vendor_site_id = inv.vendor_site_id
         AND NVL (pvs.LANGUAGE, 'AMERICAN') = 'AMERICAN'
         AND aipp.last_update_date >= &InvDate
UNION
SELECT   pv.vendor_name C_vendor_name,
         pvs.address_line1 C_address_line1,
         pvs.address_line2 C_address_line2,
         pvs.address_line3 C_address_line3,
            DECODE (pvs.city, '', '', pvs.city || ', ')
         || DECODE (pvs.state, '', '', pvs.state || ' ')
         || pvs.zip
            C_city_state_zip,
         pvs.country C_country,
         aid2.last_update_date C_application_date,
         NVL (
            ap_invoices_utility_pkg.get_pp_amt_applied_on_date (
               inv.invoice_id,
               pp.invoice_id,
               aid2.last_update_date
            ),
            0
         )
            C_amount_applied,
         inv.invoice_currency_code C_currency_code,
         pp.invoice_num C_prepay_num,
         inv.invoice_num C_invoice_num,
         NVL (inv.invoice_amount, 0)
         - (ap_invoices_pkg.get_prepaid_amount (inv.invoice_id))
            C_amt_remaining
  FROM   ap_suppliers pv,
         ap_supplier_sites_all pvs,
         ap_invoices_all inv,
         ap_invoices_all pp,
         ap_invoice_distributions_all aid1,
         ap_invoice_distributions_all aid2
 WHERE       aid1.invoice_id = inv.invoice_id
         AND aid2.invoice_id = pp.invoice_id
         AND aid2.invoice_distribution_id = aid1.prepay_distribution_id
         AND aid1.line_type_lookup_code = 'PREPAY'
         AND inv.vendor_id = pp.vendor_id
         AND inv.vendor_id = pv.vendor_id
         AND pv.vendor_id = pvs.vendor_id
         AND pvs.vendor_site_id = inv.vendor_site_id
         AND NVL (aid1.reversal_flag, 'N') != 'Y'
         AND NVL (pvs.LANGUAGE, 'AMERICAN') = 'AMERICAN'
         AND inv.invoice_date >= &InvDat

Friday, 8 June 2018

How to find the RMA order receipt details in Oracle Apps R12 ?


SELECT ooha.ORDER_NUMBER "SALES ORDER"
              ,ooha.ORDER_CATEGORY_CODE
              ,oola.ORDERED_ITEM
              ,oola.SUBINVENTORY
              ,rsh.SHIPMENT_NUM
              ,rsh.RECEIPT_NUM
              ,rsh.CUSTOMER_ID
              ,rsl.UNIT_OF_MEASURE
              ,rsl.ITEM_DESCRIPTION
              ,rsl.SHIPMENT_LINE_STATUS_CODE
              ,rsl.SOURCE_DOCUMENT_CODE

FROM OE_ORDER_HEADERS_ALL ooha
           ,OE_ORDER_LINES_ALL oola
           ,RCV_SHIPMENT_HEADERS rsh
           ,RCV_SHIPMENT_LINES rsl

WHERE  1=1
AND ooha.header_id                                = oola.header_id
AND ooha.header_id                                = rsl.OE_ORDER_HEADER_ID
AND rsh.shipment_header_id                  = rsl.shipment_header_id
AND rsl.OE_ORDER_LINE_ID                = o ola.line_id 
AND ooha.ORDER_NUMBER                 = '56' 
AND rsl.SOURCE_DOCUMENT_CODE = 'RMA';

Saturday, 26 May 2018

How to delete the records from a table by using bulk collect and forall ?

Hi, In this article We are going to know how to delete the records by using bulk binds(Bulk collect & Forall).


CREATE OR REPLACE PACKAGE XX_BULK_RECORDS_DELETE_PKG
IS

PROCEDURE XX_BULK_DELETE;

END XX_BULK_RECORDS_DELETE_PKG;

/
SHO ERRORS
/


CREATE OR REPLACE PACKAGE BODY XX_BULK_RECORDS_DELETE_PKG
IS

PROCEDURE XXPC_BULK_DELETE
IS
-- +====================================================================+
-- | lcu_mtl_trxns cursor is used to get the transactions from
-- | mtl_material_transactions which are not having consted_flag as 'Y'
-- +====================================================================+
CURSOR  lcu_mtl_trxns
IS
SELECT  transaction_id
FROM    mtl_material_transactions_bkup
WHERE   costed_flag <> 'Y'
AND     organization_id = 889;

-- +====================================================================+
-- |Declaring Local Variables.                                       
-- +====================================================================+
TYPE bulk_rec IS TABLE OF lcu_mtl_trxns%rowtype;
bulk_tab    bulk_rec;
bulk_errors NUMBER;
dml_errors  EXCEPTION;
PRAGMA exception_init(dml_errors,-24381);

BEGIN

OPEN lcu_mtl_trxns;
LOOP
FETCH lcu_mtl_trxns BULK COLLECT INTO bulk_tab LIMIT 100;

FORALL indx IN bulk_tab.FIRST .. bulk_tab.LAST SAVE EXCEPTIONS
DELETE FROM mtl_material_transactions_bkup
WHERE transaction_id = bulk_tab(indx).transaction_id;
EXIT WHEN lcu_mtl_trxns%notfound;

END LOOP;
CLOSE lcu_mtl_trxns;

COMMIT;

EXCEPTION
WHEN dml_errors THEN
bulk_errors := SQL%BULK_EXCEPTIONS.COUNT;
dbms_output.put_line('number of statements failed are '||bulk_errors);
FOR ind IN 1..bulk_errors LOOP
dbms_output.put_line('error #'||ind|| ' is occured during '|| 'iterations #' ||sql%bulk_exceptions(ind).error_index);
dbms_output.put_line('error  message is ' || SQLERRM(-sql%bulk_exceptions(ind).error_code));

end loop;

WHEN OTHERS THEN
dbms_output.put_line('Err is: '||SQLCODE ||' , '||SQLERRM);
END XX_BULK_DELETE;

END XX_BULK_RECORDS_DELETE_PKG;
/
SHO ERRORS
/
EXEC XX_BULK_RECORDS_DELETE_PKG.XXPC_BULK_DELETE;

select * from mtl_material_transactions_bkup;

How to find the receipt details based on requisition ?

This query is used to find the receipt details based on requisition.


SELECT  prh.segment1 "Req Number"
       ,prh.requisition_header_id
       ,prh.org_id "Req orgid"
       ,prh.creation_date
       ,prl.requisition_line_id
       ,prl.line_num
       ,prl.item_description "req line description"
       ,prd.distribution_id
       ,prd.set_of_books_id
       ,pda.po_distribution_id
       ,pla.po_line_id
       ,pla.line_num "Po Linenum"
       ,pha.segment1 "Po Number"
       ,pha.po_header_id
       ,as1.segment1 "Vendor Number"
       ,as1.vendor_name
       ,rt.TRANSACTION_TYPE
       ,rsl.shipment_line_id
       ,rsl.line_num "Shipment Linenum"
       ,rsl.shipment_line_status_code
       ,rsl.item_id
       ,rsl.source_document_code
       ,rsl.from_organization_id
       ,rsl.to_organization_id
       ,rsl.to_subinventory
       ,rsl.quantity_shipped
       ,rsl.quantity_received
       ,rsl.deliver_to_person_id
       ,rsl.item_description "Shipment lines Description"
       ,rsl.unit_of_measure
       ,rsh.receipt_num
       ,rsh.shipment_num
   
FROM    po_requisition_headers_All prh
       ,po_requisition_lines_All prl
       ,po_req_distributions_All prd
       ,po_distributions_all pda
       ,po_lines_all pla
       ,po_headers_all pha
       ,ap_suppliers as1
       ,rcv_transactions rt
       ,rcv_shipment_lines rsl
       ,rcv_shipment_headers rsh
   
WHERE 1=1
AND   prh.segment1              =  '143'
AND   prh.org_id                = 791
AND   prh.requisition_header_id = prl.requisition_header_id
AND   prl.requisition_line_id   = prd.requisition_line_id
AND   prd.distribution_id       = pda.req_distribution_id(+)
AND   pla.po_line_id            = pda.po_line_id         
AND   pha.po_header_id          = pla.po_header_id         
AND   pha.org_id                = 791                     
AND   pha.type_lookup_code      NOT IN ('RFQ','QUOTATION')
-- AND   pha.segment1 = '102'
AND   pha.vendor_id             = as1.vendor_id             
AND   pha.po_header_id          = rt.po_header_id           
AND   pla.po_line_id            = rt.po_line_id             
AND   pda.po_distribution_id    = rt.po_distribution_id     
AND   rt.organization_id        = 791                       
-- AND   prl.requisition_line_id    = rt.requisition_line_id(+)
AND  rt.shipment_line_id        = rsl.shipment_line_id     
AND  pha.po_header_id           = rsl.po_header_id           
AND  pla.po_line_id             = rsl.po_line_id             
AND  pda.po_distribution_id     = rsl.po_distribution_id       
AND  prd.distribution_id        = rsl.req_distribution_id     
-- AND  prl.requisition_line_id     = rsl.requisition_line_id(+)
AND  rsh.shipment_header_id     = rsl.shipment_header_id; 

How to find the receipt details based on PO number ?

This query is used to find the receipt details based on PO number.


SELECT  prh.segment1 "Req Number"
       ,prh.requisition_header_id
       ,prh.org_id "Req orgid"
       ,prh.creation_date
       ,prl.requisition_line_id
       ,prl.line_num
       ,prl.item_description "req line description"
       ,prd.distribution_id
       ,prd.set_of_books_id
       ,pda.po_distribution_id
       ,pla.po_line_id
       ,pla.line_num "Po Linenum"
       ,pha.segment1 "Po Number"
       ,pha.po_header_id
       ,as1.segment1 "Vendor Number"
       ,as1.vendor_name
       ,rt.TRANSACTION_TYPE
       ,rsl.shipment_line_id
       ,rsl.line_num "Shipment Linenum"
       ,rsl.shipment_line_status_code
       ,rsl.item_id
       ,rsl.source_document_code
       ,rsl.from_organization_id
       ,rsl.to_organization_id
       ,rsl.to_subinventory
       ,rsl.quantity_shipped
       ,rsl.quantity_received
       ,rsl.deliver_to_person_id
       ,rsl.item_description "Shipment lines Description"
       ,rsl.unit_of_measure
       ,rsh.receipt_num
       ,rsh.shipment_num
 
FROM    po_requisition_headers_All prh
       ,po_requisition_lines_All prl
       ,po_req_distributions_All prd
       ,po_distributions_all pda
       ,po_lines_all pla
       ,po_headers_all pha
       ,ap_suppliers as1
       ,rcv_transactions rt
       ,rcv_shipment_lines rsl
       ,rcv_shipment_headers rsh
 
WHERE 1=1
-- AND   prh.segment1              =  '143'
AND   prh.org_id                = 791
AND   prh.requisition_header_id = prl.requisition_header_id
AND   prl.requisition_line_id   = prd.requisition_line_id
AND   prd.distribution_id       = pda.req_distribution_id(+)
AND   pla.po_line_id            = pda.po_line_id       
AND   pha.po_header_id          = pla.po_header_id       
AND   pha.org_id                = 791                   
AND   pha.type_lookup_code      NOT IN ('RFQ','QUOTATION')
AND   pha.segment1 = '102'
AND   pha.vendor_id             = as1.vendor_id           
AND   pha.po_header_id          = rt.po_header_id         
AND   pla.po_line_id            = rt.po_line_id           
AND   pda.po_distribution_id    = rt.po_distribution_id   
AND   rt.organization_id        = 791                     
-- AND   prl.requisition_line_id    = rt.requisition_line_id(+)
AND  rt.shipment_line_id        = rsl.shipment_line_id   
AND  pha.po_header_id           = rsl.po_header_id         
AND  pla.po_line_id             = rsl.po_line_id           
AND  pda.po_distribution_id     = rsl.po_distribution_id     
AND  prd.distribution_id        = rsl.req_distribution_id   
-- AND  prl.requisition_line_id     = rsl.requisition_line_id(+)
AND  rsh.shipment_header_id     = rsl.shipment_header_id;  

Wednesday, 24 January 2018

How to create revenue events by using PA_EVENT_PUB API in R12?

create or replace PACKAGE BODY XXX_6666_reversal_pkg
IS

--==============================================================================
--                          GLOBAL CONSTANTS
--==============================================================================

  CN_PROJECT_CLASS            CONSTANT      VARCHAR2(60)    := 'Revenue Recognition Method';
  CN_CLASS_CODE               CONSTANT      VARCHAR2(30)    := 'ASC606'; 
  CN_REVERSAL_EVENT_TYPE      CONSTANT      VARCHAR2(30)    := 'REVENUE 6666 CONTRA';
  CN_EVENT_QUALIFIER          CONSTANT      VARCHAR2(30)    :=  'T6666';
  CN_6666_CONT_EVENT_QUALIFIER CONSTANT      VARCHAR2(30)   :=  'T6666 Contra';
  CN_606_EVENT_QUALIFIER      CONSTANT      VARCHAR2(30)    :=  'T606';
 

PROCEDURE Debug( p_message  IN  VARCHAR2
               ) IS
lv_message       VARCHAR2(200);
 
BEGIN
 
      lv_message    := SUBSTR(p_message,1,240);
      fnd_file.put_line(fnd_file.log, lv_message);
 
END Debug;


 PROCEDURE XXX_reversal_proc (
                                     p_project_id     NUMBER ,
                                     p_project_num    VARCHAR2,
                                     p_program_mode   VARCHAR2,
                                     p_as_of_date     DATE,
                                     p_event_type     VARCHAR2,
                                     p_task           VARCHAR2
                                     ) IS

-- +====================================================================+
--     LOCAL VARIABLES
-- +====================================================================+
 
       ln_event_id                NUMBER;
       ln_line_num                NUMBER := 0;
       ln_msg_count               NUMBER := 0;
       ln_seq_val                 NUMBER := 0;
       ld_complete_date           DATE;
       lv_flexfield_name          VARCHAR2(100) := 'PA_EVENTS_DESC_FLEX';
       lv_msg_data                VARCHAR2(100);
       lv_bill_hold_flag          VARCHAR2(3)   := 'N';
       lv_product_code            VARCHAR2(100) := 'XXX';
       lv_flag            VARCHAR2(3):='S';
       lv_6666_rev_task    VARCHAR2(40);
   --    lc_proj_rate_type     VARCHAR2(30);  -- Commented on 20-DEC-17
   --    ln_proj_ex_rate       NUMBER;        -- Commented on 20-DEC-17
--    lc_projfunc_rate_type VARCHAR2(30);  -- Commented on 20-DEC-17
   --    ln_projfunc_ex_rate   NUMBER;        -- Commented on 20-DEC-17

     
     
-- +====================================================================+
--   Declaring PLSQL TABLE TYPE VARIABLES.
-- +====================================================================+     

       lt_in_tbl_type     pa_event_pub.event_in_tbl_type;
       lt_out_tbl_type    pa_event_pub.event_out_tbl_type;
     
-- +====================================================================+
--   lcu_6666_reversal Cursor is used to fetch the events data.
-- +====================================================================+

CURSOR lcu_6666_reversal
IS 
SELECT pp.segment1,
       pe.project_id,
       pe.organization_id,
       round(-1 * sum(pe.bill_trans_rev_amount),2) trx_rev_amt,
       pe.bill_trans_currency_code        trx_rev_curr, 
       pe.PROJECT_CURRENCY_CODE  proj_curr,
       round(-1 * sum(pe.PROJECT_REVENUE_AMOUNT)) proj_rev_amt,
       pe.PROJFUNC_CURRENCY_CODE projfunc_curr,
       round(-1 * sum(pe.PROJFUNC_REVENUE_AMOUNT)) projfunc_rev_amt
FROM 
       pa_projects pp,
       pa_project_classes_v ppc,
       pa_tasks pt,
       pa_events pe,
       pa_event_types pet
WHERE ppc.class_category          =  CN_PROJECT_CLASS
AND   ppc.class_code              =  CN_CLASS_CODE
AND   ppc.project_id              =  pp.project_id
AND   pp.project_id               =  p_project_id
AND   pp.project_id               =  pt.project_id
AND   pe.project_id               =  pp.project_id
AND   pt.task_id                  =  pe.task_id
AND   pe.revenue_distributed_flag = 'Y'
AND   pe.event_type               = pet.event_type
AND   pet.attribute3              = CN_EVENT_QUALIFIER
AND   nvl(pe.attribute7,'@#$')   != CN_EVENT_QUALIFIER
AND   pe.completion_date         <=  p_as_of_date
GROUP BY pp.segment1,
         pe.project_id,
         pe.organization_id,
         pe.bill_trans_currency_code
         ,pe.PROJECT_CURRENCY_CODE
         ,pe.projfunc_currency_code
HAVING SUM(pe.bill_trans_rev_amount) != 0
order by 1;

-- +====================================================================+
--   lcu_6666_task Cursor used to fetch the 6666 reversal Task.
-- +====================================================================+
CURSOR lcu_6666_task(p_project_id NUMBER)
IS
SELECT task_number
FROM   pa_tasks pt
WHERE  pt.project_id = p_project_id
AND    pt.attribute6 =  CN_6666_CONT_EVENT_QUALIFIER;


BEGIN
 
  debug('XXX_reversal_proc => begining of procedure');
 
FOR rev_rec IN lcu_6666_reversal
LOOP

     debug('XXX_reversal_proc => Inside rev_rec loop');
   
     SELECT XXX_REV_SEQ.NEXTVAL INTO ln_seq_val FROM DUAL; 
       
        debug('XXX_reversal_proc => ln_seq_val Sequence value '||ln_seq_val);
       
   lv_flag := 'S';
 

   debug('XXX_reversal_proc => LV_FLAG '||LV_FLAG);
   debug('XXX_reversal_proc => projfunc_curr '||rev_rec.projfunc_curr);
   debug('XXX_reversal_proc => proj_curr '||rev_rec.proj_curr);
 
 IF  LV_FLAG <> 'E' then

   
   
      debug('XXX_6666_main => prepare data for Creating event');   

        ln_line_num       := 1;

            lt_in_tbl_type(ln_line_num).p_project_number            := rev_rec.segment1;
            lt_in_tbl_type(ln_line_num).p_event_type                := p_event_type;
            lt_in_tbl_type(ln_line_num).p_description               := 'Revenue reversal for project: '||rev_rec.segment1;
            lt_in_tbl_type(ln_line_num).p_completion_date           := p_as_of_date;
            lt_in_tbl_type(ln_line_num).p_task_number               := lv_6666_rev_task;
            lt_in_tbl_type(ln_line_num).p_organization_name         := lv_org_name;
            lt_in_tbl_type(ln_line_num).p_bill_trans_bill_amount    := 0;
            lt_in_tbl_type(ln_line_num).p_bill_trans_rev_amount     := rev_rec.trx_rev_amt;
            lt_in_tbl_type(ln_line_num).p_desc_flex_name            := lv_flexfield_name;
            lt_in_tbl_type(ln_line_num).p_attribute2                := rev_rec.Organization_Id;
            lt_in_tbl_type(ln_line_num).p_attribute7                := CN_EVENT_QUALIFIER;
            lt_in_tbl_type(ln_line_num).p_bill_hold_flag            := lv_bill_hold_flag;
            lt_in_tbl_type(ln_line_num).p_bill_trans_currency_code  := rev_rec.trx_rev_curr;
            lt_in_tbl_type(ln_line_num).p_pm_event_reference        := '6666 REVERSAL' || ln_seq_val;
          --  lt_in_tbl_type(ln_line_num).P_project_rate_type         := lc_proj_rate_type;     -- Commented on 20-DEC-17
          --  lt_in_tbl_type(ln_line_num).P_project_exchange_rate     := ln_proj_ex_rate;       -- Commented on 20-DEC-17
          --  lt_in_tbl_type(ln_line_num).P_projfunc_rate_type       := lc_projfunc_rate_type; -- Commented on 20-DEC-17
          --  lt_in_tbl_type(ln_line_num).P_projfunc_exchange_rate    := ln_projfunc_ex_rate;   -- Commented on 20-DEC-17
           
-- +====================================================================+
--   Calling PA_EVENT_PUB api,
--   to create a reversal event for 6666 revenue events.
-- +====================================================================+     
 debug('XXX_6666_main => calling API');
    pa_event_pub.create_event(
                p_api_version_number   => 1.0,
                p_commit               => fnd_api.g_true,
                p_init_msg_list        => fnd_api.g_true,
                p_pm_product_code      => lv_product_code,
                p_event_in_tbl         => lt_in_tbl_type,
                p_event_out_tbl        => lt_out_tbl_type,
                p_msg_count            => ln_msg_count,
                p_msg_data             => lv_msg_data,
                p_return_status        => lv_return_status
                               );
                     
     COMMIT;
   
         
   
     IF lv_return_status='S' THEN
   
          SELECT pe.event_id INTO ln_event_id
          FROM   pa_events pe
          WHERE  pe.PM_EVENT_REFERENCE = '6666 REVERSAL' || ln_seq_val
            AND  pe.organization_id = ln_org_id;
   
                                     
              ln_event_id := 0;
   
       
           
     UPDATE PA_EVENTS pe SET pe.attribute7 = CN_EVENT_QUALIFIER
     WHERE  pe.project_id = rev_rec.project_id
         AND  pe.revenue_distributed_flag = 'Y'
      --   AND pe.event_type = rev_rec.event_type
      --   AND pe.task_id    = rev_rec.task_id
         AND nvl(pe.attribute7,'@#$') != CN_EVENT_QUALIFIER  
         AND pe.completion_date  <=  p_as_of_date; 

         COMMIT; 

     ELSE
          debug('XXX_reversal_proc => Return Status: '||lv_return_status);

     END IF;
   
 END IF;
 
END LOOP;
 
    debug('XXX_reversal_proc => end of procedure');
 
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    debug('XXX_reversal_proc => No data found to reverse for the project number:' ||p_project_num);
  WHEN OTHERS THEN
    debug('XXX_reversal_proc => Error is '||SQLCODE||','||SQLERRM||' for project number:' ||p_project_num);
 
END XXX_reversal_proc;



PROCEDURE XXX_6666_main(
        errbuf               OUT VARCHAR2,
        retcode              OUT VARCHAR2,
        p_project_from       IN  VARCHAR2,
        p_project_to         IN  VARCHAR2,
        p_period             IN  VARCHAR2,
        p_program_mode       IN  VARCHAR2
                          )
IS

-- +====================================================================+
--     Local VARIABLES
-- +====================================================================+

 lv_resp_name       VARCHAR2(100);
 lv_user_name       VARCHAR2(100);
 ln_request_id      NUMBER;
 ld_as_of_date      DATE;
 lv_6666_event_type  VARCHAR2(40);
 lv_flag            CHAR(1);
 lv_6666_rev_task    VARCHAR2(40);


CURSOR lcu_6666_main
IS
SELECT pp.segment1 project_number
      ,pp.project_id
FROM   pa_projects pp,
       pa_project_classes_v ppc,
       pa_events pe,
       pa_event_types pet
WHERE ppc.class_category        = CN_PROJECT_CLASS
AND   ppc.class_code            = CN_CLASS_CODE
AND   ppc.project_id            = pp.project_id
AND   pp.project_id             = pe.project_id
and   pe.event_type             = pet.event_type
and   pet.attribute3            = CN_EVENT_QUALIFIER
AND   pp.segment1 BETWEEN NVL(p_project_from,pp.segment1) AND NVL(p_project_to,pp.segment1)
AND   nvl(pe.attribute7,'@#$') != CN_EVENT_QUALIFIER
GROUP BY  pp.segment1
         ,pp.project_id;

-- +====================================================================+
--   lcu_org_name Cursor used to fetch the organisation name.
-- +====================================================================+
CURSOR lcu_org_name(p_org_id number)
IS
SELECT hou.NAME
FROM   hr_operating_units hou
WHERE  hou.organization_id = p_org_id;


BEGIN

  debug('XXX_6666_main => begining of procedure');

-- +====================================================================+
--   Initalizing the variables.
-- +====================================================================+
  ln_org_id        := fnd_global.org_id;
  ln_request_id    := fnd_global.conc_request_id;
  lv_resp_name     := fnd_profile.value('RESP_NAME');
  lv_user_name     := fnd_profile.value('USERNAME');
 
-- +====================================================================+
--   Initalizing session.
-- +====================================================================+
  mo_global.set_policy_context('S',ln_org_id);
 
 
 
    SELECT TO_DATE(fnd_date.canonical_to_date(p_period),'YY-MON-DD')             
           INTO   ld_as_of_date
    FROM   dual;
   
    OPEN  lcu_org_name(ln_org_id);
        FETCH lcu_org_name INTO lv_org_name;
               IF lcu_org_name%NOTFOUND THEN
                  lv_flag := 'E';
                  debug('XXX_6666_main => Organization name not found');
               END IF;
    CLOSE lcu_org_name;
 

FOR lr_rec_6666_main IN lcu_6666_main
LOOP
 
 -- +====================================================================+
-- | Calling procedure XXX_reversal_proc to create the reversal 
-- | event.                                                           
-- +====================================================================+ 
     XXX_reversal_proc(lr_rec_6666_main.project_id
                             ,lr_rec_6666_main.project_number
                             ,p_program_mode
                             ,ld_as_of_date
                             ,CN_REVERSAL_EVENT_TYPE
                             ,lv_6666_rev_task);
   

END LOOP;

debug('XXX_6666_main => Complete generating events');
-- +====================================================================+
--   Printing output in concurrent program output.
-- +====================================================================+
 IF p_program_mode = 'FINAL' THEN
      report_success;
      report_errors;
 ELSE
      draft_output;
      report_errors;
 END IF;
  debug('XXX_6666_main => end of procedure');

EXCEPTION
WHEN NO_DATA_FOUND THEN
      debug('XXX_6666_main => No data found to reverse for the given projects from '||p_project_from || ' to ' || p_project_to);

WHEN OTHERS THEN
   debug('XXX_6666_main => Error is: '||SQLCODE||','||SQLERRM);
END XXX_6666_main;
END XXX_6666_reversal_pkg;
/
SHO ERRORS
/

How to schedule PO workflow schedule process

create or replace PACKAGE APPS.XXXX_PO_WF_SCHEDULING_PKG IS    --|==========================================================================...