实例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 0 with header line.
DATA: ORDER_ITEMS_IN1 type BAPISDITM occurs 0 with header line.
DATA: ORDER_ITEMS_IN1X type BAPISDITMX occurs 0 with header line.
DATA: ORDER_SCHEDULES_IN1 type BAPISCHDL occurs 0 with header line.
DATA: ORDER_SCHEDULES_IN1X type BAPISCHDLX occurs 0 with header line.
DATA : RETURN1 TYPE BAPIRET2 OCCURS 0 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 = 'TA'.
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 0 WITH HEADER LINE.
DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0 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.
* 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.
分享到:
相关推荐
在本案例中,我们需要利用BAPI_SALESORDER_CHANGE来修改销售订单(Sales Order,简称SO)的抬头增强字段。这个需求在实际项目中常见,因为企业往往需要自定义一些标准字段来满足特定的业务需求。 首先,我们要了解...
BAPI_SALESORDER_CREATEFROMDAT2是SAP系统中创建销售订单的API接口,通过调用这个接口,可以快速创建销售订单。 在创建销售订单时,需要设置订单的头信息、项目信息、伙伴信息和计划信息等。头信息包括订单类型、...
ABPA 销售订单创建BAPI批导程序的源码,有详细的检查和美观的界面。主要用两个BAPI:BAPI_SALESORDER_CREATEFROMDAT2和SD_SALESDOCUMENT_CREATE
### BAPI_NETWORK_COMP_CHANGE:修改项目网络组件的BAPI #### 概述 在SAP系统中,项目管理(Project Management, PM)是用于管理和控制工程项目的重要工具之一。项目网络则是PM模块中用来规划和控制项目活动的关键...
下面,我们将深入探讨这一主题,涵盖创建结构、实现BADI增强以及使用BAPI参数表EXTENSION2的具体步骤,以确保能够成功地导入并处理所有必要的财务数据。 ### 一、创建结构 为了在BAPI_ACC_DOCUMENT_POST中扩展字段...
### 使用BAPI_PO_CHANGE修改(ME23N)采购订单(PO)出货日期的方法 在SAP系统中,采购订单(Purchase Order, PO)管理是供应链管理中的一个关键环节,涉及采购请求、供应商选择、合同谈判等多个流程。在实际业务操作...
在销售订单管理中,BAPI_SALESORDER_CREATEFROMDAT2是一个非常重要的接口,用于创建新的销售订单。本文将详细介绍如何使用BAPI_SALESORDER_CREATEFROMDAT2接口创建销售订单,并提供相应的ABAP代码示例。 BAPI_SALES...
11. BAPI_SALESORDER_CREATEFROMDAT 该BAPI用于基于提供的数据创建销售订单。 12. BAPI_SALESORDER_CHANGE/MB_CANCEL_GOODS_MOVEMENT/BAPI_SALESORDER_CHANGEMB_CANCEL_GOODS_MOVEMENT 这些BAPI分别用于更改销售...
为了解决这个问题,可以使用BAPI_ACC_DOCUMENT_POST中的EXTENSION2传入值来实现。下面是实现的步骤和代码。 首先,需要创建一个BADI增强,事物代码SE19,创建一个实现过程点击创建输入自己的执行过程ztest_acc_...
### BAPI_NETWORK_MAINTAIN:下达项目网络的BAPI #### 概述 在SAP系统中,**BAPI_NETWORK_MAINTAIN** 是一个用于维护和管理项目网络的业务应用程序接口(Business Application Programming Interface,简称BAPI)...
### BAPI-ACC-DOCUMENT-POST 结构字段扩展 #### 概述 在SAP系统中,`BAPI_ACC_DOCUMENT_POST` 是一个重要的业务应用程序接口(BAPI),用于执行财务凭证的过账处理。但在实际应用过程中,可能会遇到现有BAPI无法...
通过JCo接口利用BAPI函数创建PO订单
BAPI 批量创建工艺路线解决方案 在本文中,我们将详细介绍如何使用 BAPI 批量创建工艺路线的解决方案。该解决方案是围绕 BAPI_ROUTING_CREATE 函数的使用,旨在解决 BAPI_ROUTING_CREATE 不可以创建定额工艺路线的...
ERP课件关于采购管理方面的只是内容,详细概述了采购的整个流程
本文将详细介绍如何使用BAPI_TRANSACTION_COMMIT创建及修改物料主数据,包括物料主数据的创建和修改、物料描述的设置、客户端层次物料数据的设置、物料类型的设置等。 物料主数据的创建 在SAP系统中,物料主数据是...
在SAP系统中,BAPI(Business Application Programming Interface)是一种预定义的函数模块,用于在不同组件之间进行集成和自动化业务流程。本示例中的"实用BAPI做内部调拨"是指使用BAPI_GOODSMVT_CREATE来执行物料...
LSMW_BAPI_MM02_CS01
三、委外PO的收货(这里使用BAPI_GOODSMVT_CREATE) *&---------------------------------------------------------------------* *& Report ZTEST_WWJG *& *&---------------------------------------------------...
采购订单BAPI增强数值型字段转换方法 在采购订单系统中,使用BAPI(Business Application Programming Interface)可以实现采购订单的自动化创建和更新。然而,在使用BAPI时,需要注意数值型字段的转换问题。数值型...
- `BAPI_SALESORDER_CREATEFROMDAT2` - `BAPI_SALESORDER_CHANGE` - `BAPI_INQUIRY_CREATEFROMDATA2` - `BAPI_CUSTOMERINQUIRY_CHANGE` - `BAPI_QUOTATION_CREATEFROMDATA2` - `BAPI_CUSTOMERQUOTATION_CHANGE` - `...