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;

沒有留言: