关于ME41创建询价单系统并没有准备标准的BAPI,这一点在note:2115337中有说明。
但是通过查阅相关资料找到一个BAPI:BS01_MM_QUOTATION_CREATE,可以为ME41进行创建,但是如果不做一些增强,会有一些额外的错误,比如创建出的单据数量为0,报错必须输入价格等。此外,该函数属于服务清单,是行业解决方案DIMP的一部分,只有在SFW5中激活DIMP才能正常使用,但是不建议仅针对要使用该函数而激活DIMP。
但是创建ME41没有比这个函数更合适的了,所以不激活DIMP的情况下,只需要做两个增强即可。
增强点1:
Main Program: SAPMM06E
Include: MM06EF0N_NEUE_POS_BESTELLUNG
Enhancement Spot: ES_SAPMM06E
Enhancement Point: MM06EF0N_NEUE_POS_BESTELLUN_05
增强点2:
Main Program: SAPMM06E
Include: MM06EF0E_EKPO-NETWR_MOD
Enhancement Spot: ES_MM06EF0E_EKPO_NETWR_MOD
Enhancement Point: MM06EF0E_EKPO_NETWR_MOD_01
BAPI调用参考代码:
*&---------------------------------------------------------------------*
*& Form FRM_BAPI_RFQ_MAINTAIN
*&---------------------------------------------------------------------*
*& Using BAPI to create RFQ
*&---------------------------------------------------------------------*
FORM frm_bapi_rfq_maintain USING us_head TYPE zprmmsrfq_head_in
ut_item TYPE zprmmtrfq_item_in
ut_item_text TYPE zprmmtcontract_item_text_in
CHANGING cs_resp TYPE zprbcsrest_out.
DATA:
ls_header TYPE bs01mmhead,
ls_address TYPE bapiaddress,
lt_items TYPE STANDARD TABLE OF bs01mmitem,
ls_items TYPE bs01mmitem,
lt_schdules TYPE STANDARD TABLE OF bs01mmschedule,
ls_schdules TYPE bs01mmschedule,
lt_text TYPE STANDARD TABLE OF bs01mmitemtx,
ls_text TYPE bs01mmitemtx,
lt_return TYPE STANDARD TABLE OF bapiret2.
DATA:
lv_ponumber TYPE ebeln.
DATA:
ls_addr_sel TYPE addr1_sel,
ls_addr_val TYPE addr1_val.
CONSTANTS:
lc_doc_type TYPE ebstyp VALUE 'A'.
**********************************************************************
* Head data
**********************************************************************
ls_header-doc_cat = lc_doc_type. "
ls_header-doc_type = us_head-bsart. "Purchasing Document Category
ls_header-created_on = sy-datum. "Purchasing Document Type
ls_header-created_by = sy-uname. "Create user
ls_header-vendor = us_head-lifnr. "Vendor
ls_header-purch_org = us_head-ekorg. "Purchasing organization
ls_header-pur_group = us_head-ekgrp. "Purchasing Group
ls_header-language = sy-langu. "Language Key
ls_header-doc_date = us_head-bedat. "Create Date
ls_header-quot_dead = us_head-angdt. "Deadline for Submission of Bid/Quotation
ls_header-currency = us_head-waers. "Currency
ls_header-mast_cond = abap_true. "Document with time-dependent conditions
**********************************************************************
* Address Data
**********************************************************************
SELECT SINGLE
adrnr
INTO ls_addr_sel-addrnumber
FROM lfa1
WHERE lifnr = ls_header-vendor.
CALL FUNCTION 'ADDR_GET'
EXPORTING
address_selection = ls_addr_sel
IMPORTING
address_value = ls_addr_val
EXCEPTIONS
parameter_error = 1
address_not_exist = 2
version_not_exist = 3
internal_error = 4
address_blocked = 5
OTHERS = 6.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
MOVE-CORRESPONDING ls_addr_val TO ls_address.
**********************************************************************
* Item Data
**********************************************************************
LOOP AT ut_item INTO DATA(us_item).
ls_items-doc_item = us_item-ebelp. "Item Number
ls_items-pur_mat = us_item-matnr. "Material Number
ls_items-plant = us_item-werks. "Plant
ls_items-store_loc = us_item-lgort. "Storage location
ls_items-unit = us_item-meins. "Unit
APPEND ls_items TO lt_items.
ls_schdules-doc_item = us_item-ebelp. "Item Number
ls_schdules-serial_no = 1. "Delivery Schedule Line Counter
ls_schdules-deliv_date = us_item-eindt. "Item delivery date
ls_schdules-quantity = us_item-ktmng. "Scheduled Quantity
APPEND ls_schdules TO lt_schdules.
LOOP AT ut_item_text INTO DATA(us_item_text) WHERE item_no = us_item-ebelp.
ls_text-doc_item = us_item_text-item_no. "Item Number
ls_text-text_id = us_item_text-text_id. "Text Id
ls_text-text_line = us_item_text-text_line. "Text Value
APPEND ls_text TO lt_text.
CLEAR ls_text.
ENDLOOP.
CLEAR:
ls_items,
ls_schdules.
ENDLOOP.
*--------------------------------------------------------------------*
* Note: This BAPI is not designed to create RFQ functions. If you need
* to use this function to create MM RFQ documents, you need to implement
* the following enhancements:
* ①
* Program: MM06EF0N_NEUE_POS_BESTELLUNG
* Enhancement:ENHANCEMENT-POINT MM06EF0N_NEUE_POS_BESTELLUN_05 SPOTS ES_SAPMM06E.
* Code: EKPO-REPOS = ''.(Should be only use for create RFQ)
*
* ②
* Program: MM06EF0E_EKPO-NETWR_MOD
* Enhancement:ENHANCEMENT-POINT MM06EF0E_EKPO_NETWR_MOD_01 SPOTS ES_MM06EF0E_EKPO_NETWR_MOD INCLUDE BOUND.
* Code: RM06E-ANMNG = EKPO-MENGE.(Should be only use for create RFQ)
*--------------------------------------------------------------------*
* Create RFQ
CALL FUNCTION 'BS01_MM_QUOTATION_CREATE'
EXPORTING
quotation_header = ls_header
quotation_address = ls_address
skip_items_with_error = ''
IMPORTING
quotation = lv_ponumber
TABLES
quotation_items = lt_items
quotation_item_schedules = lt_schdules
quotation_item_text = lt_text
return = lt_return.
LOOP AT lt_return INTO DATA(ls_return)
WHERE type CA gc_err_ty.
cs_resp-msgty = gc_msgty_e.
CONCATENATE cs_resp-msgtx ls_return-message INTO cs_resp-msgtx.
ENDLOOP.
IF lv_ponumber IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
cs_resp-msgty = gc_msgty_s.
* & created under the number &
MESSAGE s017(06) WITH sy-msgv1 sy-msgv2 INTO cs_resp-msgtx.
cs_resp-sapnum = lv_ponumber.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDFORM.
以上。