顯示具有 EBS [BOM] 標籤的文章。 顯示所有文章
顯示具有 EBS [BOM] 標籤的文章。 顯示所有文章

2020/08/07

[Check] BOM Loop

[bom_explosion_temp.loop_flag => 表示有迴圈產生]

 DECLARE

  vOrganizationId NUMBER := 85;

  CURSOR curItem(pOrganizationId IN NUMBER) IS

    SELECT *

    FROM   mtl_system_items_b msi

    WHERE  msi.organization_id = vOrganizationId

    AND    msi.bom_enabled_flag = 'Y'

    AND    msi.planning_make_buy_code = 1;

    

  vItem curItem%ROWTYPE;

  TYPE rExp IS TABLE OF bom_explosion_temp%ROWTYPE;

  vExpTbl  rExp;

  vLoopTbl rExp := rExp();


  PROCEDURE Exploder

  (

    pOrganizationId  IN NUMBER,

    pInventoryItemId IN NUMBER,

    pVerifyFlag      IN NUMBER DEFAULT 0,

    pOrderBy         IN NUMBER DEFAULT 1,

    pGrpID           IN NUMBER DEFAULT 0,

    pSessionId       IN NUMBER DEFAULT 0,

    pLevelsToExplode IN NUMBER DEFAULT 99,

    pBomOrEng        IN NUMBER DEFAULT 1,

    pImplFlag        IN NUMBER DEFAULT 1,

    pPlanFactorFlag  IN NUMBER DEFAULT 2,

    pExplodeOption   IN NUMBER DEFAULT 2,

    pModule          IN NUMBER DEFAULT 2,

    pCstTypeId       IN NUMBER DEFAULT 0,

    pStdCompFlag     IN NUMBER DEFAULT 0,

    pExplQty         IN NUMBER DEFAULT 1,

    pAltDesg         IN VARCHAR2 DEFAULT NULL,

    pCompCode        IN VARCHAR2 DEFAULT NULL,

    pRevDate         IN VARCHAR2 DEFAULT to_char(SYSDATE,

                                                 'YYYY/MM/DD HH24:MI:SS')

  ) IS

    xErrMsg  VARCHAR2(240);

    xErrCode NUMBER := 0;

  BEGIN

    DELETE bom_explosion_temp

    WHERE  group_id = pGrpID;

    apps.bompexpl.exploder_userexit(verify_flag => pVerifyFlag,

                                    org_id => pOrganizationId,

                                    order_by => pOrderBy, grp_id => pGrpId,

                                    session_id => pSessionId,

                                    levels_to_explode => pLevelsToExplode,

                                    bom_or_eng => pBomOrEng,

                                    impl_flag => pImplFlag,

                                    plan_factor_flag => pPlanFactorFlag,

                                    explode_option => pExplodeOption,

                                    module => pModule,

                                    cst_type_id => pCstTypeId,

                                    std_comp_flag => pStdCompFlag,

                                    expl_qty => pExplQty,

                                    item_id => pInventoryItemId,

                                    alt_desg => pAltDesg,

                                    comp_code => pCompCode,

                                    rev_date => pRevDate, err_msg => xErrMsg,

                                    ERROR_CODE => xErrCode);

  END Exploder;

BEGIN

  OPEN curItem(vOrganizationId);

  LOOP

    FETCH curItem

      INTO vItem;

    EXIT WHEN curItem%NOTFOUND;

    Exploder(pOrganizationId => vItem.Organization_Id,

             pInventoryItemId => vItem.Inventory_Item_Id);

  

    SELECT *

    BULK   COLLECT

    INTO   vExpTbl

    FROM   bom_explosion_temp

    WHERE  loop_flag = 1;

  

    IF vExpTbl.count <> 0 THEN

      vLoopTbl := vLoopTbl MULTISET UNION ALL vExpTbl;

    END IF;

  END LOOP;

  CLOSE curItem;


  IF NOT vLoopTbl IS EMPTY THEN

    FOR i IN vLoopTbl.first .. vLoopTbl.last

    LOOP

      dbms_output.put_line('Top Item => ' ||

                           bom_globals.Get_Item_Name(p_org_id => vLoopTbl(i).organization_id,

                                                     p_item_id => vLoopTbl(i).top_item_id) ||

                           ' / Assembly => ' ||

                           bom_globals.Get_Item_Name(p_org_id => vLoopTbl(i).organization_id,

                                                     p_item_id => vLoopTbl(i).assembly_item_id) ||

                           ' / Component => ' ||

                           bom_globals.Get_Item_Name(p_org_id => vLoopTbl(i).organization_id,

                                                     p_item_id => vLoopTbl(i).component_item_id));

    

    END LOOP;

  ELSE

    dbms_output.put_line('No Any Loop');

  END IF;

END;



2020/08/05

[Interface] Batch update => wip_supply_type

範例 : 轉入介面
1.
INSERT INTO apps.bom_inventory_comps_interface
  (component_sequence_id,
   wip_supply_type,
   process_flag,
   transaction_type,
   batch_id)
  SELECT component_sequence_id,
         6,
         1,
         'UPDATE',
         -1
  FROM   bom_inventory_components
  WHERE  .... (通常有條件) 


2. 送出請求
DECLARE
   vOrganizationId NUMBER := 00;
   vBatchId NUMBER := -1;
   vDescriptionOfRequest VARCHAR2(200) := 'Mass Update';
   vRequestId NUMBER;
BEGIN
  fnd_global.apps_initialize(00, 00, 702);
    vRequestId := apps.fnd_request.submit_request ('BOM',               -- applicaiton short name
                                      'BMCOIN',                         -- concurrent program short name
                                      vDescriptionOfRequest,            -- description of the request
                                      '',                               --request start running time
                                      false,                            -- sub_request
                                      vOrganizationId,                  -- from here, are the bmcoin parameters. organization id
                                      1,                                --all org flag (1:yes / 2:no)
                                      2,                                --import routings (1:yes / 2 :no)
                                      1,                                --import bills of material (1:yes / 2:no)
                                      1,                                --delete processed rows  (1:yes / 2:no)
                                      vBatchId                          --batch id 
                                      );
  dbms_output.put_line(vRequestId);                                       
END;

2020/07/30

[API] for update components example

範例 : 更新wip_supply_type欄位

declare
  vBomHeaderRec        bom_bo_pub.bom_head_rec_type := bom_bo_pub.g_miss_bom_header_rec;
  vBomRevisionTbl      bom_bo_pub.bom_revision_tbl_type := bom_bo_pub.g_miss_bom_revision_tbl;
  vBomComponentTbl     bom_bo_pub.bom_comps_tbl_type := bom_bo_pub.g_miss_bom_component_tbl;
  vBomRefDesignatorTbl bom_bo_pub.bom_ref_designator_tbl_type := bom_bo_pub.g_miss_bom_ref_designator_tbl;
  vBomSubComponentTbl  bom_bo_pub.bom_sub_component_tbl_type := bom_bo_pub.g_miss_bom_sub_component_tbl;
  vErrorMessageList    error_handler.error_tbl_type;
  xBomHeaderRec        bom_bo_pub.bom_head_rec_type;
  xBomRevisionTbl      bom_bo_pub.bom_revision_tbl_type;
  xBomComponentTbl     bom_bo_pub.bom_comps_tbl_type;
  xBomRefDesignatorTbl bom_bo_pub.bom_ref_designator_tbl_type;
  xBomSubComponentTbl  bom_bo_pub.bom_sub_component_tbl_type;
  xReturnStatus        varchar2(2000);
  xMsgCount            number;
  i                    number := 1;
begin
  fnd_global.apps_initialize(00, 00, 702);

  vBomComponentTbl(i) := bom_bo_pub.g_miss_bom_component_rec;
  vBomComponentTbl(i).transaction_type := 'UPDATE';
  vBomComponentTbl(i).organization_code := 'XX';
  vBomComponentTbl(i).assembly_item_name := 'XX';
  vBomComponentTbl(i).start_effective_date := to_date('0000/00/00 00:00:00','yyyy/mm/dd hh24:mi:ss');
  vBomComponentTbl(i).component_item_name := 'XX';
  vBomComponentTbl(i).wip_supply_type := 1;
  vBomComponentTbl(i).item_sequence_number := 10;
  vBomComponentTbl(i).operation_sequence_number := 1;
  error_handler.initialize;
  bom_bo_pub.process_bom(p_bo_identifier => 'BOM',
                         p_api_version_number => 1.0,
                         -- this parameter is required. it is used by the
                         -- api to compare the version number of incoming
                         -- calls to its current version number.
                         p_init_msg_list => true,
                         -- this parameter is set to true, allows callers to
                         -- to request that the api do the initialization
                         -- of message list on their behalf.
                         p_bom_header_rec => vBomHeaderRec,
                         -- this is a set of data structures that represent
                         -- the incoming business objects. this is a record
                         -- that holds the bill of materials header for the
                         -- bom
                         p_bom_revision_tbl => vBomRevisionTbl,
                         -- all the p*_tbl parameters are data structure
                         -- that represent incoming business objects they
                         -- are pl/sql tables of records that hold records
                         -- for each of the other entities.
                         p_bom_component_tbl => vBomComponentTbl,
                         p_bom_ref_designator_tbl => vBomRefDesignatorTbl,
                         p_bom_sub_component_tbl => vBomSubComponentTbl,
                         x_bom_header_rec => xBomHeaderRec,
                         -- all the x*_tbl parameters are data structure
                         -- that represent outgoing business objects they
                         -- are pl/sql tables of records that hold records
                         -- for each of the other entities except now they
                         -- have all the changes that the import program
                         -- made to it through all the steps.
                         x_bom_revision_tbl => xBomRevisionTbl,
                         x_bom_component_tbl => xBomComponentTbl,
                         x_bom_ref_designator_tbl => xBomRefDesignatorTbl,
                         x_bom_sub_component_tbl => xBomSubComponentTbl,
                         x_return_status => xReturnStatus,
                         -- this is a flag that indicates the state of the
                         -- whole business object after the import.
                         -- 'S' - success
                         -- 'E' - error
                         -- 'F' - fatal error
                         -- 'U' - unexpected error
                         x_msg_count => xMsgCount,
                         -- this holds the number of messages in the api
                         -- message stack after the import.
                         p_debug => 'N', p_output_dir => '',
                         p_debug_filename => '');

  dbms_output.put_line('Return Status = ' || xReturnStatus);
  dbms_output.put_line('Message Count = ' || xMsgCount);
  error_handler.get_message_list(vErrorMessageList);

  if xReturnStatus <> 'S' then
    -- error processing
    for k in 1 .. xMsgCount
    loop
      dbms_output.put_line(to_char(k) || ' MESSAGE TEXT ' ||
                           substr(vErrorMessageList(k).message_text, 1, 250));
      dbms_output.put_line(to_char(k) || ' MESSAGE TYPE ' || vErrorMessageList(k).message_type);
    end loop;
    -- the business object apis do not issue commits or rollbacks. it is the responsibility of
    -- the calling code to issue them. this ensures that parts of the transactions are not left
    -- in the database. if an error occurs, the whole transaction is rolled back.
    rollback;
  else
    commit;
  end if;
end;

[BOM] Explosion

範例 : 
DECLARE

  PROCEDURE truncTemp(pGroupId IN NUMBER DEFAULT 0) IS
    PRAGMA AUTONOMOUS_TRANSACTION;
  BEGIN
    EXECUTE IMMEDIATE 'delete bom_explosion_temp where group_id = :1'
      USING pGroupId;
    COMMIT;
  END truncTemp;

  PROCEDURE Exploder
  (
    pOrganizationId  IN NUMBER,
    pInventoryItemId IN NUMBER,
    pVerifyFlag      IN NUMBER DEFAULT 0,
    pOrderBy         IN NUMBER DEFAULT 1,
    pGroupId         IN NUMBER DEFAULT 0,
    pSessionId       IN NUMBER DEFAULT 0,
    pLevelsToExplode IN NUMBER DEFAULT 10,
    pBomOrEng        IN NUMBER DEFAULT 1,
    pImplFlag        IN NUMBER DEFAULT 1,
    pPlanFactorFlag  IN NUMBER DEFAULT 2,
    pExplodeOption   IN NUMBER DEFAULT 2,
    pModule          IN NUMBER DEFAULT 2,
    pCstTypeId       IN NUMBER DEFAULT 0,
    pStdCompFlag     IN NUMBER DEFAULT 0,
    pExplQty         IN NUMBER DEFAULT 1,
    pAltDesg         IN VARCHAR2 DEFAULT NULL,
    pCompCode        IN VARCHAR2 DEFAULT NULL,
    pRevDate         IN VARCHAR2 DEFAULT to_char(SYSDATE,
                                                 'YYYY/MM/DD HH24:MI:SS')
  ) IS
    vErrorMessage VARCHAR2(240);
    vErrorCode    NUMBER := 0;
  BEGIN
  
    apps.bompexpl.exploder_userexit(verify_flag => pVerifyFlag,
                                    org_id => pOrganizationId,
                                    order_by => pOrderBy, grp_id => pGroupId,
                                    session_id => pSessionId,
                                    levels_to_explode => pLevelsToExplode,
                                    bom_or_eng => pBomOrEng,
                                    impl_flag => pImplFlag,
                                    plan_factor_flag => pPlanFactorFlag,
                                    explode_option => pExplodeOption,
                                    module => pModule,
                                    cst_type_id => pCstTypeId,
                                    std_comp_flag => pStdCompFlag,
                                    expl_qty => pExplQty,
                                    item_id => pInventoryItemId,
                                    alt_desg => pAltDesg,
                                    comp_code => pCompCode,
                                    rev_date => pRevDate,
                                    err_msg => vErrorMessage,
                                    ERROR_CODE => vErrorCode);
    dbms_output.put_line(vErrorMessage);
  END Exploder;
BEGIN
  truncTemp;
  Exploder(pOrganizationId => 00, pInventoryItemId => 00);
END;

--Script 
SELECT 'Master' itemType,
       bet.component_sequence_id,
       bet.item_num,
       bet.organization_id,
       bet.assembly_item_id,
       bet.sort_order,
       bet.plan_level,
       bet.component_item_id,
       bom_globals.Get_Item_Name(p_item_id => bet.component_item_id,
                                 p_org_id => bet.organization_id) component,
       bet.extended_quantity,
       bom_globals.get_reference_designators(p_component_sequence_id => bet.component_sequence_id) designators
FROM   bom_explosion_temp bet
WHERE  plan_level <> 0
UNION ALL
SELECT 'Substitute',
       bet.component_sequence_id,
       bet.item_num,
       bet.organization_id,
       bet.assembly_item_id,
       bet.sort_order,
       bet.plan_level,
       bsc.substitute_component_id,
       bom_globals.Get_Item_Name(p_item_id => bsc.substitute_component_id,
                                 p_org_id => bet.organization_id) component,
       (bet.extended_quantity / bet.component_quantity) *
       bsc.substitute_item_quantity,
       bom_globals.get_reference_designators(p_component_sequence_id => bet.component_sequence_id) designators
FROM   bom_explosion_temp        bet,
       bom_substitute_components bsc
WHERE  bet.component_sequence_id =
       NVL(bsc.component_sequence_id, bsc.component_sequence_id)
ORDER  BY 7,
          3,
          1