EBS采购订单接收

/*
begin
  fnd_global.apps_initialize(user_id      => 8162,
                             resp_id      => 50692,
                             resp_appl_id => 20003);
  mo_global.init('M');
end;
*/

/*
select pha.segment1,
       pha.po_header_id,
       pla.po_line_id,
       pla.item_id,
       pla.quantity,
       pla.unit_meas_lookup_code,
       pda.line_location_id,
       pda.lo
       pda.po_distribution_id
  from po_headers_all pha, po_lines_all pla, po_distributions_all pda
 where pha.org_id = 295
   and pha.created_by = 8162
   and pla.po_header_id = pha.po_header_id
   and pda.po_line_id = pla.po_line_id
 order by pha.segment1 desc;
 */


--采购订单接收--attention:注意修改接收数量和插入批次表的数量保持一致
--测试通过uat 20190906
declare
 
    l_api_name CONSTANT VARCHAR2(30) := 'rcv_txn_process';
    l_savepoint_name VARCHAR2(30) := NULL;

 
    rc                  NUMBER := 0;
    outcome             VARCHAR2(200) := NULL;
    message             VARCHAR2(200) := NULL;
    r_val1              VARCHAR2(200) := NULL;
    r_val2              VARCHAR2(200) := NULL;
    r_val3              VARCHAR2(200) := NULL;
    r_val4              VARCHAR2(200) := NULL;
    r_val5              VARCHAR2(200) := NULL;
    r_val6              VARCHAR2(200) := NULL;
    r_val7              VARCHAR2(200) := NULL;
    r_val8              VARCHAR2(200) := NULL;
    r_val9              VARCHAR2(200) := NULL;
    r_val10             VARCHAR2(200) := NULL;
    r_val11             VARCHAR2(200) := NULL;
    r_val12             VARCHAR2(200) := NULL;
    r_val13             VARCHAR2(200) := NULL;
    r_val14             VARCHAR2(200) := NULL;
    r_val15             VARCHAR2(200) := NULL;
    r_val16             VARCHAR2(200) := NULL;
    r_val17             VARCHAR2(200) := NULL;
    r_val18             VARCHAR2(200) := NULL;
    r_val19             VARCHAR2(200) := NULL;
    r_val20             VARCHAR2(200) := NULL;
    x_str               VARCHAR2(4000) := NULL;
    timeout             NUMBER;
    l_str1              fnd_new_messages.message_text%TYPE := NULL;
    l_header_iface_rec  po.rcv_headers_interface%ROWTYPE;
    l_rcv_txn_iface_rec po.rcv_transactions_interface%ROWTYPE;
    l_mtl_iface_lots_rec         mtl_transaction_lots_interface%ROWTYPE; --批次接口表
    l_mtl_txn_lots_rec           mtl_transaction_lots_temp%ROWTYPE;
    l_group_id          NUMBER;
 
  BEGIN
 
    
      IF l_group_id IS NULL THEN
        l_group_id := po.rcv_interface_groups_s.nextval;
      END IF;
      l_header_iface_rec.header_interface_id     := po.rcv_headers_interface_s.nextval;
      l_header_iface_rec.group_id                := l_group_id;
      l_header_iface_rec.org_id                  := 295;--rec_poh.org_id;
      l_header_iface_rec.processing_status_code  := 'PENDING';
      l_header_iface_rec.receipt_source_code     := 'VENDOR';
      l_header_iface_rec.transaction_type        := 'NEW';
      l_header_iface_rec.auto_transact_code      := 'DELIVER';
      l_header_iface_rec.vendor_id               := 326957;--rec_poh.vendor_id;
      l_header_iface_rec.vendor_site_id          := 598395;--rec_poh.vendor_site_id;
      l_header_iface_rec.expected_receipt_date   := SYSDATE;
      l_header_iface_rec.validation_flag         := 'Y';
      l_header_iface_rec.ship_to_organization_id := 315;--rec_poh.inventory_organization_id;
      l_header_iface_rec.receipt_num             := NULL; --Automatic Number
    
      l_header_iface_rec.last_update_date  := SYSDATE;
      l_header_iface_rec.last_updated_by   := 8162;
      l_header_iface_rec.creation_date     := SYSDATE;
      l_header_iface_rec.created_by        := 8162;
      l_header_iface_rec.last_update_login := -1;
    
      INSERT INTO po.rcv_headers_interface VALUES l_header_iface_rec;
    
        l_rcv_txn_iface_rec                          := NULL;
        l_rcv_txn_iface_rec.interface_transaction_id := rcv_transactions_interface_s.nextval;
        l_rcv_txn_iface_rec.header_interface_id      := l_header_iface_rec.header_interface_id;
        l_rcv_txn_iface_rec.group_id                 := l_group_id;
        l_rcv_txn_iface_rec.org_id                   := 295;--rec_poh.org_id;
        l_rcv_txn_iface_rec.processing_status_code   := 'PENDING';
        l_rcv_txn_iface_rec.transaction_status_code  := 'PENDING';
        l_rcv_txn_iface_rec.processing_mode_code     := 'ONLINE';
        l_rcv_txn_iface_rec.validation_flag          := 'Y';
        l_rcv_txn_iface_rec.receipt_source_code      := 'VENDOR';
        l_rcv_txn_iface_rec.vendor_id                := 326957;--rec_poh.vendor_id;
        l_rcv_txn_iface_rec.vendor_site_id           := 598395;--rec_poh.vendor_site_id; --Optional      
        l_rcv_txn_iface_rec.source_document_code     := 'PO';
        l_rcv_txn_iface_rec.po_header_id             := 529302;--529294;--rec_po.po_header_id;
        l_rcv_txn_iface_rec.po_line_id               := 885818;--rec_po.po_line_id;
        l_rcv_txn_iface_rec.po_line_location_id      := 1030063;--1030055;--rec_po.line_location_id;
        l_rcv_txn_iface_rec.po_release_id            := NULL;
        l_rcv_txn_iface_rec.transaction_type         := 'RECEIVE';
        l_rcv_txn_iface_rec.auto_transact_code       := 'DELIVER';
        l_rcv_txn_iface_rec.destination_type_code    := 'EXPENSE'; --'RECEIVING';
       -- l_rcv_txn_iface_rec.item_description         := rec_po.item_description;
        l_rcv_txn_iface_rec.item_id         := 231102;--rec_po.item_description;
        l_rcv_txn_iface_rec.transaction_date         := sysdate;
        l_rcv_txn_iface_rec.quantity                 := 1.5;--rec_po.quantity;
        l_rcv_txn_iface_rec.unit_of_measure          := '千克';--rec_po.unit_meas_lookup_code; --Not Code      
        l_rcv_txn_iface_rec.to_organization_id       := 315;--rec_poh.inventory_organization_id;
        l_rcv_txn_iface_rec.ship_to_location_id      := 10888;--rec_po.ship_to_location_id;
        l_rcv_txn_iface_rec.deliver_to_location_id   := 10888;--rec_po.ship_to_location_id;
        l_rcv_txn_iface_rec.location_id              := 10888;--rec_po.ship_to_location_id;
        l_rcv_txn_iface_rec.subinventory               := 'MQ01'; --子库存
        l_rcv_txn_iface_rec.locator_id                 := 17995;--rec_line.locator_id; --货位        
        l_rcv_txn_iface_rec.interface_source_code    := 'WORK_PROGRESS';
        l_rcv_txn_iface_rec.interface_source_line_id := 9999;
        l_rcv_txn_iface_rec.attribute2               := 'N';
      
        l_rcv_txn_iface_rec.last_update_date       := SYSDATE;
        l_rcv_txn_iface_rec.last_updated_by        := 8162;
        l_rcv_txn_iface_rec.creation_date          := SYSDATE;
        l_rcv_txn_iface_rec.created_by             := 8162;
        l_rcv_txn_iface_rec.last_update_login      := -1;
        l_rcv_txn_iface_rec.program_application_id := 20003;
        l_rcv_txn_iface_rec.program_id             := -1;
        l_rcv_txn_iface_rec.program_update_date    := SYSDATE;
        l_rcv_txn_iface_rec.request_id             := 9999;
      
        INSERT INTO rcv_transactions_interface VALUES l_rcv_txn_iface_rec;

--插入批次接口表      
        l_mtl_txn_lots_rec := NULL;
        l_mtl_txn_lots_rec.transaction_temp_id    := l_rcv_txn_iface_rec.interface_transaction_id;
        l_mtl_txn_lots_rec.last_update_date       := SYSDATE;
        l_mtl_txn_lots_rec.last_updated_by        := 8162;
        l_mtl_txn_lots_rec.creation_date          := SYSDATE;
        l_mtl_txn_lots_rec.created_by             := 8162;
        l_mtl_txn_lots_rec.last_update_login      := -1;
        l_mtl_txn_lots_rec.transaction_quantity   := trunc(1.5
                                                          ,5);
        l_mtl_txn_lots_rec.primary_quantity       := trunc(1.5
                                                          ,5);
        l_mtl_txn_lots_rec.lot_number             := '2736-GT-GA01-1';--rec_line.lot_number;
        l_mtl_txn_lots_rec.group_header_id        := cux_pub_group_s.nextval;
        l_mtl_txn_lots_rec.lot_expiration_date    := NULL;
        l_mtl_txn_lots_rec.secondary_quantity     := NULL;
        l_mtl_txn_lots_rec.product_transaction_id := l_rcv_txn_iface_rec.interface_transaction_id;
        l_mtl_txn_lots_rec.product_code           := 'RCV';
                        
        INSERT INTO mtl_transaction_lots_temp
        VALUES l_mtl_txn_lots_rec;       
      
    IF l_group_id IS NOT NULL THEN
    
      COMMIT; -- Must commit before call synchronous transaction
      timeout :=10000;-- fnd_profile.value('INV_RPC_TIMEOUT');
    
      IF (timeout IS NULL) THEN
        timeout := 300;
      END IF;
    
      rc := fnd_transaction.synchronous(timeout,
                                        outcome,
                                        message,
                                        'PO',
                                        'RCVTPO',
                                        'ONLINE',
                                        l_group_id,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL,
                                        NULL);

      IF (rc = 0 AND (outcome NOT IN ('WARNING', 'ERROR'))) THEN
        dbms_output.put_line('01');--NULL;
      ELSE
        dbms_output.put_line('011');--NULL;null;
       dbms_output.put_line(outcome||':'||message);
      END IF; --added by liangjie.yuan 20140328 end
      IF (rc = 0 AND (outcome NOT IN ('WARNING', 'ERROR'))) THEN
        dbms_output.put_line('02');--NULL;
       -- NULL;
      ELSIF (rc = 1) THEN
      
        dbms_output.put_line('1');


      ELSIF (rc = 2) THEN
      
        dbms_output.put_line('2');
      ELSIF (rc = 3 OR (outcome IN ('WARNING', 'ERROR'))) THEN
      
        rc    := fnd_transaction.get_values(r_val1,
                                            r_val2,
                                            r_val3,
                                            r_val4,
                                            r_val5,
                                            r_val6,
                                            r_val7,
                                            r_val8,
                                            r_val9,
                                            r_val10,
                                            r_val11,
                                            r_val12,
                                            r_val13,
                                            r_val14,
                                            r_val15,
                                            r_val16,
                                            r_val17,
                                            r_val18,
                                            r_val19,
                                            r_val20);
        x_str := r_val1;
      
        IF (r_val2 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val2;
        END IF;
        IF (r_val3 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val3;
        END IF;
        IF (r_val4 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val4;
        END IF;
        IF (r_val5 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val5;
        END IF;
        IF (r_val6 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val6;
        END IF;
        IF (r_val7 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val7;
        END IF;
        IF (r_val8 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val8;
        END IF;
        IF (r_val9 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val9;
        END IF;
        IF (r_val10 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val10;
        END IF;
        IF (r_val11 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val11;
        END IF;
        IF (r_val12 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val12;
        END IF;
        IF (r_val13 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val13;
        END IF;
        IF (r_val14 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val14;
        END IF;
        IF (r_val15 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val15;
        END IF;
        IF (r_val16 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val16;
        END IF;
        IF (r_val17 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val17;
        END IF;
        IF (r_val18 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val18;
        END IF;
        IF (r_val19 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val19;
        END IF;
        IF (r_val20 IS NOT NULL) THEN
          x_str := x_str || chr(10) || r_val20;
        END IF;

      END IF;
    
    END IF;
    dbms_output.put_line('x_str='||x_str);

 
  EXCEPTION

    WHEN OTHERS THEN
      dbms_output.put_line('others');
  END rcv_txn_process;
 
/*  
select * from po.rcv_headers_interface rhi
  where rhi.created_by = 8162
  and rhi.vendor_id = 326957;
 
delete from po.rcv_headers_interface rhi
  where rhi.created_by = 8162
  and rhi.vendor_id = 326957;
 
    delete from po.rcv_transactions_interface rti
  where rti.created_by = 8162
  and rti.vendor_id = 326957;
 
  commit;
 
 
  */
 
/*  
select * from po.rcv_transactions_interface rti
  where rti.created_by = 8162
  and rti.vendor_id = 326957;
 
  delete from po.rcv_transactions_interface rti
  where rti.created_by = 8162
  and rti.vendor_id = 326957;
  */
 
/*  select * from mtl_transaction_lots_temp mtt
  where mtt.created_by =8162;*/
 

你可能感兴趣的:(EBS采购订单接收)