Tuesday 12 February 2019

Query to get India timezone Date & Time.

--Query to get India timezone Date & Time
SELECT TO_CHAR(SYS_EXTRACT_UTC(SYSTIMESTAMP) +
       (5.5/24), 'DD/Mon/RRRR HH24:MI:SS') IST_DATE_TIME
  FROM dual;

Script to Enable & Disable ERP Users through API.

--Script to Disable ERP User
BEGIN
FND_USER_PKG.DisableUser(username => 'XYZ_USER');
commit;
END;


----Script to Enable ERP User
BEGIN
FND_USER_PKG.EnableUser(username => 'XYZ_USER');
commit;
END;

Query to Get VENDOR, PO, INVOICE AND PAYMENT DETAILS

--Query to Get VENDOR, PO, INVOICE AND PAYMENT DETAILS
SELECT DISTINCT a.org_id
      ,e.segment1 VENDOR_NUMBER
      ,e.vendor_name
      ,UPPER (e.vendor_type_lookup_code) VENDOR_TYPE
     ,f.vendor_site_code
     ,TO_CHAR (TRUNC(d.creation_date)) PO_DATE
     ,d.segment1 PO_NUM
     ,d.type_lookup_code PO_TYPE
     ,c.quantity_ordered QTY_ORDERED
     ,c.quantity_cancelled QTY_CANCELLED
     ,g.item_description ITEM_DESCRIPTION
     ,g.unit_price UNIT_PRICE
     ,((NVL (c.quantity_ordered, 0) - NVL (c.quantity_cancelled, 0))
      * NVL (g.unit_price, 0)) PO_LINE_AMOUNT
     ,(SELECT DECODE (ph.approved_flag,'Y', 'Approved')
         FROM po.po_headers_all ph
        WHERE ph.po_header_id = d.po_header_id) PO_APPROVED
     ,a.invoice_type_lookup_code INVOICE_TYPE
     ,a.invoice_amount INVOICE_AMOUNT
     ,TO_CHAR (TRUNC (a.invoice_date)) INVOICE_DATE
     ,a.invoice_num INVOICE_NUMBER
     ,(SELECT DECODE (x.match_status_flag,'A', 'Approved')
         FROM ap.ap_invoice_distributions_all x
        WHERE x.invoice_distribution_id = b.invoice_distribution_id) INVOICE_APPROVED
     ,a.amount_paid
     ,h.check_id
     ,i.check_number
     ,h.invoice_payment_id
     ,TO_CHAR (TRUNC(i.check_date)) PAYMENT_DATE
FROM ap_invoices_all a
    ,ap_invoice_distributions_all b
    ,po_distributions_all c
    ,po_headers_all d
    ,ap_suppliers e
    ,ap_supplier_sites_all f
    ,po_lines_all g
    ,ap_invoice_payments_all h
    ,ap_checks_all i
WHERE a.invoice_id = b.invoice_id
  AND b.po_distribution_id = c.po_distribution_id(+)
  AND c.po_header_id = d.po_header_id(+)
  AND e.vendor_id(+) = d.vendor_id
  AND f.vendor_site_id(+) = d.vendor_site_id
  AND d.po_header_id = g.po_header_id
  AND c.po_line_id = g.po_line_id
  AND a.invoice_id = h.invoice_id
  AND h.check_id = i.check_id
  AND c.po_header_id IS NOT NULL
  AND a.payment_status_flag = 'Y'
  AND d.type_lookup_code != 'BLANKET'
  AND EXISTS (SELECT 1
      FROM hr_operating_units
     WHERE 1=1
       AND organization_id = d.org_id
       AND business_group_id = 81)
ORDER BY E.VENDOR_NAME

Query to Check Period Status for GL/PO/AP/AR/FA Applications

--Query to Check Period Status for GL/PO/AP/AR/FA Applications
SELECT (SELECT sob.NAME
          FROM gl_sets_of_books sob
         WHERE sob.set_of_books_id = a.set_of_books_id) ledger_Name
      ,a.period_name Period_Name
      ,a.period_num Period_Num
      ,a.gl_status GL_Period_Status
      ,b.po_status PO_period_Status
      ,c.ap_status AP_period_Status
      ,d.ar_status AR_period_Status
      ,e.fa_status FA_period_Status
 FROM (SELECT period_name
             ,period_num
             ,DECODE (closing_status,
            'O', 'Open',
            'C', 'Closed',
            'F', 'Future',
            'N', 'Never', closing_status) gl_status
     ,set_of_books_id
 FROM gl_period_statuses
WHERE application_id = 101
  AND UPPER (period_name) = UPPER (:PERIOD_NAME)
  AND set_of_books_id =  :P_SOB_ID) a,
    (SELECT period_name,
            DECODE (closing_status,
            'O', 'Open',
            'C', 'Closed',
            'F', 'Future',
            'N', 'Never',closing_status) po_status
           ,set_of_books_id
    FROM gl_period_statuses
    WHERE application_id = 201
    AND UPPER (period_name) = UPPER (:PERIOD_NAME)
    AND set_of_books_id = :P_SOB_ID ) b,
        (SELECT period_name,
                DECODE (closing_status,
            'O', 'Open',
            'C', 'Closed',
            'F', 'Future',
            'N', 'Never',closing_status) ap_status
           ,set_of_books_id
      FROM gl_period_statuses
     WHERE application_id = 200
       AND UPPER (period_name) = UPPER (:PERIOD_NAME)
       AND set_of_books_id = :P_SOB_ID ) c,
        (SELECT period_name,
         DECODE (closing_status,
            'O', 'Open',
            'C', 'Closed',
            'F', 'Future',
            'N', 'Never',
            closing_status) ar_status
           ,set_of_books_id
      FROM gl_period_statuses
     WHERE application_id = 222
       AND UPPER (period_name) = UPPER (:PERIOD_NAME)
       AND set_of_books_id = :P_SOB_ID) d,
    (SELECT fdp.period_name,
            DECODE (fdp.period_close_date,
            NULL,'Open','Closed') fa_status
          ,fbc.set_of_books_id
    FROM fa_book_controls fbc
        ,fa_deprn_periods fdp
    WHERE fbc.set_of_books_id = :P_SOB_ID
    AND fbc.book_type_code = fdp.book_type_code
    AND UPPER (fdp.period_name) = UPPER (:PERIOD_NAME)) e
WHERE a.period_name = b.period_name(+)
  AND a.period_name = c.period_name(+)
  AND a.period_name = d.period_name(+)
  AND a.period_name = e.period_name(+)
  AND a.set_of_books_id=b.set_of_books_id(+)
  AND a.set_of_books_id=c.set_of_books_id(+)
  AND a.set_of_books_id=d.set_of_books_id(+)
  AND a.set_of_books_id=e.set_of_books_id(+)
ORDER BY 1

Query to get PO created but RECEIPT/GRN not done.

SELECT pha.po_Header_id
      ,pha.segment1 PO_NUMBER
      ,pha.CLOSED_CODE
      ,to_char(pha.CREATION_DATE,'DD-MON-YYYY') CREATION_DATE
      --,To_char(pha.CREATION_DATE,'DD-MON-YYYY HH24:MI:SS') Creation_Date_Time
      ,hou.name OPERATING_UNIT
      ,aps.vendor_id
      ,aps.segment1 vendor_number
      ,aps.vendor_name
  FROM po_Headers_all pha
      ,ap_suppliers aps
      ,hr_operating_units hou
 WHERE 1=1
   --AND pha.vendor_order_num LIKE '%SA%'
   AND pha.vendor_id = aps.vendor_id
   AND hou.business_group_id = 81
   AND pha.AUTHORIZATION_STATUS = 'APPROVED'
   AND pha.org_id = hou.organization_id
   AND cancel_flag <> 'Y'
   AND pha.APPROVED_DATE BETWEEN fnd_date.canonical_to_date (:P_DT_FRM) AND fnd_date.canonical_to_date (:P_DT_TO)
  AND NOT EXISTS
  (SELECT 1
     FROM rcv_shipment_lines rsl
    WHERE PHA.PO_HEADER_ID = RSL.PO_HEADER_ID)
ORDER BY pha.CREATION_DATE DESC;

Query to find request group and application information for a concurrent program

SELECT cpt.user_concurrent_program_name
      ,DECODE(rgu.request_unit_type,
              'P', 'Program',
              'S', 'Set',
              rgu.request_unit_type) request_unit_type
      ,cp.concurrent_program_name Concurrent_Program_Short_Name
      ,rg.application_id
      ,rg.request_group_name
      ,fat.application_name
      ,fa.application_short_name
      ,fa.basepath application_basepath
  FROM fnd_request_groups          rg,
       fnd_request_group_units     rgu,
       fnd_concurrent_programs     cp,
       fnd_concurrent_programs_tl  cpt,
       fnd_application             fa,
       fnd_application_tl          fat
 WHERE rg.request_group_id       =  rgu.request_group_id
   AND rgu.request_unit_id       =  cp.concurrent_program_id
   AND cp.concurrent_program_id  =  cpt.concurrent_program_id
   AND rg.application_id         =  fat.application_id
   AND fa.application_id         =  fat.application_id
   AND cpt.language              =  USERENV('LANG')
   AND fat.language              =  USERENV('LANG')
   AND (cpt.user_concurrent_program_name = :p_user_program_name OR :p_user_program_name IS NULL)

Query to get BI/XML Publisher Data Definition and Template details

--Query to get XML Publisher Data Definition and Template details
SELECT fcp.user_concurrent_program_name "Program Name",
         fcp1.concurrent_program_name "Program Short Name",
         fat.application_name program_application_name,
         fet.executable_name "Executable Name",
         fat1.application_name executable_application_name,
         fet.execution_file_name,
         flv.meaning execution_method,
         xlo.lob_type,
         xlo.file_name "Data/Brusting File",
         xds.data_source_code,
         xds.data_source_name,
         xdt.template_code,
         xlt.language,
         xlt.file_name
    FROM fnd_concurrent_programs_tl fcp,
         fnd_concurrent_programs fcp1,
         fnd_executables fet,
         fnd_lookup_values flv,
         fnd_application_tl fat,
         fnd_application_tl fat1,
         xdo_lobs xlo,
         xdo_ds_definitions_vl xds,
         xdo_templates_b xdt,
         xdo_templates_tl xdtl,
         xdo_lobs xlt
   WHERE 1=1   
     AND (fcp.application_id = :p_app_id OR :p_app_id IS NULL)
     AND fcp.language = 'US'
     AND fcp.concurrent_program_id = fcp1.concurrent_program_id
     AND fcp.application_id = fcp1.application_id
     AND fcp1.executable_id = fet.executable_id
     AND fcp1.executable_application_id = fet.application_id
     AND flv.lookup_code = fet.execution_method_code
     AND flv.language = 'US'
     AND FLV.LOOKUP_TYPE = 'CP_EXECUTION_METHOD_CODE'
     AND fcp1.application_id = fat.application_id
     AND fet.application_id = fat1.application_id
     AND fat.language = 'US'
     AND fat1.language = 'US'
     AND fet.executable_name = 'XDODTEXE'
     AND fcp1.concurrent_program_name = xlo.lob_code(+)
     AND xlo.lob_type IN ('DATA_TEMPLATE', 'BURSTING_FILE')
     AND (fcp1.concurrent_program_name = :p_program_code OR :p_program_code IS NULL)
     AND fcp1.concurrent_program_name = xds.data_source_code
     AND xds.data_source_code = xdt.data_source_code(+)
     AND xdt.template_code = xdtl.template_code(+)
     AND xdtl.language = 'US'
     AND xds.data_source_name = xdtl.template_name
     AND xlt.lob_type = 'TEMPLATE_SOURCE'
     AND xdt.template_code = xlt.lob_code
ORDER BY 1;