用'BAPI_QUOTATION_CREATEFROMDATA2'导入客户报价数据时,订单数量为0。
后来参考了Jack Wu的Block ( http://blog.csdn.net/CompassButton/archive/2007/05/09/1601691.aspx )
现在搞定,具体的代码如下:
*&---------------------------------------------------------------------*
*& Report ZSD_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsd_test.
DATA:
header LIKE bapisdhd1,
* headerx LIKE bapisdhd1x,
g_vbeln LIKE vbak-vbeln,
it_retmsg LIKE TABLE OF bapiret2 WITH HEADER LINE,
it_item LIKE TABLE OF bapisditm WITH HEADER LINE,
* it_itemx LIKE TABLE OF bapisditmx WITH HEADER LINE,
it_partners LIKE TABLE OF bapiparnr WITH HEADER LINE,
it_sch LIKE TABLE OF bapischdl WITH HEADER LINE,
it_condition LIKE TABLE OF bapicond WITH HEADER LINE.
*headerx-updateflag = 'I'.
*headerx-doc_type = 'X'.
*headerx-sales_org = 'X'.
*headerx-distr_chan = 'X'.
*headerx-division = 'X'.
*headerx-req_date_h = 'X'.
*headerx-qt_valid_f = 'X'.
*headerx-qt_valid_t = 'X'.
header-doc_type = 'ZQTC'.
header-sales_org = '1060'.
header-distr_chan = 'ET'.
header-division = '60'.
header-req_date_h = sy-datum + 2. "请求交货日期
header-qt_valid_f = sy-datum. "报价/询价有效从
header-qt_valid_t = '99991231'. "投标/报价截止的日期(有效日)
it_partners-partn_role = 'AG'.
it_partners-partn_numb = '0000000086'."售达方
APPEND it_partners.
it_partners-partn_role = 'WE'.
it_partners-partn_numb = '0000000086'."售达方
APPEND it_partners.
*& 初始化项目
*it_itemx-updateflag = 'I'.
*it_itemx-itm_number = '000010'.
*it_itemx-material = 'X'.
*it_itemx-plant = 'X'.
*it_itemx-target_qty = 'X'.
*it_itemx-target_qu = 'X'.
*it_itemx-salqtynum = 'X'.
*it_itemx-salqtyden = 'X'.
*APPEND it_itemx.
it_item-itm_number = '000010'.
it_item-material = '12303700370000000D'.
it_item-plant = '1000'.
*it_item-target_qty = '1100'. "这个数量可以不要传递
*it_item-target_qu = 'PCS'.
*it_item-salqtynum = '1'.
*it_item-salqtyden = '1'.
*& 计划行数量
it_sch-itm_number = '000010'.
*it_sch-req_date = sy-datum.
*it_sch-dlv_date = sy-datum.
it_sch-req_qty = '11000'. "数量 这个数量一定要有,否则报价单上的"订单数量"为0
APPEND it_sch. "这里的Append的顺序不知是否有影响,原来APPEND it_item.是在 it_item后就新增了
APPEND it_item.
**& 抬头的条件价格
**it_condition-currency = 'HKD'.
**it_condition-cond_type = 'ZP00'.
**it_condition-cond_value = '12'.
**APPEND it_condition.
*
**&项目的金额,一定要加上货币,否则会乘以10倍
*it_condition-itm_number = '000010'.
*it_condition-cond_type = 'ZP00'.
*it_condition-roundoffdi = '1.000'.
*it_condition-currency = 'HKD'.
*APPEND it_condition.
**it_condition-itm_number = '000020'.
**it_condition-cond_type = 'ZP00'.
**it_condition-roundoffdi = '22.000'.
**it_condition-currency = 'CNY'.
**APPEND it_condition.
CALL FUNCTION 'BAPI_QUOTATION_CREATEFROMDATA2'
EXPORTING
quotation_header_in = header
* quotation_header_inx = headerx
testrun = ' '
IMPORTING
salesdocument = g_vbeln
TABLES
return = it_retmsg
quotation_items_in = it_item
* quotation_items_inx = it_itemx
quotation_partners = it_partners
quotation_schedules_in = it_sch "这里一定要传递,否则订单数量为0,其他都正常。因为订单数量是计划行数量的汇总
* quotation_conditions_in = it_condition
.
IF sy-subrc = 0.
READ TABLE it_retmsg WITH KEY type = 'E'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
WRITE: 'sale order document:',g_vbeln.
*取意向订单对应的状态对象编号
DATA:g_objnr LIKE vbak-objnr.
SELECT SINGLE objnr INTO g_objnr
FROM vbak
WHERE vbeln = g_vbeln.
* IF sy-subrc = 0.
*
* CALL FUNCTION 'STATUS_CHANGE_EXTERN'
* EXPORTING
* objnr = g_objnr
* user_status = 'E0004'.
* ENDIF.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
ENDIF.
ENDIF.