BAPI_PO_CREATE创建采购订单

 

*&---------------------------------------------------------------------*
*& Report  ZBAPI_PO_CREATE
*&
*&---------------------------------------------------------------------*
*&create by:   
*&create time:  2010-12-27
*&function:     create poes by bapi
*&---------------------------------------------------------------------*

REPORT  zbapi_po_create.


DATA: BEGIN OF gw_po,
*---->header
  doc_type  TYPE bapiekkoc-doc_type,   "订单类型NB
  co_code   TYPE bapiekkoc-co_code,    "公司代码
  purch_org TYPE bapiekkoc-purch_org,  "采购组织
  pur_group TYPE bapiekkoc-pur_group,  "采购组
  vendor    TYPE bapiekkoc-vendor,     "供应商
*---->item
  pur_mat   TYPE bapiekpoc-pur_mat,    "物料号
  disp_quan  TYPE bapiekpoc-disp_quan,   "订单数量
  net_price TYPE bapiekpoc-net_price,  "净价
  plant     TYPE bapiekpoc-plant,      "工厂

*---->schedules
 deliv_date TYPE bapieket-deliv_date,  "交货日期
 quantity   TYPE bapieket-quantity,    "已计划数量
 PO_ITEM    type bapieket-PO_ITEM,    "行项目
END OF gw_po.
DATA gt_po LIKE  gw_po occurs 0 with header line. .
DATA gt_po2 LIKE TABLE OF gw_po WITH HEADER LINE.

DATA gt_ekko LIKE TABLE OF bapiekkoc WITH HEADER LINE.
DATA gt_ekpo LIKE TABLE OF bapiekpoc WITH HEADER LINE.
DATA gt_eket LIKE TABLE OF bapieket  WITH HEADER LINE.
DATA gt_return LIKE TABLE OF bapireturn WITH HEADER LINE.


DATA po_outnuber TYPE bapiekkoc-po_number.


DATA : lv_cancel(1) TYPE c. 
*---->upload
CALL FUNCTION 'UPLOAD'
  EXPORTING
    filename                = 'D:\PO.txt'
    filetype                = 'DAT'
  IMPORTING
    cancel                  = lv_cancel
  TABLES
    data_tab                = gt_po
  EXCEPTIONS
    conversion_error        = 1
    invalid_table_width     = 2
    invalid_type            = 3
    no_batch                = 4
    unknown_error           = 5
    gui_refuse_filetransfer = 6
    OTHERS                  = 7.
IF lv_cancel EQ 'X'.
  LEAVE PROGRAM.
ENDIF.        .
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSEIF sy-subrc = 0.
  SORT gt_po BY doc_type co_code purch_org pur_group vendor  .

LOOP AT gt_po .
  move gt_po TO gw_po.

*---->item
    gt_ekpo-pur_mat   = gw_po-pur_mat.       "物料号
    gt_ekpo-disp_quan = gw_po-disp_quan.     "订单数量
    gt_ekpo-net_price = gw_po-net_price .    "净价
    gt_ekpo-plant     = gw_po-plant.         "工厂
    gt_ekpo-PO_ITEM = gw_po-PO_ITEM .        "行项目
    APPEND gt_ekpo.

*---->schedules
    gt_eket-deliv_date = gw_po-deliv_date .  "交货日期
    gt_eket-quantity = gw_po-quantity  .     "已计划数量
    gt_eket-PO_ITEM = gw_po-PO_ITEM .        "行项目
    APPEND gt_eket.

*    AT END OF doc_type ."订单类型
*    ENDAT.
*      AT END OF co_code ."公司代码
*      ENDAT.
*        AT END OF purch_org."采购组织
*        ENDAT.
*          AT END OF pur_group ."采购组
*          ENDAT.
            AT END OF vendor.   "供应商

*---->header
              gt_ekko-doc_type  = gw_po-doc_type.      "订单类型NB
              gt_ekko-co_code   = gw_po-co_code .      "公司代码
              gt_ekko-purch_org = gw_po-purch_org .    "采购组织
              gt_ekko-pur_group = gw_po-pur_group .    "采购组
              gt_ekko-vendor    = gw_po-vendor.        "供应商
            CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                 input  = gt_ekko-vendor
                IMPORTING
                 output = gt_ekko-vendor.


              APPEND gt_ekko.

              CALL FUNCTION 'BAPI_PO_CREATE'
                EXPORTING
                  po_header                        = gt_ekko
                  skip_items_with_error            = 'X'
               IMPORTING
                 purchaseorder                    = po_outnuber
               TABLES
                  po_items                         = gt_ekpo
                  po_item_schedules                = gt_eket
                  return                           = gt_return .

              REFRESH gt_ekpo.
              REFRESH gt_ekko.
              REFRESH gt_eket.
              clear gw_po.

            ENDAT.

      loop at gt_return."输出稍息

        write gt_return-message.
      endloop.
  ENDLOOP.

 

ENDIF.

你可能感兴趣的:(Date,function,report,header,table,input)