登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

原来为了你

我的人生就是要一次次的超越

 
 
 

日志

 
 
 
 

BAPI_SALESORDER_CREATEFROMDAT2 创建订单 va01  

2011-04-19 10:43:09|  分类: BAPI |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

 
实例1:带订单参考创建
report  z_order_create_spa_hbr.


*----------------------------------------------------------------------*
* Parameters
*----------------------------------------------------------------------*

parameters: p_order like vbak-vbeln.
parameters: p_quote like bapivbeln-vbeln.
parameters: p_new   like bapivbeln-vbeln.
*
* We need to create a new order number P_New from an existing order P_order
* linked to an existing quotation P_quote
*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*
tables: vbak,
        vbap,
        vbkd. "Sales Document: Business Data

*----------------------------------------------------------------------*
* Data and internal table
*----------------------------------------------------------------------*

data:  order_header_in1       like bapisdhd1.                             "订单抬头
data:  order_header_intx      like bapisdhd1x.                            "订单抬头控制字段
data:  salesdocument1         type bapivbeln-vbeln.                       "订单号
data:  return2                type bapiret2.
data:  order_partners1        type bapiparnr  occurs with header line.
data:  order_items_in1        type bapisditm  occurs with header line.
data:  order_items_in1x       type bapisditmx occurs with header line.
data:  order_schedules_in1    type bapischdl  occurs with header line.
data:  order_schedules_in1x   type bapischdlx occurs with header line.
data:  return1                type bapiret2   occurs with header line.

start-of-selection.

  select single from vbak where vbeln = p_quote.

  if not sy-subrc = 0.
    write:/ text-e02.
    exit.
  endif.

  select single from vbak where vbeln = p_order.

  if not sy-subrc = 0.
    write:/ text-e01.
    exit.
  endif.

  select single from vbkd where vbeln = p_order.

  if not sy-subrc = 0.
    write:/ text-e03.
    exit.
  endif.

  order_header_in1-doc_type   = 'ZOR'.                    "销售订单类型
  order_header_in1-sales_org  =  vbak-vkorg.              "销售组织
  order_header_in1-distr_chan =  vbak-vtweg.              "分销渠道
  order_header_in1-division   =  vbak-spart.              "产品组
  order_header_in1-req_date_h =  sy-datum + 20.           "请求交货日期
  order_header_in1-purch_no_c = 'HBR_Commande'.
  order_header_in1-ref_1      = 'E-DISTR'.
  order_header_in1-sd_doc_cat = 'C'.                      "凭证类别
  order_header_in1-ref_doc    =  p_quote.
  order_header_in1-ref_doc_l  =  p_quote.
  order_header_in1-refdoc_cat = 'B'.                      "前续凭证类别
  order_header_in1-incoterms1 = vbkd-inco1.
  order_header_in1-incoterms2 = vbkd-inco2.
  order_header_in1-pmnttrms   = vbkd-zterm.
  order_header_in1-sales_off  = vbak-vkbur.               "销售部门

  select from vbap where vbeln = vbak-vbeln.
    clear order_items_in1.
    order_items_in1-po_itm_no        = vbap-posnr.
    order_items_in1-material         = vbap-matnr.
    order_items_in1-target_qu        = vbap-zieme.
    order_items_in1-ref_doc          = p_quote.
    order_items_in1-ref_doc_it       = vbap-posnr.
    order_items_in1-ref_doc_ca       = 'B'.
    append order_items_in1.
*
    clear order_schedules_in1.
    order_schedules_in1-itm_number   = vbap-posnr.
    order_schedules_in1-req_date     = sy-datum + 20.
    order_schedules_in1-req_qty      = vbap-kwmeng.
    append order_schedules_in1.
*
  endselect.

  order_partners1-partn_role         = 'WE'.
  order_partners1-partn_numb         = vbak-kunnr.
  append order_partners1.

  order_partners1-partn_role         = 'AG'.
  append order_partners1.


  perform call_function.

*&---------------------------------------------------------------------*
*& Form call_function
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form call_function .


  call function 'BAPI_SALESORDER_CREATEFROMDAT2'
    exporting
    salesdocumentin               = p_new
    order_header_in               = order_header_in1
*   ORDER_HEADER_INX              = order_header_intX
*   SENDER                        =
*   BINARY_RELATIONSHIPTYPE       =
*   INT_NUMBER_ASSIGNMENT         =
*   BEHAVE_WHEN_ERROR             =
*   LOGIC_SWITCH                  =
*   TESTRUN                       =
*   CONVERT                       = ' '
  importing
    salesdocument                 = salesdocument1
  tables
    return                        = return1
    order_items_in                = order_items_in1
*   ORDER_ITEMS_INX               = ORDER_ITEMS_IN1X
    order_partners                = order_partners1
    order_schedules_in            = order_schedules_in1
*   ORDER_SCHEDULES_INX           = ORDER_SCHEDULES_IN1X
*   ORDER_CONDITIONS_IN           =
*   ORDER_CONDITIONS_INX          =
*   ORDER_CFGS_REF                =
*   ORDER_CFGS_INST               =
*   ORDER_CFGS_PART_OF            =
*   ORDER_CFGS_VALUE              =
*   ORDER_CFGS_BLOB               =
*   ORDER_CFGS_VK                 =
*   ORDER_CFGS_REFINST            =
*   ORDER_CCARD                   =
*   ORDER_TEXT                    =
*   ORDER_KEYS                    =
*   EXTENSIONIN                   =
*   PARTNERADDRESSES              =
            .

*

  if not salesdocument1 is initial.
    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait   'X'
      importing
        return = return2.
  else.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
  endif.
endform.                    "call_function


实例2: 不带订单参考创建
report z_bapi_salesorder_create.

* Parameters
* Sales document type
selection-screen begin of line.
selection-screen comment 2(20) v_text for field p_auart.
parameters: p_auart type auart obligatory.
selection-screen end of line.

* Sales organization
selection-screen begin of line.
selection-screen comment 2(20) v_text1 for field p_vkorg.
parameters: p_vkorg type vkorg obligatory.
selection-screen end of line.

* Distribution channel
selection-screen begin of line.
selection-screen comment 2(20) v_text2 for field p_vtweg.
parameters: p_vtweg type vtweg obligatory.
selection-screen end of line.

* Division.
selection-screen begin of line.
selection-screen comment 2(20) v_text3 for field p_spart.
parameters: p_spart type spart obligatory.
selection-screen end of line.

skip 1.

* Sold-to
selection-screen begin of line.
selection-screen comment 2(20) v_text4 for field p_sold.
parameters: p_sold  type kunnr obligatory.
selection-screen end of line.

* Ship-to
selection-screen begin of line.
selection-screen comment 2(20) v_text5 for field p_ship.
parameters: p_ship  type kunnr obligatory.
selection-screen end of line.

skip 1.

* Material
selection-screen begin of line.
selection-screen comment 2(20) v_text6 for field p_matnr.
parameters: p_matnr type matnr   obligatory.
selection-screen end of line.

* Quantity.
selection-screen begin of line.
selection-screen comment 2(20) v_text7 for field p_menge.
parameters: p_menge type kwmeng  obligatory.
selection-screen end of line.

* Plant
selection-screen begin of line.
selection-screen comment 2(20) v_text9 for field p_plant.
parameters: p_plant type werks_d obligatory.
selection-screen end of line.

* Data declarations.
data: v_vbeln            like vbak-vbeln.
data: header             like bapisdhead1.
data: headerx            like bapisdhead1x.
data: item               like bapisditem  occurs with header line.
data: itemx              like bapisditemx occurs with header line.
data: partner            like bapipartnr  occurs with header line.
data: return             like bapiret2    occurs with header line.
data: lt_schedules_inx   type standard table of bapischdlx
                         with header line.
data: lt_schedules_in    type standard table of bapischdl
                         with header line.

* Initialization.
initialization.
  v_text   = 'Order type'.
  v_text1  = 'Sales Org'.
  v_text2  = 'Distribution channel'.
  v_text3  = 'Division'.
  v_text4  = 'Sold-to'.
  v_text5  = 'Ship-to'.
  v_text6  = 'Material'.
  v_text7  = 'Quantity'.
  v_text9  = 'Plant'.

* Start-of-selection.
start-of-selection.

* Header data

* Sales document type
  header-doc_type = p_auart.
  headerx-doc_type = 'X'.

* Sales organization
  header-sales_org = p_vkorg.
  headerx-sales_org = 'X'.

* Distribution channel
  header-distr_chan  = p_vtweg.
  headerx-distr_chan = 'X'.

* Division
  header-division = p_spart.
  headerx-division = 'X'.

  headerx-updateflag = 'I'.

* Partner data
* Sold to
  partner-partn_role = 'AG'.
  partner-partn_numb = p_sold.
  append partner.

* Ship to
  partner-partn_role = 'WE'.
  partner-partn_numb = p_ship.
  append partner.

*---ITEM DATA
  itemx-updateflag = 'I'.

* Line item number.
  item-itm_number = '000010'.
  itemx-itm_number = 'X'.

* Material
  item-material = p_matnr.
  itemx-material = 'X'.

* Plant
  item-plant    = p_plant.
  itemx-plant   = 'X'.

* Quantity
  item-target_qty = p_menge.
  itemx-target_qty = 'X'.

  append item.
  append itemx.

*   Fill schedule lines   这个参数不能少吧?
  lt_schedules_in-itm_number = '000010'.
  lt_schedules_in-sched_line = '0001'.
  lt_schedules_in-req_qty    = p_menge.
  append lt_schedules_in.

*   Fill schedule line flags
  lt_schedules_inx-itm_number  = '000010'.
  lt_schedules_inx-sched_line  = '0001'.
  lt_schedules_inx-updateflag  = 'X'.
  lt_schedules_inx-req_qty     = 'X'.
  append lt_schedules_inx.

或当多行数据时:

  *---Item data
  datal_pornr type vbap-posnr value '000000'.
  datal_etenr type vbep-etenr value '0000'.
  loop at t_import_01.
    l_pornr l_pornr + 10.
    l_etenr l_etenr + 1.

    itemx-updateflag 'I'.

* Line item number.
    item-itm_number l_pornr.
    itemx-itm_number 'X'.

* Material
    item-material t_import_01-matnr.
    itemx-material 'X'.

* Quantity
    item-target_qty t_import_01-kwmeng.
    itemx-target_qty 'X'.

*   Fill schedule lines
    lt_schedules_in-itm_number l_pornr.
    lt_schedules_in-sched_line l_etenr.
    lt_schedules_in-req_qty    t_import_01-kwmeng.
    append lt_schedules_in.

*   Fill schedule line flags
    lt_schedules_inx-itm_number  l_pornr.
    lt_schedules_inx-sched_line  l_etenr.
    lt_schedules_inx-updateflag  'X'.
    lt_schedules_inx-req_qty     'X'.
    append lt_schedules_inx.

    append item.
    append itemx.
  endloop.


* Call the BAPI to create the sales order.
  call function 'BAPI_SALESDOCU_CREATEFROMDATA1'
    exporting
      sales_header_in     = header
      sales_header_inx    = headerx
    importing
      salesdocument_ex    = v_vbeln
    tables
      return              return
      sales_items_in      = item
      sales_items_inx     = itemx
      sales_schedules_in  = lt_schedules_in
      sales_schedules_inx = lt_schedules_inx
      sales_partners      = partner.

* Check the return table.
  loop at return where type 'E' or type 'A'.
    exit.
  endloop.

  if sy-subrc = 0.

    write: / 'Error in creating document'.

  else.

* Commit the work.
    commit work and wait.

    write: / 'Document ', v_vbeln, ' created'.

  endif.

  评论这张
 
阅读(1586)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018