背景:

   这两天在做客户化物料编码导入的功能,发现请求运行完毕后,竟然警告了!“Warning : Validation Errors Occured. Please check MTL_INTERFACE_ERRORS Table”,不明所以,追查接口表,报错内容如下:“无法在“组织物料”中创建/删除物料控制的类别集。”,对应英文代码:“INV_CAT_CANNOT_CREATE_DELETE”。


查找问题:

   比对此版本代码与过往版本代码的区别。最后发现如下:

       新版本代码中采用了insert Mtl_Item_Categories_Interface 的方式以定义料以及其类别的关系;

       旧版本代码中采用的是update Mtl_Item_Categories 表的方式。

   

   为什么旧版本运行正常无警告?肯定是标准功能已经做过了insert Mtl_Item_Categories 的操作。那么该操作在什么地方实现的?

   首先想到的是物料表 mtl_system_item_b 触发器。追查了半天,在trigger MTL_SYSTEM_ITEMS_T1 中发现一段代码,用于插入至Mtl_Item_Categories,不过该段代码被注释,详情如下:

/* Bug:2948014 Already supported by INVIDIT2.Insert_Cost_Details
   So, calling the same from IOI (UPD2B), already calling form forms(VITMB)
               if :new.inventory_asset_flag = 'Y' then
                     -- insert default material overhead or TL matl cost
                      --  row in CST_ITEM_COST_DETAILS depending on cost method
                     l_sql_stmt_num := 30;
-- begin bug 2103959
--mtl_item_categories has to be updated before calling CSTPIDIO
 insert into mtl_item_categories
        (inventory_item_id,
         category_set_id,
         category_id,
         last_update_date,
         last_updated_by,
         creation_date,
         created_by,
         last_update_login,
         program_application_id,
         program_id,
         program_update_date,
         request_id,
         organization_id)
    select  :new.inventory_item_id,
        s.category_set_id,
        s.default_category_id,
        sysdate,
        -1,
        sysdate,
        -1,
        -1,
        -1,
        -1,
        sysdate,
        -1,
       :new.organization_id
    from    mtl_category_sets_B s
    where   s.category_set_id in
        (select d.category_set_id
        from    mtl_default_category_sets d
        where   d.functional_area_id = 5)
    and not exists
       ( select  'x'
         from    mtl_item_categories c
         where   c.inventory_item_id = :new.inventory_item_id
         and     c.organization_id = :new.organization_id
         and     c.category_set_id = s.category_set_id
       );
-- end bug 2103959
                     CSTPIDIC.CSTPIDIO(:new.inventory_item_id,
                              :new.organization_id,
                              :new.last_updated_by,
                              l_cost_type_id,
                              :new.planning_make_buy_code,
                              :new.std_lot_size,
                              l_shrinkage_rate,
                              l_return_code,
                              l_return_err);
                      if l_return_code <> 0 then
                            l_sql_stmt_num := 35;
                            raise_application_error(-20000,l_return_err);
                      end if;
               end if;
Bug:2948014 Ended*/

   原来如此,oracle修复bug时将此功能移动到其他地方了。遂前往INVIDIT2.Insert_Cost_Details 查看。在Insert_Costing_Category 过程中发现了insert,代码如下:

PROCEDURE Insert_Costing_Category
(
   X_item_id        number
,  X_org_id     number
)
IS
   l_user_id     NUMBER  :=  NVL(FND_GLOBAL.User_Id, 0);
BEGIN
   insert into mtl_item_categories
        (inventory_item_id,
         category_set_id,
         category_id,
         last_update_date,
         last_updated_by,
         creation_date,
         created_by,
         last_update_login,
         program_application_id,
         program_id,
         program_update_date,
         request_id,
         organization_id)
   select
        X_item_id,
        s.category_set_id,
        s.default_category_id,
        sysdate,
        l_user_id,
        sysdate,
        l_user_id,
        -1,
        -1,
        -1,
        NULL,
        -1,
        X_org_id
    from    mtl_category_sets_B s
    where   s.category_set_id in
        (select d.category_set_id
        from    mtl_default_category_sets d
        where   d.functional_area_id = 5)
    and not exists
       ( select  'x'
         from    mtl_item_categories c
         where   c.inventory_item_id = X_item_id
         and     c.organization_id = X_org_id
         and     c.category_set_id = s.category_set_id
       );
END Insert_Costing_Category;

哈, 至此,原因找到!


方案:

   将新版本中的insert interface代码修改为源版本中的update即可。