Monday, 13 May 2013

Query to find rcv shipment lines not yet deliver ( Pending For Binning)

 SELECT   msi.segment1 part_num,
           poh.segment1 po_num,
           pra.release_num,
           TRUNC (poh.creation_date) po_date,
           TRUNC (PRA.APPROVED_DATE) Release_Approved_Date,
           SUM (quantity) Quantity,
           (SELECT   shipment_num
              FROM   rcv_shipment_headers
             WHERE   shipment_header_id = rs.shipment_header_id)
              shipment_num
    FROM   rcv_supply rs,
           mtl_system_items_b msi,
           po_headers_all poh,
           po_releases_all pra
   WHERE       to_organization_id = :p_org_id --171
           AND rs.item_id = msi.inventory_item_id
           AND rs.to_organization_id = msi.organization_id
           AND rs.PO_HEADER_ID = poh.PO_HEADER_ID
           AND rs.po_release_id = pra.po_release_id
           AND poh.po_header_id = pra.po_header_id
--and             substr(quantity,1,1) = '-' 
GROUP BY   msi.segment1,
           poh.segment1,
           pra.release_num,
           rs.shipment_header_id,
           PRA.APPROVED_DATE,
           poh.creation_date
          

Query to find pending for Receiving quantity against the PO and Release NO

/* Pending for Receiving Details */

SELECT   HOU.NAME ORG_NAME,
         pra.AUTHORIZATION_STATUS,
         PHA.SEGMENT1 PO_NUMBER,
         PRA.RELEASE_NUM,
         PLA.LINE_NUM,
         MSIB.SEGMENT1 PARTNO,
         MSIB.DESCRIPTION PARTDESC,
         PV.SEGMENT1 VENDOR_NUMBER,
         PV.VENDOR_NAME,
         PLLA.QUANTITY ORDer_QTY,
         PRA.APPROVED_DATE,
         TRUNC (pra.creation_date) APPROVED_DATE,
         ( (PLLA.QUANTITY - PLLA.QUANTITY_RECEIVED) - PLLA.QUANTITY_CANCELLED)
            PENDINGORDQTY,
         (SELECT   SUM (NVL (rsl.quantity_shipped, 0))
            FROM   RCV_SHIPMENT_LINES RSL, PO_LINE_LOCATIONS_ALL PLSA      --,
           WHERE       RSL.po_line_location_id = PLSA.line_location_id
                   AND PLSA.SHIPMENT_NUM = PLLA.SHIPMENT_NUM
                   AND rsl.PO_RELEASE_ID = plla.PO_RELEASE_ID)
            SHIPPED_QUANTITY,
         PLLA.QUANTITY_RECEIVED,
         PLLA.NEED_BY_DATE                                                 --,
  FROM   PO_HEADERS_ALL PHA,
         PO_LINES_ALL PLA,
         HR_OPERATING_UNITS HOU,
         PO_LINE_LOCATIONS_ALL PLLA,
         PO_RELEASES_ALL PRA,
         PO_VENDORS PV,
         MTL_SYSTEM_ITEMS_B MSIB
 WHERE                                           ------PHA.SEGMENT1 = '101358'
             ------AND PRA.RELEASE_NUM = 5
             PHA.PO_HEADER_ID = PLA.PO_HEADER_ID
         AND PLLA.PO_HEADER_ID = PHA.PO_HEADER_ID
         AND PLLA.PO_LINE_ID = PLA.PO_LINE_ID
         AND PLA.ORG_ID = HOU.ORGANIZATION_ID
         AND PRA.PO_RELEASE_ID = PLLA.PO_RELEASE_ID
         AND PHA.VENDOR_ID = PV.VENDOR_ID
         AND MSIB.INVENTORY_ITEM_ID = PLA.ITEM_ID
         AND MSIB.ORGANIZATION_ID = PLLA.SHIP_TO_ORGANIZATION_ID
         AND PLA.ORG_ID = NVL (:P_ORG_ID, PLA.ORG_ID)
         AND PV.VENDOR_ID = NVL (:P_VENDOR, PV.VENDOR_ID)
         AND MSIB.INVENTORY_ITEM_ID = NVL (:P_ITEM, MSIB.INVENTORY_ITEM_ID)
         AND ( (PLLA.QUANTITY - PLLA.QUANTITY_RECEIVED)
              - PLLA.QUANTITY_CANCELLED) > 0

Procedure to Cancel the PO Release Lines


/*   Procedure to Cancel the PO LINES */
CREATE OR REPLACE PROCEDURE APPS.XX_PO_CANCEL_PRG (
   ERRBUF                 OUT VARCHAR2,
   RETCODE                OUT NUMBER,
   P_ORG               IN     NUMBER,
   P_P0_HEADER_ID      IN     NUMBER,
   P_VENDER_ID         IN     NUMBER,
   P_RELEASE_NUMBER    IN     NUMBER,
   P_ITEM_ID           IN     NUMBER,
   P_SHIPMENT_NUMBER   IN     NUMBER
)
IS
   CURSOR C_PO_CANCEL
   IS
      SELECT   PHA.TYPE_LOOKUP_CODE,
               PHA.PO_HEADER_ID,
               PLA.PO_LINE_ID,
               PLA.LINE_NUM,
               PRA.RELEASE_NUM,
               PRA.PO_RELEASE_ID,
               PLLA.LINE_LOCATION_ID,
               PLLA.SHIPMENT_NUM,
               PLA.ITEM_ID,
               PLA.ITEM_DESCRIPTION,
               PHA.SEGMENT1 PO_NUMBER,
               PHA.ORG_ID,
               PRA.AUTHORIZATION_STATUS,
               NVL (PLLA.QUANTITY, 0) ORDER_QTY,
               NVL (PLLA.QUANTITY_RECEIVED, 0) QTY_REC,
               PHA.VENDOR_ID,
               VENDOR_TYPE_LOOKUP_CODE
        FROM   PO_HEADERS_ALL PHA,
               PO_LINES_ALL PLA,
               PO_LINE_LOCATIONS_ALL PLLA,
               PO_RELEASES_ALL PRA,
               AP_SUPPLIERS AP
       WHERE       1 = 1
               AND PHA.PO_HEADER_ID = PLA.PO_HEADER_ID
               AND PHA.ORG_ID = PRA.ORG_ID
               AND PHA.PO_HEADER_ID = NVL (P_P0_HEADER_ID, PHA.PO_HEADER_ID)
               AND PHA.VENDOR_ID = NVL (P_VENDER_ID, PHA.VENDOR_ID)
               AND PHA.VENDOR_ID = AP.VENDOR_ID
               AND PRA.RELEASE_NUM = NVL (P_RELEASE_NUMBER, PRA.RELEASE_NUM)
               AND PHA.TYPE_LOOKUP_CODE = 'BLANKET'
               AND PRA.PO_RELEASE_ID = PLLA.PO_RELEASE_ID
               AND PLLA.PO_LINE_ID = PLA.PO_LINE_ID
               AND PLA.ITEM_ID = NVL (P_ITEM_ID, PLA.ITEM_ID)
               AND PLLA.SHIPMENT_NUM =
                     NVL (P_SHIPMENT_NUMBER, PLLA.SHIPMENT_NUM)
               AND PHA.ORG_ID = NVL (P_ORG, PHA.ORG_ID)
               AND PLLA.CANCEL_FLAG = 'N'
               AND PRA.AUTHORIZATION_STATUS IN
                        ('INCOMPLETE', 'APPROVED', 'IN PROCESS')
               AND NVL (PLLA.QUANTITY, 0) - NVL (PLLA.QUANTITY_RECEIVED, 0) >
                     0;                                    --AND ROWNUM > 500;

   P_API_VERSION        NUMBER;
   P_INIT_MSG_LIST      VARCHAR2 (32767);
   P_COMMIT             VARCHAR2 (32767);
   X_RETURN_STATUS      VARCHAR2 (32767);
   P_DOC_TYPE           VARCHAR2 (25);
   P_DOC_SUBTYPE        VARCHAR2 (25);
   P_DOC_ID             NUMBER;
   P_DOC_NUM            VARCHAR2 (20);
   P_RELEASE_ID         NUMBER;
   P_RELEASE_NUM        NUMBER;
   P_DOC_LINE_ID        NUMBER;
   P_DOC_LINE_NUM       NUMBER;
   P_DOC_LINE_LOC_ID    NUMBER;
   P_DOC_SHIPMENT_NUM   NUMBER;
   P_ACTION             VARCHAR2 (32767);
   P_ACTION_DATE        DATE;
   P_CANCEL_REASON      VARCHAR2 (240);
   P_CANCEL_REQS_FLAG   VARCHAR2 (32767);
   P_PRINT_FLAG         VARCHAR2 (32767);
   P_NOTE_TO_VENDOR     VARCHAR2 (480);
   P_USE_GLDATE         VARCHAR2 (32767);
   P_ORG_ID             NUMBER;
BEGIN
   INSERT INTO  po_rel_performance_chk (start_date)
     VALUES   (SYSDATE);
   COMMIT;
   MO_GLOBAL.INIT ('PO');
   FND_GLOBAL.APPS_INITIALIZE (FND_PROFILE.VALUE ('USER_ID'), 50372, 7000);
   FOR I IN C_PO_CANCEL
   LOOP
      FND_MSG_PUB.INITIALIZE;
      FND_FILE.PUT_LINE (
         FND_FILE.LOG,
            'PO NUMBER TO CANCEL IS :'
         || '-'
         || I.PO_NUMBER
         || '-'
         || I.RELEASE_NUM
         || '-'
         || I.ITEM_DESCRIPTION
         || I.QTY_REC
      );
      IF I.QTY_REC = 0 AND I.AUTHORIZATION_STATUS = 'APPROVED'
      THEN
         P_API_VERSION := 1.0;
         P_INIT_MSG_LIST := FND_API.G_TRUE;
         P_COMMIT := FND_API.G_TRUE;
         X_RETURN_STATUS := X_RETURN_STATUS;
         P_DOC_TYPE := 'RELEASE';
         P_DOC_SUBTYPE := 'BLANKET';
         P_DOC_ID := I.PO_HEADER_ID;
         P_DOC_NUM := NULL;
         P_RELEASE_ID := NULL;
         P_RELEASE_NUM := I.RELEASE_NUM;
         P_DOC_LINE_ID := NULL;
         P_DOC_LINE_NUM := NULL;
         P_DOC_LINE_LOC_ID := I.LINE_LOCATION_ID;
         P_DOC_SHIPMENT_NUM := I.SHIPMENT_NUM;
         P_ACTION := 'CANCEL';
         P_ACTION_DATE := NULL;
         P_CANCEL_REASON := 'API';
         P_CANCEL_REQS_FLAG := 'N';
         P_PRINT_FLAG := NULL;
         P_NOTE_TO_VENDOR := NULL;
         P_USE_GLDATE := NULL;
         P_ORG_ID := I.ORG_ID;

         APPS.PO_DOCUMENT_CONTROL_PUB.CONTROL_DOCUMENT (P_API_VERSION,
                                                        P_INIT_MSG_LIST,
                                                        P_COMMIT,
                                                        X_RETURN_STATUS,
                                                        P_DOC_TYPE,
                                                        P_DOC_SUBTYPE,
                                                        P_DOC_ID,
                                                        P_DOC_NUM,
                                                        P_RELEASE_ID,
                                                        P_RELEASE_NUM,
                                                        P_DOC_LINE_ID,
                                                        P_DOC_LINE_NUM,
                                                        P_DOC_LINE_LOC_ID,
                                                        P_DOC_SHIPMENT_NUM,
                                                        P_ACTION,
                                                        P_ACTION_DATE,
                                                        P_CANCEL_REASON,
                                                        P_CANCEL_REQS_FLAG,
                                                        P_PRINT_FLAG,
                                                        P_NOTE_TO_VENDOR,
                                                        P_USE_GLDATE,
                                                        P_ORG_ID);
         DBMS_OUTPUT.PUT_LINE ('X_RETURN_STATUS = ' || X_RETURN_STATUS);
         IF X_RETURN_STATUS = 'S'
         THEN
            FND_FILE.PUT_LINE (
               FND_FILE.LOG,
               'The Purchase Order Which is Cancelled Now => ' || I.PO_NUMBER
            );
            BEGIN
               COMMIT;
            END;
         ELSE
            FND_FILE.PUT_LINE (
               FND_FILE.LOG,
                  'The Purchase Order'
               || I.PO_NUMBER
               || 'Failed to cancel Due To Following Reason'
            );
            FOR J IN 1 .. FND_MSG_PUB.COUNT_MSG
            LOOP
               DBMS_OUTPUT.PUT_LINE (
                  FND_MSG_PUB.GET (P_MSG_INDEX => J, P_ENCODED => 'F')
               );
            END LOOP;
         END IF;
      ELSIF I.QTY_REC = 0 AND I.AUTHORIZATION_STATUS = 'INCOMPLETE'
      THEN
         DELETE FROM   PO_RELEASES_ALL PRA
               WHERE   PRA.PO_RELEASE_ID = I.PO_RELEASE_ID
                       AND PRA.ORG_ID = I.ORG_ID;
         DELETE FROM   PO_DISTRIBUTIONS_ALL POD
               WHERE   POD.PO_RELEASE_ID = I.PO_RELEASE_ID
                       AND POD.ORG_ID = I.ORG_ID;
      ELSE
         UPDATE   PO_LINE_LOCATIONS_ALL A
            SET   A.QUANTITY = A.QUANTITY_RECEIVED
          WHERE   A.LINE_LOCATION_ID = I.LINE_LOCATION_ID
                  AND A.ORG_ID = I.ORG_ID;
         UPDATE   PO_DISTRIBUTIONS_ALL B
            SET   QUANTITY_ORDERED = I.ORDER_QTY
          WHERE   B.LINE_LOCATION_ID = I.LINE_LOCATION_ID
                  AND B.ORG_ID = I.ORG_ID;
         COMMIT;
      END IF;
   END LOOP;
   UPDATE   po_rel_performance_chk
      SET   end_date = SYSDATE
    WHERE   start_date IS NOT NULL;
   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      FND_FILE.PUT_LINE (FND_FILE.LOG, 'no-data-found');
END;
/

Query to find Expected Lines in rcv shipment


/* Formatted on 5/11/2013 7:53:40 PM (QP5 v5.115.810.9015) */
SELECT   (SELECT   (SELECT   name
                      FROM   hr_operating_units
                     WHERE   organization_id = org_id)
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            org_name,
         pv.vendor_name,
         vendor_site_code country,
         rsh.shipment_num,
         (SELECT   segment1
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            po_number,
         (SELECT   line_num
            FROM   po_lines_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id)
            po_line_num,
         (SELECT   release_num
            FROM   po_releases_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_release_id = rsl.po_release_id)
            PO_release_num,
         (SELECT   SHIPMENT_NUM
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_RELEASE_LINE_NO,
         rsl.LINE_NUM asn_line_no,
         (SELECT   segment1
            FROM   mtl_system_items_b
           WHERE   inventory_item_id = rsl.item_id AND organization_id = 86)
            part_number,
         (SELECT   QUANTITY
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty,
         (SELECT   QUANTITY_ACCEPTED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_accepted,
         (SELECT   QUANTITY_RECEIVED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_received,
         (SELECT   QUANTITY_BILLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_billed,
         (SELECT   QUANTITY_CANCELLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_cancelled,
         QUANTITY_SHIPPED RCV_QUANTITY_SHIPPED,
         QUANTITY_received RCV_QUANTITY_received,
         rsl.shipment_line_status_code,
         (SELECT   CLOSED_CODE
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_CLOSED_STATUS_CODE                                          --,
  FROM   rcv_shipment_headers rsh,
         rcv_shipment_lines rsl,
         po_vendors pv,
         po_vendor_sites_all pvs
 WHERE       1 = 1
         AND rsh.shipment_header_id = rsl.shipment_header_id
         AND rsh.vendor_id = pv.vendor_id
         AND rsh.VENDOR_SITE_ID = pvs.VENDOR_SITE_ID
         AND pv.vendor_id = pvs.vendor_id
         AND rsl.source_document_code = 'PO'
         AND rsl.shipment_line_status_code = 'EXPECTED'
--           AND rsl.po_header_id = 1321
--         AND rsh.shipment_num = 'EAAA42670'

Query to find Expected Lines


/* Formatted on 5/11/2013 7:53:40 PM (QP5 v5.115.810.9015) */
SELECT   (SELECT   (SELECT   name
                      FROM   hr_operating_units
                     WHERE   organization_id = org_id)
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            org_name,
         pv.vendor_name,
         vendor_site_code country,
         rsh.shipment_num,
         (SELECT   segment1
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            po_number,
         (SELECT   line_num
            FROM   po_lines_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id)
            po_line_num,
         (SELECT   release_num
            FROM   po_releases_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_release_id = rsl.po_release_id)
            PO_release_num,
         (SELECT   SHIPMENT_NUM
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_RELEASE_LINE_NO,
         rsl.LINE_NUM asn_line_no,
         (SELECT   segment1
            FROM   mtl_system_items_b
           WHERE   inventory_item_id = rsl.item_id AND organization_id = 86)
            part_number,
         (SELECT   QUANTITY
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty,
         (SELECT   QUANTITY_ACCEPTED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_accepted,
         (SELECT   QUANTITY_RECEIVED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_received,
         (SELECT   QUANTITY_BILLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_billed,
         (SELECT   QUANTITY_CANCELLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_cancelled,
         QUANTITY_SHIPPED RCV_QUANTITY_SHIPPED,
         QUANTITY_received RCV_QUANTITY_received,
         rsl.shipment_line_status_code,
         (SELECT   CLOSED_CODE
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_CLOSED_STATUS_CODE                                          --,
  FROM   rcv_shipment_headers rsh,
         rcv_shipment_lines rsl,
         po_vendors pv,
         po_vendor_sites_all pvs
 WHERE       1 = 1
         AND rsh.shipment_header_id = rsl.shipment_header_id
         AND rsh.vendor_id = pv.vendor_id
         AND rsh.VENDOR_SITE_ID = pvs.VENDOR_SITE_ID
         AND pv.vendor_id = pvs.vendor_id
         AND rsl.source_document_code = 'PO'
         AND rsl.shipment_line_status_code = 'EXPECTED'
--           AND rsl.po_header_id = 1321
--         AND rsh.shipment_num = 'EAAA42670'

Query to Back ordered Ageing Report


/*Back ordered Ageing Report  */
SELECT   TRUNC (SYSDATE) - TRUNC (wdd.creation_date) age,
         source_header_type_name,
         hca.customer_class_code,
         hca.ACCOUNT_NUMBER cust_number,
         wdd.organization_id
  FROM   wsh_delivery_details wdd,
         hz_cust_accounts hca,
         oe_order_headers_all ooha,
         oe_order_lines_all oola
 WHERE       1 = 1
         AND ooha.header_id = oola.header_id
         AND wdd.source_header_id = ooha.header_id
         AND wdd.source_line_id = oola.line_id
         AND wdd.inventory_item_id = oola.inventory_item_id
         AND wdd.customer_id = hca.cust_account_id
         AND wdd.source_code = 'OE'
         AND wdd.organization_id = NVL (P_ORG_ID, wdd.organization_id)
         AND wdd.SOURCE_HEADER_TYPE_ID = 1007                 -- Order type ID
         AND SUBSTR (hca.customer_class_code, 1, 2) IN
                  NVL (p_business, SUBSTR (hca.customer_class_code, 1, 2)) -- Business code
         AND wdd.released_status IN ('B')

Query to find the concurrent manager for a specific concurrent request.


/* To find the concurrent manager for a specific concurrent request. */


SELECT b.user_concurrent_queue_name
FROM fnd_concurrent_processes a,
fnd_concurrent_queues_vl b,
fnd_concurrent_requests c
WHERE a.concurrent_queue_id = b.concurrent_queue_id
AND a.concurrent_process_id = c.controlling_manager
AND c.request_id = :p_request_id

script to compile all invalid objects in APPS Schema

/* script to compile all invalid objects in APPS Schema */

* Pls login through APPS schema and run the below script


begin
dbms_utility.compile_schema('APPS');
end;

Query to find difference between concurrent start time and complete time

e

  SELECT   fcr.request_id,
           fu.user_name,
           FCP.USER_CONCURRENT_PROGRAM_NAME Report_Name,
           ARGUMENT_TEXT Parameters,
           MAX (FCRC.DATE1) SCHEDULED_PROG_START_DATE,
           MAX (FCRC.DATE2) SCHEDULED_PROG_END_DATE,
           NVL ( (DECODE (STATUS_CODE,
                          'C',
                          'COMPLETED',
                          'R',
                          'RUNNING',
                          'G',
                          'WARNING',
                          'D',
                          'CANCELLED',
                          'X',
                          'TERMINATED',
                          'E',
                          'ERROR')), STATUS_CODE)
              statUS,
           REQUESTED_START_DATE,
           ACTUAL_START_DATE,
           ACTUAL_COMPLETION_DATE,
           TO_CHAR (
              TRUNC( (  (ACTUAL_COMPLETION_DATE - ACTUAL_START_DATE)
                      * 24
                      * 60
                      * 60)
                    / 60
                    / 60),
              '09'
           )
           || 'HR'
           || TO_CHAR (
                 TRUNC(MOD (
                          (  (ACTUAL_COMPLETION_DATE - ACTUAL_START_DATE)
                           * 24
                           * 60
                           * 60),
                          3600
                       )
                       / 60),
                 '09'
              )
           || 'MIN'
           || TO_CHAR (
                 MOD (
                    MOD (
                       (  (ACTUAL_COMPLETION_DATE - ACTUAL_START_DATE)
                        * 24
                        * 60
                        * 60),
                       3600
                    ),
                    60
                 ),
                 '09'
              )
           || 'SEC'
              Time_difference,
           '' comments,
           '' Solved
    FROM   fnd_concurrent_requests fcr,
           fnd_concurrent_programs_tl fcp,
           fnd_conc_release_classes FCRC,
           fnd_user fu
   WHERE       fcr.CONCURRENT_PROGRAM_ID = fcp.CONCURRENT_PROGRAM_ID
           AND fcr.REQUESTED_BY = fu.user_id
           AND fcr.release_class_id = fcrc.release_class_id(+)
           AND fcr.concurrent_program_id = 41587
           -- AND fcp.user_concurrent_program_name --LIKE 'Pre%'
           --           IN ('Pregenerate putaway suggestions')
           --  ( 'Pre)
           AND TRUNC (fcr.REQUESTED_START_DATE) BETWEEN TRUNC (SYSDATE - 1)
                                                    AND  TRUNC (SYSDATE)
           --           AND FCR.REQUESTED_BY = 2678
           AND status_code = 'Q'                           --NOT IN ('Q', 'I')
--           AND phase_code <> 'P'
GROUP BY   request_id,
           FCP.USER_CONCURRENT_PROGRAM_NAME,
           STATUS_CODE,
           REQUESTED_START_DATE,
           ACTUAL_START_DATE,
           ACTUAL_COMPLETION_DATE,
           ARGUMENT_TEXT,
           fu.user_name
ORDER BY   2

Saturday, 11 May 2013

Query to find on hand qty on specific date


/* Formatted on 08-Apr-12 5:27:39 PM (QP5 v5.115.810.9015) */
/*HOW TO FIND THE ON HAND QUANTITY FOR A SPECIFIC DATE */

  SELECT   ITEM_ID, SUM (TARGET_QTY) quantity
    FROM   (  SELECT   moqd.inventory_item_id item_id,
                       SUM (primary_transaction_quantity) target_qty
                FROM   mtl_onhand_quantities_detail moqd
               WHERE   moqd.organization_id = :p_organizations
--               and moqd.inventory_item_id =65345
                       AND moqd.owning_tp_type =
                             DECODE (2, 2, 2, moqd.owning_tp_type)
            GROUP BY   moqd.inventory_item_id
            UNION
              SELECT   mmt.inventory_item_id item_id,
                       -SUM (primary_quantity) target_qty
                FROM   mtl_material_transactions mmt,
                       mtl_txn_source_types mtst,
                       mtl_parameters mp
               WHERE       mmt.organization_id = :p_organizations
                       AND mp.organization_id = :p_organizations
                       AND trunc(transaction_date) >= to_date((:p_start_date ),'DD-MON-RR')+ 1
                       AND NVL (mmt.owning_tp_type, 2) =
                             DECODE (2, 2, 2, NVL (mmt.owning_tp_type, 2))
                       AND mmt.transaction_source_type_id =
                             mtst.transaction_source_type_id
                       AND NVL (mmt.logical_transaction, 2) <> 1
--                       and mmt.inventory_item_id =65345
            GROUP BY   mmt.inventory_item_id)
GROUP BY   ITEM_ID

Query to retrieve vendor against the total receiving qty


select vendor_name,sum(receive_qty) from (SELECT    NVL (
            NVL (
               (SELECT   vendor_name
                  FROM   rcv_shipment_headers rt, po_vendors pv
                 WHERE       shipment_header_id = rsh.shipment_header_id
                         AND rt.vendor_id = pv.vendor_id
                         AND ROWNUM = 1),
               (SELECT   ood.name
                  FROM   rcv_shipment_lines rt, hr_operating_units ood
                 WHERE       shipment_header_id = rsh.shipment_header_id
                         AND rt.from_organization_id = ood.organization_id
                         AND ROWNUM = 1)
            ),
            (SELECT   customer_name
               FROM   ar_customers ar, rcv_transactions rt
              WHERE       rt.customer_id = ar.customer_id
                      AND rt.shipment_header_id = rsh.shipment_header_id
                      AND ROWNUM = 1)
         )
            vendor_name,  quantity  receive_qty
  FROM   rcv_transactions rt,
         rcv_shipment_headers rsh,
         rcv_shipment_lines rsl
 WHERE       rt.organization_id =  71
         AND rt.shipment_header_id = rsh.shipment_header_id
         AND rt.shipment_line_id = rsl.shipment_line_id
         and trunc(transaction_date) between '01-JAN-2012' and '31-JAN-2012'
         and transaction_type ='RECEIVE')
         group by vendor_name  order by 1

Query to find Expected Lines status in rcv shipment lines


/* Formatted on 5/11/2013 7:53:40 PM (QP5 v5.115.810.9015) */
SELECT   (SELECT   (SELECT   name
                      FROM   hr_operating_units
                     WHERE   organization_id = org_id)
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            org_name,
         pv.vendor_name,
         vendor_site_code country,
         rsh.shipment_num,
         (SELECT   segment1
            FROM   po_headers_all
           WHERE   po_header_id = rsl.po_header_id)
            po_number,
         (SELECT   line_num
            FROM   po_lines_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id)
            po_line_num,
         (SELECT   release_num
            FROM   po_releases_all
           WHERE   po_header_id = rsl.po_header_id
                   AND po_release_id = rsl.po_release_id)
            PO_release_num,
         (SELECT   SHIPMENT_NUM
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_RELEASE_LINE_NO,
         rsl.LINE_NUM asn_line_no,
         (SELECT   segment1
            FROM   mtl_system_items_b
           WHERE   inventory_item_id = rsl.item_id AND organization_id = 86)
            part_number,
         (SELECT   QUANTITY
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty,
         (SELECT   QUANTITY_ACCEPTED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_accepted,
         (SELECT   QUANTITY_RECEIVED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_received,
         (SELECT   QUANTITY_BILLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_billed,
         (SELECT   QUANTITY_CANCELLED
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            po_qty_cancelled,
         QUANTITY_SHIPPED RCV_QUANTITY_SHIPPED,
         QUANTITY_received RCV_QUANTITY_received,
         rsl.shipment_line_status_code,
         (SELECT   CLOSED_CODE
            FROM   po_line_locations_all
           WHERE       po_header_id = rsl.po_header_id
                   AND po_line_id = rsl.po_line_id
                   AND po_release_id = rsl.po_release_id
                   AND line_location_id = rsl.po_line_location_id)
            PO_CLOSED_STATUS_CODE                                          --,
  FROM   rcv_shipment_headers rsh,
         rcv_shipment_lines rsl,
         po_vendors pv,
         po_vendor_sites_all pvs
 WHERE       1 = 1
         AND rsh.shipment_header_id = rsl.shipment_header_id
         AND rsh.vendor_id = pv.vendor_id
         AND rsh.VENDOR_SITE_ID = pvs.VENDOR_SITE_ID
         AND pv.vendor_id = pvs.vendor_id
         AND rsl.source_document_code = 'PO'
         AND rsl.shipment_line_status_code = 'EXPECTED'
--           AND rsl.po_header_id = 1321
--         AND rsh.shipment_num = 'EAAA42670'

Create Data Base link


   CREATE DATABASE LINK 'instance_name'
 CONNECT TO 'schema' --eg -- apps
 IDENTIFIED BY passoword
 USING '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 00.0.0.000)(PORT = 1111)) )
    (CONNECT_DATA =
      (SERVICE_NAME = 'NAME')
    )
  )';

Friday, 10 May 2013

Procedure for BOM interface





Step 1: Create staging table for header

create table dmf_bom_ph_bom_com (
C_PROJECTED_YIELD    varchar2(100),
C_PLANNING_PERCENT    varchar2(100),
C_MINIMUM_ALLOWED_QUANTITY    varchar2(100),
C_MAXIMUM_ALLOWED_QUANTITY    varchar2(100),
C_TRANSACTION_TYPE    varchar2(100),
C_START_EFFECTIVE_DATE    varchar2(100),
C_ALTERNATE_BOM_CODE    varchar2(100),
C_ORGANIZATION_CODE    varchar2(100),
C_ASSEMBLY_ITEM_NAME    varchar2(100),
C_QUANTITY_PER_ASSEMBLY    varchar2(100),
C_ITEM_SEQUENCE_NUMBER    varchar2(100),
C_OPERATION_SEQUENCE_NUMBER    varchar2(100),
C_COMPONENT_ITEM_NAME    varchar2(100),
C_ATTRIBUTE_CATEGORY    varchar2(100),
SUPPLY_TYPE    varchar2(100),
OPTIONAL    varchar2(100),
INCLUDE_ON_SHIP_DOCS    varchar2(100),
COMPONENT_QUANTITY    varchar2(100),
COMPONENT_REMARKS    varchar2(100),
RETURN_STATUS    varchar2(100))


Step 2:

create table for header   dmf_bom_ph_bom_header:

create table  for the following fields

  return_status,                    
                          assembly_type,
                          transaction_type,
                         
                          assembly_item_name,
                          organization_code,
                          alternate_bom_code,
                          attribute_category,
                          operating_unit_name
     









/* Formatted on 10/22/2012 2:33:19 PM (QP5 v5.115.810.9015) */
--CREATE OR REPLACE PROCEDURE bolinf.dmf_bom_ph_billofmaterial (
--   errbuf    OUT VARCHAR2,
--   retcode   OUT NUMBER
--)
--IS

DECLARE
   l_cnt                         NUMBER := 0;
   d_actionvalidate_msg          VARCHAR2 (1000);
   d_actionvalidate_flag         VARCHAR2 (1000);
   d_actionvalidate_value        DATE;
   l_error_details               VARCHAR2 (4000);
   b1                            NUMBER := 1;
   bom_hdr_lno                   NUMBER;
   bom_hdr_exid                  NUMBER;
   l_condt_flag                  VARCHAR2 (10);
   assembly_item_name            VARCHAR2 (4000);
   organization_code             VARCHAR2 (4000);
   alternate_bom_code            VARCHAR2 (4000);
   assembly_type                 VARCHAR2 (4000);
   transaction_type              VARCHAR2 (4000);
   attribute_category            VARCHAR2 (4000);
   attribute1                    VARCHAR2 (4000);
   attribute2                    VARCHAR2 (4000);
   attribute3                    VARCHAR2 (4000);
   attribute4                    VARCHAR2 (4000);
   attribute5                    VARCHAR2 (4000);
   attribute6                    VARCHAR2 (4000);
   attribute7                    VARCHAR2 (4000);
   attribute8                    VARCHAR2 (4000);
   attribute9                    VARCHAR2 (4000);
   attribute10                   VARCHAR2 (4000);
   attribute11                   VARCHAR2 (4000);
   attribute12                   VARCHAR2 (4000);
   attribute13                   VARCHAR2 (4000);
   attribute14                   VARCHAR2 (4000);
   attribute15                   VARCHAR2 (4000);
   row_identifier                NUMBER;
--   bom_implementation_date       DATE;
   implementation_date           DATE;
   b2                            NUMBER := 1;
   bom_comp_lno                  NUMBER;
   bom_comp_exid                 NUMBER;
   c_organization_code           VARCHAR2 (4000);
   c_assembly_item_name          VARCHAR2 (4000);
--   c_start_effective_date        VARCHAR2 (100);
   c_operation_sequence_number   NUMBER;
   c_component_item_name         VARCHAR2 (4000);
   c_alternate_bom_code          VARCHAR2 (4000);
   c_item_sequence_number        NUMBER;
   c_quantity_per_assembly       NUMBER;
   c_planning_percent            NUMBER;
   c_projected_yield             NUMBER;
   supply_type                   VARCHAR2 (4000);
   optional                      VARCHAR2 (4000);
   include_on_ship_docs          VARCHAR2 (4000);
   c_minimum_allowed_quantity    NUMBER;
   c_maximum_allowed_quantity    NUMBER;
   component_remarks             VARCHAR2 (4000);
   c_attribute_category          VARCHAR2 (4000);
   c_attribute3                  VARCHAR2 (4000);
   c_attribute4                  VARCHAR2 (4000);
   c_attribute5                  VARCHAR2 (4000);
   c_attribute6                  VARCHAR2 (4000);
   c_attribute7                  VARCHAR2 (4000);
   c_attribute8                  VARCHAR2 (4000);
   c_attribute9                  VARCHAR2 (4000);
   c_attribute10                 VARCHAR2 (4000);
   c_attribute11                 VARCHAR2 (4000);
   c_attribute12                 VARCHAR2 (4000);
   c_attribute13                 VARCHAR2 (4000);
   c_attribute14                 VARCHAR2 (4000);
   c_attribute15                 VARCHAR2 (4000);
   c_transaction_type            VARCHAR2 (4000);
   x_return_status               VARCHAR2 (4000);
   x_msg_count                   NUMBER;
   p_status_code                 VARCHAR2 (1000);
   status_code                   VARCHAR2 (1000);
   operating_unit_name           VARCHAR2 (1000);
   component_item_name           VARCHAR2 (1000);
   l_assembly_item_name          VARCHAR2 (4000);
   l_user_id                     NUMBER;
   component_quantity            NUMBER;
   l_component_item_name         VARCHAR2 (1000);
   l_alternate_bom_designator    VARCHAR2 (100);

   --   l_user_id                     NUMBER := 1150;

   CURSOR bom_hdr
   IS
 
        SELECT   DISTINCT return_status,                     --row_identifier,
                          assembly_type,
                          transaction_type,
                          --bom_implementation_date,
                          assembly_item_name,
                          organization_code,
                          alternate_bom_code,
                          attribute_category,
                          operating_unit_name
          FROM   dmf_bom_ph_bom_header
         WHERE   return_status IS NULL
      GROUP BY   return_status,
                 -- row_identifier,
                 assembly_type,
                 transaction_type,
--                 bom_implementation_date,
                 assembly_item_name,
                 organization_code,
                 alternate_bom_code,
                 attribute_category,
                 operating_unit_name;

   CURSOR bom_comp (
      p_assembly_item_name                 VARCHAR2,
      p_organization_code                  VARCHAR2
   )
   IS
 
        SELECT   DISTINCT c_projected_yield,
                          c_planning_percent,
                          c_minimum_allowed_quantity,
                          c_maximum_allowed_quantity,
                          c_transaction_type,
--                            c_start_effective_date,
                          c_alternate_bom_code,
                          c_organization_code,
                          c_assembly_item_name,
                          c_quantity_per_assembly,
                          c_item_sequence_number,
                          c_operation_sequence_number,
                          c_component_item_name,
                          c_attribute_category,
                          optional,
                          include_on_ship_docs,
                          component_remarks,
                          supply_type,
                          component_quantity,
                          return_status
          FROM   dmf_bom_ph_bom_com
         WHERE       return_status IS NULL
                 AND c_assembly_item_name = p_assembly_item_name
                 AND c_organization_code = p_organization_code
      GROUP BY   c_projected_yield,
                 c_planning_percent,
                 c_minimum_allowed_quantity,
                 c_maximum_allowed_quantity,
                 c_transaction_type,
--                 c_start_effective_date,
                 c_alternate_bom_code,
                 c_organization_code,
                 c_assembly_item_name,
                 c_quantity_per_assembly,
                 c_item_sequence_number,
                 c_operation_sequence_number,
                 c_component_item_name,
                 c_attribute_category,
                 optional,
                 include_on_ship_docs,
                 component_remarks,
                 supply_type,
                 component_quantity,
                 return_status;
               
BEGIN
   --   fnd_profile.get ('USER_ID', l_user_id);
   BEGIN
      SELECT   user_id
        INTO   l_user_id
        FROM   fnd_user
       WHERE   user_name = 'HLIFE';
   END;

   FOR cur_bom_hdr IN bom_hdr
   LOOP
      BEGIN
         SELECT   organization_id
           INTO   operating_unit_name
           FROM   org_organization_definitions
          WHERE   organization_code = cur_bom_hdr.organization_code;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line (
               'Invalide Organization ID ' || cur_bom_hdr.organization_code
            );
            fnd_file.put_line (
               fnd_file.LOG,
               'Invalide Organization ID ' || cur_bom_hdr.organization_code
            );
      END;

      BEGIN
         SELECT   inventory_item_id
           INTO   l_assembly_item_name
           FROM   mtl_system_items
          WHERE   segment1 = cur_bom_hdr.assembly_item_name
                  AND organization_id = operating_unit_name;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line (
               'Assembly Invalid Item ' || cur_bom_hdr.assembly_item_name
            );
            fnd_file.put_line (
               fnd_file.LOG,
               'Assembly Invalid Item ' || cur_bom_hdr.assembly_item_name
            );
      END;

--      implementation_date := cur_bom_hdr.bom_implementation_date;
      transaction_type := cur_bom_hdr.transaction_type;

      IF (cur_bom_hdr.alternate_bom_code IS NOT NULL)
      THEN
         BEGIN
            SELECT   alternate_designator_code
              INTO   l_alternate_bom_designator
              FROM   bom_alternate_designators
             WHERE   alternate_designator_code =
                        cur_bom_hdr.alternate_bom_code;
         EXCEPTION
            WHEN NO_DATA_FOUND
            THEN
               DBMS_OUTPUT.put_line ('Alt BOM Code Err: ' || SQLERRM);
            WHEN OTHERS
            THEN
               DBMS_OUTPUT.put_line ('Alt BOM Code Err: ' || SQLERRM);
         END;
      END IF;

      --                           l_ALTERNATE_BOM_DESIGNATOR := cur_bom_hdr.alternate_bom_code;
      IF (transaction_type IS NULL)
      THEN
         transaction_type := 'CREATE';
      END IF;

      INSERT INTO bom_bill_of_mtls_interface (assembly_item_id,
                                              organization_id,
                                              bill_sequence_id,
                                              item_number,
                                              last_update_date,
                                              last_updated_by,
                                              creation_date,
                                              created_by,
                                              transaction_type,
                                              process_flag,
                                              alternate_bom_designator)
        VALUES   (l_assembly_item_name,
                  operating_unit_name,
                  NULL,
                  cur_bom_hdr.assembly_item_name,
--                  implementation_date,
sysdate,
                  l_user_id,
                  implementation_date,
                  l_user_id,
                  transaction_type,
                  1,
                  l_alternate_bom_designator);

      BEGIN
         FOR cur_bom_comp
         IN bom_comp (cur_bom_hdr.assembly_item_name,
                      cur_bom_hdr.organization_code)
         LOOP
            BEGIN
               SELECT   inventory_item_id
                 INTO   l_component_item_name
                 FROM   mtl_system_items
                WHERE   segment1 = cur_bom_comp.c_component_item_name
                        AND organization_id = operating_unit_name;
            EXCEPTION
               WHEN OTHERS
               THEN
                  DBMS_OUTPUT.put_line('Component Invalid Item '
                                       || cur_bom_comp.c_component_item_name);
                  fnd_file.put_line (
                     fnd_file.LOG,
                     'Component Invalid Item '
                     || cur_bom_comp.c_component_item_name
                  );
            END;

            c_item_sequence_number := cur_bom_comp.c_item_sequence_number;
            c_operation_sequence_number :=
               cur_bom_comp.c_operation_sequence_number;
            c_transaction_type := cur_bom_hdr.transaction_type;

            IF (c_transaction_type IS NULL)
            THEN
               c_transaction_type := 'CREATE';
            END IF;

            component_quantity := cur_bom_comp.component_quantity;
            DBMS_OUTPUT.put_line (
               'COMPONENT_QUANTITY ' || component_quantity
            );
            c_planning_percent := cur_bom_comp.c_planning_percent;

            IF (c_planning_percent IS NULL)
            THEN
               c_planning_percent := '100';
            END IF;

            component_remarks := cur_bom_comp.component_remarks;
--            c_start_effective_date := cur_bom_comp.c_start_effective_date;

            INSERT INTO bom_inventory_comps_interface (
                                                          component_item_id,
                                                          assembly_item_id,
                                                          organization_id,
                                                          item_num,
                                                          operation_seq_num,
                                                        --  effectivity_date,
                                                          transaction_type,
                                                          process_flag,
                                                          bill_sequence_id,
                                                          component_sequence_id,
                                                          component_quantity,
                                                          component_yield_factor,
                                                          implementation_date,
                                                          wip_supply_type,
                                                          so_basis,
                                                          check_atp,
                                                          planning_factor,
                                                          last_update_date,
                                                          last_updated_by,
                                                          creation_date,
                                                          created_by,
                                                          component_remarks,
                                                          ALTERNATE_BOM_DESIGNATOR
                       )
              VALUES   (l_component_item_name,
                        l_assembly_item_name,
                        operating_unit_name,
                        c_item_sequence_number,
                        c_operation_sequence_number,
                       -- c_start_effective_date,
                        c_transaction_type,
                        1,
                        NULL,
                        NULL,
                        component_quantity,
                        NULL,
                        implementation_date,
                        NULL,
                        NULL,
                        NULL,
                        c_planning_percent,
                        sysdate,--implementation_date,
                        l_user_id,
                        implementation_date,
                        l_user_id,
                        component_remarks,
                        l_alternate_bom_designator);
         END LOOP;
      END;
   END LOOP;

   UPDATE    dmf_bom_ph_bom_header
      SET   return_status = 'S';

   UPDATE   dmf_bom_ph_bom_com
      SET   return_status = 'S';

   COMMIT;
END;



Step final :


Once data inserted into the interface table then pls run the  import concurrent in Bills of material responsibility
"Bill and Routing Interface"


/