1. 程式人生 > >VL01N銷售訂單揀配bapi

VL01N銷售訂單揀配bapi

  data:wa_items type bapidlvreftosalesorder,
       begin of temp_item occurs 0,
         item(2000),
       end   of temp_item,
       begin of it_item occurs 0,
         sequence,
         item(6type n,
       end   of it_item,
       wa_item like line of it_item,
       begin of item_list occurs 0,
         item(6
type n,
       end   of item_list,
       l_it_orderitem type standard table of bapidlvreftosalesorder with header line.

  data:lx_vbkok type vbkok,
       it_prott like table of prott with header line,
       it_vbpok like table of vbpok with header line.
*& 因過賬時,有行專案的限制,需要對過賬專案進行拆分,揀配的次數之間用'-'分割
*& 專案內用','

  refresh:temp_item.
  split item_divison at '-' into table temp_item.

  loop at temp_item.
    clear:it_item.
    it_item-sequence = sy-tabix.
    refresh:item_list.
    shift temp_item-item left deleting leading ''.
    split temp_item-item at ',' into table item_list.
    loop at item_list.
      it_item-item = item_list-item.
      collect
 it_item.
    endloop.

  endloop.
  sort it_item by sequence item.
  sort sales_order_items by ref_doc ref_item.
*& 按拆分的專案,進行建立交貨單
  loop at it_item.

    wa_item = it_item.
    at end of sequence.
      refresh:l_it_orderitem .
      loop at sales_order_items where ref_item <= wa_item-item.
        l_it_orderitem = sales_order_items.
        append l_it_orderitem.
        clear:l_it_orderitem.
        delete sales_order_items.
      endloop.

      call function 'BAPI_OUTB_DELIVERY_CREATE_SLS'
        exporting
          ship_point        = ship_point
          due_date          = due_date
          debug_flg         = debug_flg
        importing
          delivery          = delivery
          num_deliveries    = num_deliveries
        tables
          sales_order_items = l_it_orderitem
          serial_numbers    = serial_numbers
          extension_in      = extension_in
          deliveries        = deliveries
          created_items     = created_items
          extension_out     = extension_out
          return            = return.

      read table return with key type = 'E'.

      if sy-subrc ne 0.

        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            wait = 'X'.

        refresh:it_vbpok.
        clear:it_vbpok,lx_vbkok.
        loop at  l_it_orderitem.

          if sy-tabix = 1.
            lx_vbkok-vbeln_vl = delivery.
            lx_vbkok-vbtyp_vl = 'J' .
            lx_vbkok-vbeln = l_it_orderitem-ref_doc.
            lx_vbkok-wabuc = 'X'.
          endif.

          it_vbpok-vbeln_vl = delivery.
          read table created_items index sy-tabix.
          it_vbpok-posnr_vl = created_items-deliv_item.
          it_vbpok-vbeln = l_it_orderitem-ref_doc.
          it_vbpok-posnn = l_it_orderitem-ref_item.
*it_vbpok-matnr = fp_afpo-matnr.
*it_vbpok-charg = fp_afpo-charg.
*it_vbpok-werks = fp_afpo-dwerk.
          it_vbpok-taqui = 'X'.
*& 揀配數量
          it_vbpok-pikmg = l_it_orderitem-dlv_qty.
          append it_vbpok.

        endloop.
*&更改揀配數量,當不自動過帳時,需要更改引數如下,並且需要再提交一次
        call function 'WS_DELIVERY_UPDATE'
          exporting
            vbkok_wa                 = lx_vbkok
*&            synchron                 = 'X'
            commit                   = 'X'
            delivery                 = delivery
            update_picking           = 'X'