Monday, 13 November 2017

API to Assign Items from one Org to another org in Oracle Inventory

CREATE OR REPLACE PROCEDURE xx_assign_org_items
IS
   CURSOR c_items
   IS
      SELECT   organization_id,
               description,
               segment1,
               primary_uom_code,
               --template_name,
               weight_uom_code,
               unit_weight,
               'CREATE' transaction_type,
               --process_flag, set_process_id,
               inventory_item_id,
               item_type,
               atp_flag,
               atp_components_flag,
               bom_enabled_flag,
               customer_order_enabled_flag,
               customer_order_flag,
               enabled_flag,
               inspection_required_flag,
               internal_order_enabled_flag,
               internal_order_flag,
               inventory_asset_flag,
               inventory_item_flag,
               invoiceable_item_flag,
               invoice_enabled_flag,
               mtl_transactions_enabled_flag,
               purchasing_enabled_flag,
               purchasing_item_flag,
               receipt_required_flag,
               shippable_item_flag,
               so_transactions_flag,
               stock_enabled_flag,
               summary_flag
        FROM   mtl_system_items_b
       WHERE       organization_id = 83 --<From Org Id>
               AND inventory_item_status_code = 'Active';
           

   v_items   c_items%ROWTYPE;

   CURSOR c_wares
   IS

      SELECT   organization_id
        FROM   apps.org_organization_definitions
       WHERE   organization_id = 102; ---<To Org Id>

   v_wares   c_wares%ROWTYPE;
BEGIN
   OPEN c_items;

   LOOP
      FETCH c_items INTO   v_items;

      EXIT WHEN c_items%NOTFOUND;

      OPEN c_wares;

      LOOP
         FETCH c_wares INTO   v_wares;

         EXIT WHEN c_wares%NOTFOUND;

         --dbms_output.put_line( v_wares.organization_id || ' ' || v_items.description );
         BEGIN
            INSERT INTO mtl_system_items_interface (
                                                       organization_id,
                                                       description,
                                                       segment1,
                                                       primary_uom_code,
                                                       template_name,
                                                       weight_uom_code,
                                                       unit_weight,
                                                       transaction_type,
                                                       process_flag,
                                                       set_process_id,
                                                       inventory_item_id,
                                                       last_update_date,
                                                       item_type,
                                                       atp_flag,
                                                       atp_components_flag,
                                                       bom_enabled_flag,
                                                       customer_order_enabled_flag,
                                                       customer_order_flag,
                                                       enabled_flag,
                                                       inspection_required_flag,
                                                       internal_order_enabled_flag,
                                                       internal_order_flag,
                                                       inventory_asset_flag,
                                                       inventory_item_flag,
                                                       invoiceable_item_flag,
                                                       invoice_enabled_flag,
                                                       mtl_transactions_enabled_flag,
                                                       purchasing_enabled_flag,
                                                       purchasing_item_flag,
                                                       receipt_required_flag,
                                                       shippable_item_flag,
                                                       so_transactions_flag,
                                                       stock_enabled_flag,
                                                       summary_flag,
                                                       last_updated_by,
                                                       creation_date,
                                                       created_by,
                                                       last_update_login,
                                                       request_id,
                                                       program_application_id,
                                                       program_id,
                                                       program_update_date
                       )
              VALUES   (v_wares.organization_id,
                        v_items.description,
                        v_items.segment1,
                        v_items.primary_uom_code,
                        '',
                        v_items.weight_uom_code,
                        v_items.unit_weight,
                        'CREATE',
                        1,
                        1,
                        v_items.inventory_item_id,
                        SYSDATE,
                        v_items.item_type,
                        v_items.atp_flag,
                        v_items.atp_components_flag,
                        v_items.bom_enabled_flag,
                        v_items.customer_order_enabled_flag,
                        v_items.customer_order_flag,
                        v_items.enabled_flag,
                        v_items.inspection_required_flag,
                        v_items.internal_order_enabled_flag,
                        v_items.internal_order_flag,
                        v_items.inventory_asset_flag,
                        v_items.inventory_item_flag,
                        v_items.invoiceable_item_flag,
                        v_items.invoice_enabled_flag,
                        v_items.mtl_transactions_enabled_flag,
                        v_items.purchasing_enabled_flag,
                        v_items.purchasing_item_flag,
                        v_items.receipt_required_flag,
                        v_items.shippable_item_flag,
                        v_items.so_transactions_flag,
                        v_items.stock_enabled_flag,
                        v_items.summary_flag,
                        fnd_global.user_id,
                        SYSDATE,
                        fnd_global.user_id,
                        fnd_global.login_id,
                        fnd_global.conc_request_id,
                        fnd_global.prog_appl_id,
                        fnd_global.conc_program_id,
                        SYSDATE);

            IF SQL%NOTFOUND
            THEN
               DBMS_OUTPUT.put_line('Insert Failed in Header Level at segment : '
                                    || v_items.segment1
                                    || ' and organization_id : '
                                    || v_wares.organization_id);
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               DBMS_OUTPUT.put_line('Insert Failed in Header Level at segment : '
                                    || v_items.segment1
                                    || ' and organization_id : '
                                    || v_wares.organization_id);
         END;
      END LOOP;

      CLOSE c_wares;
   END LOOP;

   CLOSE c_items;
END xx_assign_org_items;
/

Note: Run "Import Items" Program from the destination Organization.

No comments:

Post a Comment