WIP 物料事务处理 API Demo

--WIP 物料事务处理
DECLARE
  p_issue_txn_id  NUMBER;
  x_error_status  VARCHAR2(1);
  x_error_message VARCHAR2(2000);
  l_iface_rec     inv.mtl_transactions_interface%ROWTYPE;
  l_iface_lot_rec inv.mtl_transaction_lots_interface%ROWTYPE;
  l_return_status VARCHAR2(40);
  l_msg_count     NUMBER;
  l_msg_data      VARCHAR2(2000);
  l_trans_count   NUMBER;
  l_request_id    NUMBER;

BEGIN
  --
  fnd_global.apps_initialize(user_id => 2411, resp_id => 50647, resp_appl_id => 20003);
  --
  l_iface_rec.last_update_date  := SYSDATE;
  l_iface_rec.last_updated_by   := fnd_global.user_id;
  l_iface_rec.creation_date     := SYSDATE;
  l_iface_rec.created_by        := fnd_global.user_id;
  l_iface_rec.last_update_login := fnd_global.user_id;
  --
  SELECT mtl_material_transactions_s.nextval INTO l_iface_rec.transaction_interface_id FROM dual;
  l_iface_rec.transaction_header_id := l_iface_rec.transaction_interface_id;
  /************transaction_mode*********************
  * transaction_mode
  *2 Concurrent, Process transaction interface不处理,
  * 需要程序调用Inventory transaction worker处理
  *3 Background, 由Process transaction interface处理
  ***************************************************/
  l_iface_rec.transaction_mode := 3;
  /************process_flag*********************
  * process_flag 
  *1 Yes
  *2 No
  *3 Error
  ***************************************************/
  l_iface_rec.process_flag := 1;
  l_iface_rec.transaction_source_type_id := 5; --mtl_txn_source_types--Job or Schedule
  /*************************************************
  *账户别名杂项,用别名ID即disposition_id
  *账户杂项,用账户ID即code_combination_id
  *WIP物料事务,用任务ID即wip_entity_id
  *SO物料事务,用mtl_sales_orders.sales_order_id
  *子库转移或组织间转移,为空
  ************************************************/
  l_iface_rec.transaction_source_id := 178160; --l_wip_entity_id;  

  l_iface_rec.inventory_item_id := 59185; --rec_issue.inventory_item_id;
  l_iface_rec.organization_id   := 683; --rec_issue.organization_id;
  l_iface_rec.subinventory_code := '200-BX1'; --rec_issue.secondary_inventory_name;
  --l_iface_rec.locator_id           := rec_issue.inventory_location_id;
  l_iface_rec.transaction_quantity := -1; --rec_issue.transaction_quantity;
  --判断事务处理类型
  IF 1/*l_iface_rec.transaction_quantity*/ >= 0 THEN
    l_iface_rec.transaction_type_id := 35; --mtl_transaction_types--WIP Issue
  ELSE
    l_iface_rec.transaction_type_id := 43; --wip return
  END IF;
  --
  l_iface_rec.transaction_uom := 'UN'; --rec_issue.primary_uom_code;
  --l_iface_rec.reason_id            := rec_issue.reason_id;

  l_iface_rec.transaction_date := SYSDATE;
  l_iface_rec.source_code      := 'lcy_wip_issue_txn';
  l_iface_rec.source_header_id      := 178160;
  l_iface_rec.source_line_id        := 178160;
  l_iface_rec.final_completion_flag := 'N';

  INSERT INTO inv.mtl_transactions_interface VALUES l_iface_rec;
  --是否启用批次控制
  /*IF rec_issue.lot_number IS NOT NULL THEN
    l_iface_lot_rec.last_update_date  := SYSDATE;
    l_iface_lot_rec.last_updated_by   := fnd_global.user_id;
    l_iface_lot_rec.creation_date     := SYSDATE;
    l_iface_lot_rec.created_by        := fnd_global.user_id;
    l_iface_lot_rec.last_update_login := fnd_global.user_id;
  
    l_iface_lot_rec.transaction_interface_id := l_iface_rec.transaction_interface_id;
    l_iface_lot_rec.lot_number               := rec_issue.lot_number;
    l_iface_lot_rec.primary_quantity         := -rec_issue.transaction_quantity;
    l_iface_lot_rec.transaction_quantity     := -rec_issue.transaction_quantity;
  
    l_iface_lot_rec.source_code    := 'cux_wip_issue_txn';
    l_iface_lot_rec.source_line_id := rec_issue.wip_issue_txn_id;
  
    INSERT INTO inv.mtl_transaction_lots_interface VALUES l_iface_lot_rec;
  END IF;*/

  l_request_id   := inv_txn_manager_pub.process_transactions(p_api_version      => 1,
                                                             p_init_msg_list    => fnd_api.g_false,
                                                             p_commit           => fnd_api.g_false,
                                                             p_validation_level => fnd_api.g_valid_level_full,
                                                             x_return_status    => l_return_status,
                                                             x_msg_count        => l_msg_count,
                                                             x_msg_data         => l_msg_data,
                                                             x_trans_count      => l_trans_count,
                                                             p_table            => 1,
                                                             p_header_id        => l_iface_rec.transaction_header_id);
  x_error_status := l_return_status;
  BEGIN
    SELECT mti.error_code || ',' || mti.error_explanation || ',' || mli.error_code
      INTO x_error_message
      FROM mtl_transactions_interface     mti,
           mtl_transaction_lots_interface mli
     WHERE mti.transaction_interface_id = l_iface_rec.transaction_interface_id
       AND mli.transaction_interface_id(+) = mti.transaction_interface_id;
  EXCEPTION
    WHEN no_data_found THEN
      NULL;
  END;
  dbms_output.put_line('x_error_status:' || x_error_status);
  dbms_output.put_line('x_error_message:' || x_error_message);

END;

你可能感兴趣的:(wip)