ERP系統裏的BOM展開函數

ERP系統裏的BOM展開函數:

l_grp_id                      NUMBER                  ;
l_session_id                    NUMBER                  ;
l_org_id                        NUMBER           ;
l_levels_to_explode             NUMBER  :=  10              ;
l_module                        NUMBER  DEFAULT 2       ; -- BOM = 2
l_cst_type_id                   NUMBER  DEFAULT -1      ; -- All cost = -1 else 0
l_item_id                       NUMBER                  ;
l_bom_or_eng                    NUMBER                  ;
l_using_req_quantity            NUMBER                  ;
l_using_ass_dem_date    DATE                    ;
l_rev_date                      VARCHAR2(20):=  to_char(bom_dt,'DD-MON-YY HH24:MI');
l_err_msg                       VARCHAR2(250)           ;
l_error_code                    NUMBER                  ;

BEGIN
                -- 首先要有一個Group id
                SELECT  bom_explosion_temp_s.NEXTVAL
                INTO       l_grp_id               
                FROM    dual    ;

                -- 其次要得到一個Session id
                SELECT  bom_explosion_temp_session_s.NEXTVAL
                INTO       l_session_id
                FROM    dual    ;

                bompexpl.exploder_userexit(
                        verify_flag                    =>0,
                        org_id                          =>l_org_id,
                        order_by                      =>1,
                        grp_id                          =>l_grp_id,
                        session_id                    =>l_session_id,
                        levels_to_explode        =>l_levels_to_explode,
                        bom_or_eng                 =>l_bom_or_eng,
                        impl_flag                     =>1,
                        plan_factor_flag          =>2,
                        explode_option           =>2, -- 2,
                        module                        =>l_module,
                        cst_type_id                =>l_cst_type_id,
                        std_comp_flag           =>2,
                        expl_qty                    =>1,
                        item_id                      =>l_item_id,
                        alt_desg                     =>'',
                        comp_code                =>'',
                        rev_date                    =>l_rev_date,
                        err_msg                     =>l_err_msg,
                        error_code                 =>l_error_code
                        );

          END ;

運行結束後用以下語句得到結果.
SELECT *  FROM  bom_explosion_temp bet
  WHERE      bet.group_id         = l_grp_id

 

 

Select Aa.Organization_Code 組織
      ,Aa.Segment1 裝配件編碼
      ,Aa.Description 裝配件描述
      ,Msi.Segment1 組件編碼
      ,Msi.Description 組件描述
      ,Msi.Primary_Uom_Code 單位
      ,Aa.Component_Quantity 數量
      ,Aa.Component_Remarks 工位
      ,Aa.Operation_Seq_Num 工序
      ,Aa.Supply_Subinventory 供應子庫
      ,Decode(Aa.Wip_Supply_Type, 1, '推式', 2, '裝配拉式', 3, '拉式工序', 4, '批量',
                             5, '供應商', 6, '虛擬件', 7,'基於物料清單', '未定義') 供應方式
       ,Aa.Level_Num 級別
From Mtl_System_Items_b Msi
        ,(Select Bom.Organization_Id                                ,Mp.Organization_Code,Msi.Segment1
        ,Msi.Description
        ,Bic.Component_Item_Id
                     ,Bic.Component_Remarks
        ,Bic.Operation_Seq_Num
        ,Bic.Component_Quantity
        ,Bic.Supply_Subinventory
        ,Bic.Wip_Supply_Type
        ,Level Level_Num
                From Bom_Structures_b   Bom
        ,Bom_Components_b   Bic
        ,Mtl_System_Items_b Msi
        ,Mtl_Parameters     Mp
              Where Bom.Bill_Sequence_Id = Bic.Bill_Sequence_Id
        And Nvl(Bic.Disable_Date, Sysdate + 1) > Sysdate
        And Bom.Organization_Id = Msi.Organization_Id
        And Bom.Assembly_Item_Id = Msi.Inventory_Item_Id
                     And Bom.Organization_Id = Mp.Organization_Id
                    And Mp.Organization_Code = '&organization_code'
           Start With Msi.Segment1 = '&Assembly_Item_Num'  Connect By Prior                              Bic.Component_Item_Id = Bom.Assembly_Item_Id
        And Prior Bic.Wip_Supply_Type = 6) Aa
Where Msi.Organization_Id = Aa.Organization_Id
         And Msi.Inventory_Item_Id = Aa.Component_Item_Id
         And Aa.Wip_Supply_Type <> 6
Order By Aa.Component_Remarks
         ,Msi.Segment1

 

 

PROCEDURE extend_bom (
      p_sequence_id              IN       NUMBER
     ,p_organization_id          IN       NUMBER
     ,p_assembly_item_id         IN       NUMBER
     ,p_assembly_item            IN       VARCHAR2
     ,p_top_assembly_item_id     IN       NUMBER
     ,p_top_assembly_item        IN       VARCHAR2
     ,p_creation_date            IN       NUMBER
   )
   IS
      aa                            NUMBER;

      CURSOR c1
      IS
         SELECT bic.component_item_id
               ,msib.segment1
               ,bic.component_quantity unit_qty
               ,msib.wip_supply_type
               ,bic.bill_sequence_id
               ,bic.item_num
           FROM bom_bill_of_materials bom
               ,bom_inventory_components bic
               ,mtl_system_items_b msib
          WHERE bom.organization_id = p_organization_id
            AND msib.organization_id = bom.organization_id
            AND msib.inventory_item_id = bic.component_item_id
            AND bom.assembly_item_id = p_assembly_item_id
            AND NVL (bom.common_bill_sequence_id, bom.bill_sequence_id) = bic.bill_sequence_id
            AND (   bic.disable_date IS NULL
                 OR bic.disable_date > SYSDATE)
            AND effectivity_date <= SYSDATE;
   BEGIN
      FOR r1 IN c1
      LOOP
         BEGIN
            IF r1.wip_supply_type = 6
            THEN   --phantom
               BEGIN
                  extend_bom (p_sequence_id
                             ,p_organization_id
                             ,r1.component_item_id
                             ,r1.segment1
                             ,p_top_assembly_item_id
                             ,p_top_assembly_item
                             ,p_creation_date
                             );
                  NULL;
               END;
            ELSE
               BEGIN
                  INSERT INTO aps_sd_sourcing_rule_check_t
                              (sequence_id
                              ,top_assembly_item_id
                              ,assembly_item_id
                              ,component_item_id
                              ,item_num
                              ,unit_qty
                              ,organization_id
                              ,creation_date
                              ,top_assembly_item
                              ,assembly_item
                              ,item
                              )
                       VALUES (p_sequence_id
                              ,p_top_assembly_item_id
                              ,p_assembly_item_id
                              ,r1.component_item_id
                              ,r1.item_num
                              ,r1.unit_qty
                              ,p_organization_id
                              ,p_creation_date
                              ,p_top_assembly_item
                              ,p_assembly_item
                              ,r1.segment1
                              );
               END;
            END IF;
         END;
      END LOOP;

      COMMIT;
   END;

 

 

 

發佈了21 篇原創文章 · 獲贊 1 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章