Friday, December 5, 2025

Query to get Sales Order Customer details

 SELECT  ooha.order_number

     ,  ooha.org_id

     ,  ooha.sold_to_org_id bill_cust_account_id

     ,  ooha.ship_to_org_id ship_to_site_use_id

     ,  ooha.invoice_to_org_id bill_to_site_use_id

     ,  hp.party_name "Customer Name"

     ,  hca.account_name

     ,  hcasab.orig_system_reference bill_to_orig_ref

     ,  hpb.status bill_to_status

     ,  bill_loc.address1

        || ', '

        || bill_loc.address2

        || ', '

        || bill_loc.address3

        || ', '

        || bill_loc.city

        || ', '

        || bill_loc.postal_code

        || ', '

        || bill_loc.country

           bill_to_address

     ,  hcasas.orig_system_reference ship_to_orig_ref

     ,  hps.status ship_to_status

     ,  ship_loc.address1

        || ', '

        || ship_loc.address2

        || ', '

        || ship_loc.address3

        || ', '

        || ship_loc.city

        || ', '

        || ship_loc.postal_code

        || ', '

        || ship_loc.country

           ship_to_address

  FROM  apps.oe_order_headers_all ooha

     ,  apps.hz_parties hp

     ,  apps.hz_cust_accounts hca

     ,  apps.hz_cust_acct_sites_all hcasab

     ,  apps.hz_cust_acct_sites_all hcasas

     ,  apps.hz_cust_site_uses_all hzsuab

     ,  apps.hz_cust_site_uses_all hzsuas

     ,  apps.hz_party_sites hps

     ,  apps.hz_party_sites hpb

     ,  apps.hz_locations bill_loc

     ,  apps.hz_locations ship_loc

 WHERE 1 = 1

   AND hp.party_id  =  hca.party_id

   AND hca.cust_account_id  = ooha.sold_to_org_id

   AND hcasab.cust_account_id   = hca.cust_account_id

   AND hcasas.cust_account_id   = hca.cust_account_id

   AND hpb.location_id               = bill_loc.location_id

   AND hps.location_id               = ship_loc.location_id

   AND hcasab.party_site_id      = hpb.party_site_id

   AND hcasas.party_site_id      = hps.party_site_id

   AND hcasab.cust_acct_site_id = hzsuab.cust_acct_site_id

   AND hcasas.cust_acct_site_id = hzsuas.cust_acct_site_id

   AND ooha.ship_to_org_id      = hzsuas.site_use_id

   AND ooha.invoice_to_org_id   = hzsuab.site_use_id

   AND ooha.order_number        =  '&Enter_Order_Number';

Query to get Concurrent program details with Value sets

 SELECT cp.user_concurrent_program_name "Program Name",

cp.concurrent_program_name "Short Name",

ap.application_name "Application",

cp.description "Progam Description",

cp.enabled_flag "Enabled Flag",

cp.output_file_type "Output Format",

cx.executable_name "Executable Short Name",

lv.meaning "Executable Method",

cx.user_executable_name "Executable Name",

df.column_seq_num "Sequence",

df.end_user_column_name "Parameter" ,

df.description "Parameter Desciption",

df.enabled_flag "Parameter Enabled",

df.required_flag "Parameter Required",

df.security_enabled_flag "Enable Security",

df.display_flag "Parameter Display",

fvs.flex_value_set_name "Value Set",

df.default_type "Default Type",

df.default_value "Default Value"

FROM apps.fnd_concurrent_programs_vl cp,

apps.fnd_executables_form_v cx,

apps.fnd_application_vl ap,

apps.fnd_descr_flex_col_usage_vl df,

apps.fnd_flex_value_sets fvs,

apps.fnd_lookup_values lv

WHERE cp.executable_id            = cx.executable_id

AND cp.application_id                  = ap.application_id

AND cx.execution_method_code  = lv.lookup_code(+)

AND '$SRS$.'||cp.concurrent_program_name = df.descriptive_flexfield_name(+)

AND df.flex_value_set_id             = fvs.flex_value_set_id(+)

AND NVL(lv.lookup_type,'CP_EXECUTION_METHOD_CODE') = 'CP_EXECUTION_METHOD_CODE'

AND NVL(lv.language,'US') = 'US'

AND cp.user_concurrent_program_name = 'Enter your concurrent program name'

ORDER BY cp.user_concurrent_program_name, df.column_seq_num;

Sunday, November 16, 2025

Update QA_RESULTS table using Interface table- Oracle Apps R12

Updating QA_RESULTS using the interface table in Oracle Apps R12 follows below steps:

Insert or update records in the QA_RESULTS_INTERFACE table with the desired quality results data.
Ensure all mandatory columns are populated and the UPDATE_FLAG is set appropriately: UPDATE_FLAG = 2 for updating existing QA_RESULTS records. Any other value for UPDATE_FLAG (or leaving it null) will create new QA_RESULTS records.

For updates, the MATCHING_ELEMENTS column in QA_RESULTS_INTERFACE must be populated to identify the target QA_RESULTS record. 


    ln_user_id                 NUMBER := 54667;
    ln_resp_id                 NUMBER := 44234;
    ln_resp_appl_id        NUMBER := 11276;
    ld_last_update_date  DATE   := SYSDATE;
    l_sql                          VARCHAR2(2000);
    ln_request_id            NUMBER;
BEGIN
    l_sql := 'INSERT INTO qa_results_interface
              (
               collection_id
              ,organization_id
              ,organization_code
              ,plan_id
              ,plan_name
              ,matching_elements
              ,validate_flag
              ,insert_type
              ,process_status
              ,last_update_date
              ,last_updated_by
              ,character11
              )
            VALUES(
               2334
              ,124
              ,:organization_code
              ,345
              ,:plan_name
              ,:matching_elements
              ,2
              ,2
              ,1
              ,:last_update_date
              ,-1
              ,:character11
             )';

        EXECUTE IMMEDIATE l_sql USING
              'ERT'                     -- organization_code
             ,'XXINV_COLLECTION_PLAN'   -- plan_name
             ,'COLLECTION_ID'           -- matching_elements
             ,ld_last_update_date       -- last_update_date
             ,'Update Testing';         -- character11
            
            COMMIT;
        --  Call standard import program to update base table.
        BEGIN
            fnd_global.apps_initialize (ln_user_id, ln_resp_id, ln_resp_appl_id);
            ln_request_id := fnd_request.submit_request 
                           ( application => 'QA'
                            ,program     => 'QLTTRAMB'    -- Collection Import Manager
                            ,argument1   => '200'
                            ,argument2   => '2'                      -- 2 for update, 1 for Insert/create
                            ,argument3   => ln_user_id
                            ,argument4   => 'Yes'
                            );
        EXCEPTION
            WHEN others THEN
            dbms_output.put_line(' --> Error1: '||SQLERRM);
        END;
EXCEPTION
    WHEN others THEN
    dbms_output.put_line(' --> Error in main script is: '||SQLERRM);
END;
/

Base table: QA.QA_RESULTS
Interface table: QA.QA_RESULTS_INTERFACE
Interface Error table: QA.QA_INTERFACE_ERRORS

Friday, February 7, 2025

Query to get Concurrent Program Data Template details

 SELECT  fcpt.user_concurrent_program_name

      , fcp.concurrent_program_name
      , fet.user_executable_name executable_name
      , fe.executable_name executable_short_name
      , fet.description
      , fe.execution_file_name
      , fcp.enabled_flag
      , xtt.template_name
      , xddv.data_source_name
      , xddv.data_source_code
      , xl.file_name
      , xl.lob_code
      , xl.language
      , xl.territory
      , xl.creation_date
      , xl.last_update_date

FROM fnd_concurrent_programs_tl fcpt

      , fnd_concurrent_programs fcp
      , xdo_templates_b xtb
      , xdo_templates_tl xtt
      , xdo_ds_definitions_vl xddv
      , xdo_lobs xl
      , apps.fnd_executables fe
      , apps.fnd_executables_tl fet

WHERE fcpt.concurrent_program_id = fcp.concurrent_program_id

  AND xtb.data_source_code = fcp.concurrent_program_name
  AND xtb.template_code = xtt.template_code
  AND xtb.data_source_code = xddv.data_source_code
  AND xl.lob_code = xtb.template_code
  AND xl.xdo_file_type = xtb.template_type_code
  AND fet.application_id = fe.application_id
  AND fet.executable_id = fe.executable_id
  AND fcp.application_id = fe.application_id
  AND fcp.executable_id = fe.executable_id
  AND fcpt.language = 'US'
  AND xtt.language = 'US'
  AND fet.language = 'US'

GROUP BY fcpt.user_concurrent_program_name

      , fcp.concurrent_program_name
      , fet.user_executable_name
      , fe.executable_name
      , fet.description
      , fe.execution_file_name
      , fcp.enabled_flag
      , xtt.template_name
      , xddv.data_source_name
      , xddv.data_source_code
      , xl.file_name
      , xl.lob_code
      , xl.language
      , xl.territory
      , xl.creation_date
      , xl.last_update_date;

Query to get Bill To and Ship To address details of AR Invoice

SELECT (SELECT name FROM v$database) instance,

  ct.trx_number, -- ct.interface_header_attribute1, ct.interface_header_attribute3,
  ct.old_trx_number, hou.name ou_name,
  ct.recurred_from_trx_number,
  ct.trx_date,
  ct.batch_id,
  ct.batch_source_id,
  ct.reason_code,
  ct.term_id,
  ct.complete_flag,
  ct.invoice_currency_code,
  ct.purchase_order,
  rac_bill_party.party_name bill_party_name,
  rac_bill.account_number bill_account_number,
  su_bill.LOCATION bill_location,
  raa_bill_loc.address1    bill_address1,
  raa_bill_loc.address2    bill_address2,
  raa_bill_loc.address3    bill_address3,
  raa_bill_loc.city        bill_city,
  raa_bill_loc.county      bill_county,
  raa_bill_loc.state       bill_state,
  raa_bill_loc.province    bill_province,
  raa_bill_loc.postal_code bill_postal_code,
  rac_ship_party.party_name ship_party_name,
  rac_ship.account_number ship_account_number,
  su_ship.LOCATION bill_location,
  raa_ship_loc.address1    ship_address1,
  raa_ship_loc.address2    ship_address2,
  raa_ship_loc.address3    ship_address3,
  raa_ship_loc.city        ship_city,
  raa_ship_loc.county      ship_county,
  raa_ship_loc.state       ship_state,
  raa_ship_loc.province    ship_province,
  raa_ship_loc.postal_code ship_postal_code,
  bs.NAME batch_source_name,
  rab.NAME batch_name,
  ctt.NAME trx_type_name,
  ctt.TYPE trx_type

FROM ra_customer_trx_all ct,

  hz_cust_accounts_all rac_bill,
  hz_parties rac_bill_party,
  hz_cust_accounts_all rac_ship,
  hz_parties rac_ship_party,
  hz_cust_accounts_all rac_paying,
  hz_parties rac_paying_party,
  hz_cust_site_uses_all su_bill,
  hz_cust_site_uses_all su_ship,
  hz_cust_acct_sites_all raa_bill,
  hz_party_sites raa_bill_ps,
  hz_locations raa_bill_loc,
  hz_cust_acct_sites_all raa_ship,
  hz_party_sites raa_ship_ps,
  hz_locations raa_ship_loc,
  hz_relationships raco_ship_rel,
  hz_parties raco_bill_party,
  hz_relationships raco_bill_rel,
  ra_batch_sources_all bs,
  ra_batches_all rab,
  ra_cust_trx_types_all ctt,
  hr_operating_units hou

WHERE 1   =   1

AND ct.bill_to_customer_id              = rac_bill.cust_account_id
AND rac_bill.party_id                   = rac_bill_party.party_id
AND ct.ship_to_customer_id              = rac_ship.cust_account_id(+)
AND rac_ship.party_id                   = rac_ship_party.party_id(+)
AND ct.paying_customer_id               = rac_paying.cust_account_id(+)
AND rac_paying.party_id                 = rac_paying_party.party_id(+)
AND ct.bill_to_site_use_id              = su_bill.site_use_id
AND ct.ship_to_site_use_id              = su_ship.site_use_id(+)
AND su_bill.cust_acct_site_id           = raa_bill.cust_acct_site_id
AND ct.org_id                           = hou.organization_id
AND raa_bill.party_site_id              = raa_bill_ps.party_site_id
AND raa_bill_loc.location_id            = raa_bill_ps.location_id
AND su_ship.cust_acct_site_id           = raa_ship.cust_acct_site_id(+)
AND raa_ship.party_site_id              = raa_ship_ps.party_site_id(+)
AND raa_ship_loc.location_id(+)         = raa_ship_ps.location_id
AND raco_bill_rel.subject_table_name(+) = 'HZ_PARTIES'
AND raco_bill_rel.object_table_name(+)  = 'HZ_PARTIES'
AND raco_bill_rel.directional_flag(+)   = 'F'
AND raco_bill_rel.subject_id            = raco_bill_party.party_id(+)
AND raco_ship_rel.subject_table_name(+) = 'HZ_PARTIES'
AND raco_ship_rel.object_table_name(+)  = 'HZ_PARTIES'
AND raco_ship_rel.directional_flag(+)   = 'F'
AND ct.batch_source_id                  = bs.batch_source_id
AND ct.batch_id                         = rab.batch_id(+)
AND ct.cust_trx_type_id                 = ctt.cust_trx_type_id
AND ctt.org_id                          = ct.org_id
AND bs.org_id                           = ct.org_id
--AND ct.trx_number IN ('8612110138', '8612110083', '8612180120', '8612180140')
AND rac_bill_party.party_name = 'HD HYUNDAI INFRACORE'
GROUP BY ct.trx_number,
  ct.old_trx_number, hou.name,
  ct.recurred_from_trx_number,
  ct.trx_date,
  ct.batch_id,
  ct.batch_source_id,
  ct.reason_code,
  ct.term_id,
  ct.complete_flag,
  ct.invoice_currency_code,
  ct.purchase_order,
  rac_bill_party.party_name ,
  rac_bill.account_number ,
  su_bill.LOCATION ,
  raa_bill_loc.address1    ,
  raa_bill_loc.address2    ,
  raa_bill_loc.address3    ,
  raa_bill_loc.city        ,
  raa_bill_loc.county      ,
  raa_bill_loc.state       ,
  raa_bill_loc.province    ,
  raa_bill_loc.postal_code ,
  rac_ship_party.party_name ,
  rac_ship.account_number ,
  su_ship.LOCATION ,
  raa_ship_loc.address1    ,
  raa_ship_loc.address2    ,
  raa_ship_loc.address3    ,
  raa_ship_loc.city        ,
  raa_ship_loc.county      ,
  raa_ship_loc.state       ,
  raa_ship_loc.province    ,
  raa_ship_loc.postal_code ,
  bs.NAME,
  rab.NAME,
  ctt.NAME,
  ctt.TYPE;

Query to check Standard Purchase Order linked with Blanket Agreement

 SELECT pha.segment1 po_number

, pha.type_lookup_code
, pha.enabled_flag
, fu.user_name standard_po_created_by
, pha.vendor_id
, pha.vendor_site_id
, pha.authorization_status
, pla.line_num
, pla.item_id
, pla.unit_price
, pla.quantity
, pla.from_header_id
, pla.from_line_id
, pha1.segment1 BPA_NUM
, pha1.global_agreement_flag
, pha1.type_lookup_code
, fu1.user_name bpa_created_by
, pha1.vendor_id
, pha1.vendor_site_id
, pha1.authorization_status
, pla1.item_id
, pla1.unit_price
, pla1.from_header_id
, pla1.from_line_id

FROM po_headers_all pha

, po_lines_all pla
, po_headers_all pha1
, po_lines_all pla1
, fnd_user fu
, fnd_user fu1

WHERE pha.po_header_id   = pla.po_header_id

  AND pla.from_header_id = pha1.po_header_id
  AND pla.from_line_id     = pla1.po_line_id
  AND pha.created_by       = fu.user_id
  AND pha1.created_by     = fu1.user_id
  --
  AND pha.segment1 IN ('5800999942', '5800999943')
  AND pla.line_num = 10;

---> Check at PO line level.. Columns - from header id and from line id, also the Global agreement flag should by Y for Blanket Agreement.

Query to check Sales Order HOLD reasons

 SELECT ooha.order_number

, ooha.ordered_date
, ooha.flow_status_code
, ooha.credit_card_approval_code
, ohd.name "Hold Name"
, ohs.released_flag
, ohr.release_reason_code
, ohr.creation_date "Hold Release Date"
, ooha.payment_type_code 

FROM apps.oe_order_headers_all ooha

, apps.oe_order_holds_all ohld
, apps.oe_hold_sources_all ohs
, apps.oe_hold_definitions ohd
, apps.oe_hold_releases ohr 

WHERE 1 = 1

AND ooha.order_category_code = 'ORDER' 
AND ohld.header_id(+)       = ooha.header_id 
AND ohs.hold_source_id(+)   = ohld.hold_source_id 
AND ohd.hold_id(+)          = ohs.hold_id 
AND ohr.hold_release_id(+)  = ohs.hold_release_id 
-- AND ooha.order_number = 'ORDERNUMBER'
ORDER BY ooha.order_number

Query to get Customer details of Sales Order

 

SELECT  ooha.order_number
     ,  ooha.ordered_date
     ,  ooha.flow_status_code
     ,  hp.party_name "Customer Name"
     ,  hca.account_name
     ,  hca.org_id
     ,  hpb.status bill_to_status
     ,     'Address1: '
        || bill_loc.address1
        || ','
        || CHR (10)
        || 'Address2: '
        || bill_loc.address2
        || ','
        || CHR (10)
        || 'Address3: '
        || bill_loc.address3
        || ','
        || CHR (10)
        || 'City     - '
        || bill_loc.city
        || ','
        || CHR (10)
        || 'Postal Code: '
        || bill_loc.postal_code
        || ','
        || CHR (10)
        || 'Country: '
        || bill_loc.country
           bill_to_address
     ,  hcasas.orig_system_reference ship_to_orig_ref
     ,  hps.status ship_to_status
     ,     'Address1: '
        || ship_loc.address1
        || ','
        || CHR (10)
        || 'Address1: '
        || ship_loc.address2
        || ','
        || CHR (10)
        || 'Address1: '
        || ship_loc.address3
        || ','
        || CHR (10)
        || 'City: '
        || ship_loc.city
        || ','
        || CHR (10)
        || 'Postal Code: '
        || ship_loc.postal_code
        || ','
        || CHR (10)
        || 'Country: '
        || ship_loc.country
           ship_to_address

  FROM  apps.oe_order_headers_all ooha

     ,  apps.hz_parties hp
     ,  apps.hz_cust_accounts hca
     ,  apps.hz_cust_acct_sites_all hcasab
     ,  apps.hz_cust_acct_sites_all hcasas
     ,  apps.hz_cust_site_uses_all hzsuab
     ,  apps.hz_cust_site_uses_all hzsuas
     ,  apps.hz_party_sites hps
     ,  apps.hz_party_sites hpb
     ,  apps.hz_locations bill_loc
     ,  apps.hz_locations ship_loc

 WHERE 

   AND hp.party_id                        = hca.party_id
   AND hca.cust_account_id          = ooha.sold_to_org_id
   AND hcasab.cust_account_id    = hca.cust_account_id
   AND hcasas.cust_account_id     = hca.cust_account_id
   AND hpb.location_id                 = bill_loc.location_id
   AND hps.location_id                 = ship_loc.location_id
   AND hcasab.party_site_id         = hpb.party_site_id
   AND hcasas.party_site_id         = hps.party_site_id
   AND hcasab.cust_acct_site_id  = hzsuab.cust_acct_site_id
   AND hcasas.cust_acct_site_id  = hzsuas.cust_acct_site_id
   AND ooha.ship_to_org_id        = hzsuas.site_use_id
   AND ooha.invoice_to_org_id   = hzsuab.site_use_id
   AND ooha.order_number          = '&Order_Number';

Add Concurrent Program to Request Group from backend


DECLARE

  lc_program_short_name  VARCHAR2 (200);
  lc_program_application VARCHAR2 (200);
  lc_request_group       VARCHAR2 (200);
  lc_group_application   VARCHAR2 (200);
  lc_check               VARCHAR2 (2);

BEGIN

  lc_program_short_name  := 'XXPO123REPORT';
  lc_program_application := 'XXPO Custom';
  lc_request_group       := 'Custom Purchasing';
  lc_group_application   := 'XXPO Custom';

  -- Calling API to assign concurrent program to a reqest group

   apps.fnd_program.add_to_group (program_short_name  => lc_program_short_name,
                                  program_application => lc_program_application,
                                  request_group       => lc_request_group,
                                  group_application   => lc_group_application                            
                                 );  

  COMMIT;

  BEGIN

    --To check whether a concurrent program has added to Request Group or not

     SELECT 'Y'
       INTO l_check
       FROM fnd_request_groups frg,
      fnd_request_group_units frgu,
      fnd_concurrent_programs fcp
      WHERE frg.request_group_id    = frgu.request_group_id
    AND frg.application_id          = frgu.application_id
    AND frgu.request_unit_id        = fcp.concurrent_program_id
    AND frgu.unit_application_id    = fcp.application_id
    AND fcp.concurrent_program_name = 'XXPO123REPORT';
    dbms_output.put_line ('Adding Concurrent Program to Request Group Succeeded');

  EXCEPTION

  WHEN no_data_found THEN

    dbms_output.put_line ('Adding Concurrent Program to Request Group Failed');

  END;

END;

/

Monday, November 4, 2024

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 like shapes, text, barcodes and images, combine these elements, and finally print them.

👉Create your report using ZPL language and print code in Output or Log file.

    Output or Log file text:

    

👉Copy that whole text/output and refer below steps to get Output in Zebra print format - 

    Step:01) Open Zebra Viewer in any browser

                   URL: https://labelary.com/viewer.html

Step: 2) Remove / Clear defaulted text and paste your output text in left column. 
Step: 3) Change label size as per your requirement diamension.
Step: 4) Click on Redraw button, you will see the output at Right side of screen.
Step: 5) To get/download output in PDF format, click on PDF option(below the label output screen). Output file will save in .pdf format.

👉You can download output file in image format to click on PNG optoin.

Monday, November 6, 2023

Release the Sales Order using API

Here we have used two APIs: The first API will create the delivery using the deliver detail ID and then the second API will release that delivery.

1) Create Delivery API ---  wsh_delivery_details_pub.autocreate_deliveries
2) Release that Delivery API ---  wsh_deliveries_pub.delivery_action

    DECLARE
        x_return_status                 VARCHAR2 (2);
        x_msg_count                    NUMBER;
        x_msg_data                      VARCHAR2 (2000);
        p_api_version_number     NUMBER := 1.0;
        init_msg_list                     VARCHAR2 (200);
        x_msg_details                   VARCHAR2 (3000);
        x_msg_summary              VARCHAR2 (3000);
        p_line_rows wsh_util_core.id_tab_type;
        x_del_rows wsh_util_core.id_tab_type;
        l_commit                          VARCHAR2 (30);
        p_delivery_id                   NUMBER;
        p_delivery_name             VARCHAR2 (30);
        x_trip_id                          VARCHAR2 (30);
        x_trip_name                    VARCHAR2 (30);
        api_exception                  EXCEPTION;
        lc_process_flag                VARCHAR2(5) := 'Y';
        lc_inv_period                   VARCHAR2(10);
        ln_hold_cnt                      NUMBER;
        ln_onhand_quantity         NUMBER := 0;
        lc_run_mode                    VARCHAR2(10);
        ln_request_id                   NUMBER := 0;
        lg_request_id                   NUMBER := 0;
        lc_export_phase_code     VARCHAR2(2);
        --
        ln_qoh                   NUMBER := 0;
        ln_rqoh                  NUMBER := 0;
        ln_atr                     NUMBER := 0;
        ln_att                     NUMBER := 0;
        ln_qr                      NUMBER := 0;
        ln_qs                      NUMBER := 0;
        lb_lot_control_code      BOOLEAN;
        lb_serial_control_code   BOOLEAN;
        --
        ln_delivery_detail_id    NUMBER := 0;
        ln_inv_item_id              NUMBER := 0;
        ln_organization_id        NUMBER := 0;
        ln_requested_qty           NUMBER := 0;
        ln_so_line_id                 NUMBER := 0;
        lc_subinventory             oe_order_lines_all.subinventory%TYPE;
    BEGIN
        --
        BEGIN
            SELECT wdd.delivery_detail_id, wdd.inventory_item_id, wdd.organization_id, wdd.requested_quantity,
              ola.line_id, ola.subinventory
              INTO ln_delivery_detail_id, ln_inv_item_id, ln_organization_id, ln_requested_qty, ln_so_line_id, lc_subinventory
              FROM apps.oe_order_headers_all oha,
                   apps.oe_order_lines_all ola,
                   apps.wsh_delivery_details wdd,
                   apps.mtl_system_items_b msib
              WHERE oha.header_id         = ola.header_id
                AND oha.org_id            = ola.org_id
                AND oha.header_id         = wdd.source_header_id
                AND ola.line_id           = wdd.source_line_id
                AND wdd.inventory_item_id = msib.inventory_item_id
                AND wdd.organization_id   = msib.organization_id
                AND oha.booked_flag       = 'Y'
                AND NVL (ola.cancelled_flag, 'N') <> 'Y'
                AND wdd.released_status IN ('R', 'B') -- Ready to Release, Backordered
                AND ola.flow_status_code  = 'AWAITING_SHIPPING'
                AND ola.line_number       = 1
                AND oha.order_number      = '3657782'
                AND oha.org_id            = 101;
        EXCEPTION
            WHEN no_data_found THEN
            dbms_output.put_line('  Order delivery details are not found.');
            WHEN others THEN
            dbms_output.put_line('  Error while getting order delivery details: '||SQLERRM);
        END;
        --
        x_return_status := wsh_util_core.g_ret_sts_success;
            --Check Hold applied or not on SO Line using SO_Line_ID
            BEGIN
              SELECT count(*) INTO ln_hold_cnt
              FROM oe_order_holds_all
              WHERE line_id     = ln_so_line_id
              AND released_flag = 'N'
              AND hold_release_id IS NULL;
            EXCEPTION
              WHEN no_data_found THEN
              lc_process_flag := 'Y';
              WHEN others THEN
              dbms_output.put_line( '  Error while checking on hand quantity: '||SQLERRM);
              lc_process_flag := 'N';
            END;
            --
            IF (ln_hold_cnt > 0) THEN
              dbms_output.put_line( '  Validation Error: Hold has applied on Selected SO Line');
              lc_process_flag := 'N';
            END IF;
            -- Check Inventory period is open or not
            BEGIN
              SELECT period_name INTO lc_inv_period
              FROM org_acct_periods_v 
              WHERE organization_id = ln_organization_id
              AND period_name = TO_CHAR(TRUNC(sysdate),'MON-RR')
              AND status = 'Open';
            EXCEPTION
              WHEN no_data_found THEN
              dbms_output.put_line( '  Validation Error: Current Date Inventory Period is not opened. Please alter.');
              lc_process_flag := 'N';
            END;
            -- Check On Hand quantity against SO Line item
            inv_quantity_tree_pub.query_quantities (
                        p_api_version_number    => 1.0,
                        p_init_msg_lst          => 'F',
                        x_return_status         => x_return_status,
                        x_msg_count             => x_msg_count,
                        x_msg_data              => x_msg_data,
                        p_organization_id       => ln_organization_id,
                        p_inventory_item_id     => ln_inv_item_id,
                        p_tree_mode             => apps.inv_quantity_tree_pub.g_transaction_mode,
                        p_is_revision_control   => FALSE,
                        p_is_lot_control        => lb_lot_control_code,
                        p_is_serial_control     => lb_serial_control_code,
                        p_revision              => NULL,
                        p_lot_number            => NULL,
                        p_lot_expiration_date   => SYSDATE,
                        p_subinventory_code     => lc_subinventory,
                        p_locator_id            => NULL,
                        p_onhand_source         => 3,      -- All subinventories
                        x_qoh                   => ln_qoh,
                        x_rqoh                  => ln_rqoh,
                        x_qr                    => ln_qr,
                        x_qs                    => ln_qs,
                        x_att                   => ln_att,  -- available to transact
                        x_atr                   => ln_atr   -- available to reserve
                     );
            --
            IF ( ln_att < ln_requested_quantity) OR ln_att IS NULL THEN
              dbms_output.put_line( '    Validation Error: Onhand quantity is not available.');
              dbms_output.put_line( '    -- Requested quantity : '||ln_requested_quantity);
              dbms_output.put_line( '    -- Available to transact quantity : '||ln_att);
              lc_process_flag := 'N';
            END IF;
            --
            IF (lc_process_flag = 'Y') THEN
                p_line_rows (1) := ln_delivery_detail_id;  -- we can create delivery using Delivery Detail ID
                --
                dbms_output.put_line( '  ');
                dbms_output.put_line( '  Call Auto Create Delivery API.. With Delivery Detail ID: '||ln_delivery_detail_id);
                    --1) API Call for Auto Create Deliveries
                    wsh_delivery_details_pub.autocreate_deliveries
                           (p_api_version_number => 1.0,
                            p_init_msg_list             => apps.fnd_api.g_true,
                            p_commit                      => l_commit,
                            x_return_status             => x_return_status,
                            x_msg_count                => x_msg_count,
                            x_msg_data                  => x_msg_data,
                            p_line_rows                 => p_line_rows,
                            x_del_rows                  => x_del_rows
                           );
                    IF (x_return_status <> wsh_util_core.g_ret_sts_success) THEN
                      dbms_output.put_line('  --> Failed to Auto create delivery for Sales Order');
                      dbms_output.put_line('  --> API Returned error message :'||x_msg_data);
                      RAISE api_exception;
                    ELSE
                        COMMIT;
                    END IF;
                    --
                    p_delivery_id := x_del_rows (1);
                    p_delivery_name := TO_CHAR (x_del_rows (1));
                    --
                    --2) Call API to create Pick Release.
                    dbms_output.put_line( '  API Call for Pick Release. ');
                    --
                    wsh_deliveries_pub.delivery_action
                     (p_api_version_number          => 1.0,
                            p_init_msg_list                => NULL,
                            x_return_status                => x_return_status,
                            x_msg_count                   => x_msg_count,
                            x_msg_data                     => x_msg_data,
                            p_action_code                 => 'PICK-RELEASE',
                            p_delivery_id                  => p_delivery_id,
                            p_delivery_name            => p_delivery_name,
                            p_asg_trip_id                  => NULL,
                            p_asg_trip_name            => NULL,
                            p_asg_pickup_stop_id    => NULL,
                            p_asg_pickup_loc_id      => NULL,
                            p_asg_pickup_stop_seq     => NULL,
                            p_asg_pickup_loc_code     => NULL,
                            p_asg_pickup_arr_date     => NULL,
                            p_asg_pickup_dep_date     => NULL,
                            p_asg_dropoff_stop_id     => NULL,
                            p_asg_dropoff_loc_id      => NULL,
                            p_asg_dropoff_stop_seq    => NULL,
                            p_asg_dropoff_loc_code    => NULL,
                            p_asg_dropoff_arr_date    => NULL,
                            p_asg_dropoff_dep_date    => NULL,
                            p_sc_action_flag          => 'S',
                            p_sc_intransit_flag       => 'N',
                            p_sc_close_trip_flag      => 'N',
                            p_sc_create_bol_flag      => 'N',
                            p_sc_stage_del_flag       => 'Y',
                            p_sc_trip_ship_method     => NULL,
                            p_sc_actual_dep_date      => NULL,
                            p_sc_report_set_id        => NULL,
                            p_sc_report_set_name      => NULL,
                            p_sc_defer_interface_flag => 'Y',
                            p_sc_send_945_flag        => NULL,
                            p_sc_rule_id              => NULL,
                            p_sc_rule_name            => NULL,
                            p_wv_override_flag        => 'N',
                            x_trip_id                 => x_trip_id,
                            x_trip_name               => x_trip_name
                           );
                    IF (x_return_status <> wsh_util_core.g_ret_sts_success) THEN
                      dbms_output.put_line('    Failed to Pick Release the sales order');
                      RAISE api_exception;
                    ELSE
                      COMMIT;
                      dbms_output.put_line('  ');
                      lc_api_flag := 'Y';
                    END IF;
            END IF; -- lc_process_flag
        --
    EXCEPTION
        WHEN api_exception THEN
          dbms_output.put_line( '  ');
          wsh_util_core.get_messages ('Y', x_msg_summary, x_msg_details, x_msg_count);
          IF x_msg_count > 1 THEN
            x_msg_data := x_msg_summary || x_msg_details;
            dbms_output.put_line( '  Msg Data1: '||x_msg_data);
          ELSE
            x_msg_data := x_msg_summary || x_msg_details;
            dbms_output.put_line( '  Msg Data2: '||x_msg_data);
          END IF;
    END;
    /

Friday, August 11, 2023

How to handle Log messages in stored objects (Functions, Procedure, Package Body)


Normally we handle log messages using FND_FILE.PUT_LINE(fnd_file.LOG,'Msg');

But in some cases we need to handle Log messages based on the Parameter value.

If we give the parameter value for DEBUG as Y (Yes), then the program must print a message in the log file. And if the N (No) value is entered, the program cannot print the message.

We can do it using following code logic.. (You can modify it according to your requirement and logic)

For Example -

     -- Package Specification

     CREATE OR REPLACE Package XXC_GET_DATA
     IS
         Procedure write_log(p_message IN VARCHAR2
                                        ,  p_debug_flag IN VARCHAR2 Default 'N');
         --
         Procedure employee_details(errbuf OUT VARCHAR2
                                                  , retcode OUT VARCHAR2
                                                  , p_debug_flag IN VARCHAR2
                                                  , p_emp_id IN NUMBER);
          --
    END XXC_GET_DATA;
   /

     -- Package Body

     CREATE OR REPLACE Package Body XXC_GET_DATA
     IS
         PROCEDURE write_log(p_message IN VARCHAR2
                                        ,  p_debug_flag IN VARCHAR2 Default 'N')
          IS
               lc_time VARCHAR2(20);  -- It will store log print Date with time.
          BEGIN
               SELECT to_char(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') INTO lc_time
               FROM dual;
               --
               IF (p_debug_flag = 'Y') THEN
                    fnd_file.put_line(fnd_file.LOG,lc_time||'-'||p_message);
               END IF;
          EXCEPTION
               WHEN others THEN
                    fnd_file.put_line(fnd_file.LOG,'Error in Write_Log procedure: '||SQLERRM);
          END write_log;
          --
          PROCEDURE employee_details(errbuf OUT VARCHAR2
                                                  , retcode OUT VARCHAR2
                                                  , p_debug_flag IN VARCHAR2
                                                  , p_emp_id IN NUMBER)
          IS
               lc_emp_name emp.emp_name%TYPE;
               lc_address  emp.address%TYPE;
               ln_emp_num  emp.emp_number%TYPE;
          BEGIN
               BEGIN
                    SELECT emp_name, address, emp_number
                    INTO lc_emp_name, lc_address, ln_emp_num
                    FROM emp
                    WHERE emp_id = p_emp_id;
               EXCEPTION
                    WHEN no_data_found THEN
                         write_log('Employee record not found.', p_debug_flag);
                    WHEN others THEN
                         write_log('Error while getting emp details: '||SQLERRM, p_debug_flag);
               END;
               --
          EXCEPTION
               WHEN others THEN
               write_log('Error in employee_details procedure: '||SQLERRM, p_debug_flag);                   
          END employee_details;
          --
    END XXC_GET_DATA;
   /

Monday, June 5, 2023

Delete AR(Account Receivable) Transaction Using API in Oracle Apps

Delete AR Transaction Using API:

Before delete AR transaction "Allow Transaction Deletion" flag should be Y.

Allow Transaction Deletion:
           Enable the Allow transaction deletion option if you want to let users delete transactions from Oracle Receivables after the transactions have been saved.
           You will update this option at Operating Unit level.
 
   Check in database table:
 
           SELECT invoice_deletion_flag
           FROM ar_system_parameters_all ab
           WHERE org_id = 201;   -- Operating Unit org_id
 
           If value of 'invoice_deletion_flag' is Y, its mean you are enable to delete AR Transaction, otherwise you need to do setup for this.
 
   Setup:

      Navigation:  Receivable Responsibility --> Setup --> System --> System Options

  Select 'Trans and Customers' Tab:


  Click on "Allow Transaction Deletion" button and Save it.
  Check in database table.
 
   To delete AR Transaction, follow below steps:
 
   Step 1) Create a staging table to stored data related to AR transaction.

           CREATE TABLE xx_delete_ar_transaction
           AS
             SELECT customer_trx_id,
                             trx_date,
                             trx_number,
                             org_id,
                             creation_date,
                             created_by,
                             'N' record_status
                 FROM ra_customer_trx_all
              WHERE org_id = 201
                    AND trx_number IN ('123000', '124000');

   Step 2) Call API in PLSQL block to Delete AR Transactions:

           DECLARE
              CURSOR lcur_ar_trans
              IS
                 SELECT ROWID,
                                 customer_trx_id,
                                 trx_date,
                                 trx_number,
                                 org_id,
                                 creation_date,
                                 created_by
                 FROM xx_delete_ar_transaction
                 WHERE record_status = 'N';

                          lc_msg_data                VARCHAR2(4000);
                          ln_msg_count              NUMBER;
                          lc_ret_status                VARCHAR2(1) := 'S';
                          v_message_tbl             arp_trx_validate.message_tbl_type;
                          ln_user_id                    NUMBER;
                          ln_responsibility_id     NUMBER;
                          ln_application_id         NUMBER;
                          ln_msg_index              NUMBER;

           BEGIN
              --
              ln_user_id                 := 0;
              ln_application_id      := 0;
              ln_responsibility_id  := 0;

              -- Get application and responsibility id's
              BEGIN
                       SELECT application_id, responsibility_id
                       INTO ln_application_id, ln_responsibility_id
                       FROM fnd_responsibility_tl
                       WHERE responsibility_name = 'Responsibility Name';  -- Enter valid Responsibility Name
              EXCEPTION
                       WHEN others THEN
                        lc_ret_status := 'E';
                        dbms_output.put_line('Error at getting Responsibility id: '||SQLERRM);
              END;
              -- Get User ID
              BEGIN
                       SELECT user_id
                       INTO ln_user_id
                       FROM fnd_user
                       WHERE user_name = 'ABC007';   -- Enter valid User Name
              EXCEPTION
                       WHEN others THEN
                        lc_ret_status := 'E';
                        dbms_output.put_line('Error at getting User id: '||SQLERRM);
              END;
              --
              FOR lreq_ar IN lcur_ar_trans
              LOOP
              -- Variable initialization:
                  ln_msg_count := NULL;
                  lc_msg_data := NULL;
                  --
                  dbms_output.put_line ('--> TRX Number: '|| lreq_ar.trx_number);
                  -- Set Org Context for the session
                  apps.mo_global.set_policy_context ('S', lreq_ar.org_id);
                  -- Set Oracle applications context
                  apps.fnd_global.apps_initialize (ln_user_id, ln_responsibility_id, ln_application_id);

                 -- Call API
                 ar_invoice_api_pub.delete_transaction (
                            p_api_name               => 'Delete_Transaction',
                            p_api_version            => 1.0,
                            p_init_msg_list          => fnd_api.g_true,
                            p_commit                   => fnd_api.g_true,
                            p_validation_level     => fnd_api.g_valid_level_full,
                            p_customer_trx_id     => lreq_ar.customer_trx_id,
                            p_return_status          => lc_ret_status,
                            p_msg_count             => ln_msg_count,
                            p_msg_data               => lc_msg_data,
                            p_errors                     => v_message_tbl);

                IF lc_ret_status <> 'S' THEN
                    dbms_output.put_line ('--> Status: '||lc_ret_status);
             
                    BEGIN
                         UPDATE xx_delete_ar_transaction
                         SET record_status = lc_ret_status
                         WHERE ROWID = lreq_ar.ROWID;
                    EXCEPTION
                         WHEN others THEN
                         dbms_output.put_line('Error at update staging table: '||SQLERRM);
                    END;
             
                    FOR i IN 1 .. ln_msg_count
                    LOOP
                            apps.fnd_msg_pub.get (i,
                                            apps.fnd_api.g_false,
                                            lc_msg_data,
                                            ln_msg_index
                                          );
                            dbms_output.put_line ('Error: '||lc_msg_data);
                     END LOOP;
                ELSE
                     dbms_output.put_line ('AR Transaction Successfully Deleted.');
                END IF;
                dbms_output.put_line ('--------------------');
                COMMIT;
              END LOOP;
           EXCEPTION
                 WHEN OTHERS THEN
                 dbms_output.put_line ('Error in main block: ' || SQLERRM);
           END;
           / 

Query to get Sales Order Customer details

  SELECT  ooha.order_number      ,  ooha.org_id      ,  ooha.sold_to_org_id bill_cust_account_id      ,  ooha.ship_to_org_id ship_to_site_us...