批量更新 ITEM 物料屬性

因爲期初物料導入有問題,須要批量修改 物料說明, 只能經過 建立臨時表 、調用API 的方式。api

DECLARE
  l_item_rec      inv_item_grp.item_rec_type;
  l_error_tbl     inv_item_grp.error_tbl_type;
  x_item_rec      inv_item_grp.item_rec_type;
  l_return_status VARCHAR2(40);

  l_inventory_item_id NUMBER;
BEGIN

  dbms_output.enable(1000000);

  FOR r IN (SELECT tmp.seq_no, tmp.item_number, tmp.item_description
              FROM cux.cux_item_temp tmp) LOOP
  
    SELECT msi.inventory_item_id
      INTO l_inventory_item_id
      FROM mtl_system_items_b msi
     WHERE msi.organization_id = 88 --主組織
       AND msi.segment1 = r.item_number;
  
    inv_globals.set_org_id(88);
  
    fnd_global.apps_initialize(1150, 50679, 401); --userid,resposi_id,app_id
  
    -- 更新標準物料表屬性
    l_item_rec.inventory_item_id := l_inventory_item_id;
    l_item_rec.organization_id   := 88; --You master organization
    l_item_rec.description       := r.item_description;
  
    inv_item_grp.update_item(p_commit           => fnd_api.g_false,
                             p_lock_rows        => fnd_api.g_true,
                             p_validation_level => fnd_api.g_valid_level_full,
                             p_item_rec         => l_item_rec,
                             x_item_rec         => x_item_rec,
                             x_return_status    => l_return_status,
                             x_error_tbl        => l_error_tbl);
  
    dbms_output.put_line(r.seq_no || ',物料說明更新成功:' || l_return_status);
  
    IF l_error_tbl.count() > 0 THEN
      FOR i IN 1 .. l_error_tbl.count LOOP
        dbms_output.put_line(r.seq_no || ',更新失敗: ' || l_error_tbl(i).message_text);
        dbms_output.put_line(r.seq_no || ',更新失敗: ' || l_error_tbl(i).message_name);
      END LOOP;
    END IF;
  
    --COMMIT;
  
  END LOOP;
END;
相關文章
相關標籤/搜索