创建销售订单的RFC
串讲
SPAN {
font-family: “Courier New”;
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}
FUNCTION ZBAPI_ZOR3.
*"----------------------------------------------------------------------
"“本地接口:
*” TABLES
*" TAB_VBAK STRUCTURE ZBAPI_VBAK
*"----------------------------------------------------------------------
DATA:wa_vbak TYPE zbapi_vbak.
DATA:tab_vbak_temp TYPE TABLE OF zbapi_vbak,
wa_vbak_temp TYPE zbapi_vbak.
DATA:tab_return TYPE TABLE OF zbapi_vbak WITH HEADER LINE.
CHECK tab_vbak[] IS NOT INITIAL.
"返回数据
DATA lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
"存放抬头数据
DATA : ls_order_header_in LIKE bapisdhd1.
DATA : ls_order_header_inx LIKE bapisdhd1x.
DATA : ls_logic_switch LIKE bapisdls.
"存放明细数据
DATA : lt_order_items_in LIKE bapisditm OCCURS 0.
DATA : ls_order_items_in TYPE bapisditm.
DATA : lt_order_items_inx LIKE bapisditmx OCCURS 0.
DATA : ls_order_items_inx TYPE bapisditmx.
"合作伙伴(用于存储售达方等信息)
DATA : lt_order_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE.
"定价
DATA lt_order_conditions_in TYPE bapicond OCCURS 0 WITH HEADER LINE.
DATA lt_order_conditions_inx TYPE bapicondx OCCURS 0 WITH HEADER LINE.
"维护 SD 凭证计划行的通讯字段
DATA: lt_order_schedules_in TYPE TABLE OF bapischdl WITH HEADER LINE.
DATA: lt_order_schedules_inx TYPE TABLE OF bapischdlx WITH HEADER LINE .
DATA:lt_sales_text LIKE bapisdtext OCCURS 0 WITH HEADER LINE.
DATA:lt_text LIKE swastrtab OCCURS 0 WITH HEADER LINE.
"增强字段
DATA lt_extensionin TYPE TABLE OF bapiparex.
DATA ls_extensionin TYPE bapiparex.
DATA ls_bape_vbap TYPE bape_vbap.
DATA ls_bape_vbapx TYPE bape_vbapx.
DATA bape_vbak TYPE bape_vbak.
DATA bape_vbakx TYPE bape_vbakx.
DATA:lv_text960(960) TYPE c.
DATA:lv_vbeln TYPE vbeln_va,
lv_msgtx TYPE msgtx,
lv_flag,
lv_change,
l_zterm TYPE knb1-zterm.
DATA:l_string_temp TYPE string,
l_string TYPE string.
DATA:lt_tvak TYPE TABLE OF tvak WITH HEADER LINE,
lt_t683v TYPE TABLE OF t683v WITH HEADER LINE,
lt_knvv TYPE TABLE OF knvv WITH HEADER LINE,
lt_t683s TYPE TABLE OF t683s WITH HEADER LINE.
DATA:lv_kalks TYPE kalks,
lv_kartv TYPE kartv,
lv_kalsm TYPE kalsm,
lv_kschl TYPE kschl.
DATA:lv_stunr TYPE t683s-stunr,
lv_zaehk TYPE t683s-zaehk.
DATA:lv_ps_psp_pnr TYPE ps_posnr,
lv_prctr TYPE prctr.
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_tvak
FROM tvak.
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_t683v
FROM t683v.
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_t683s
FROM t683s.
IF tab_vbak[] IS NOT INITIAL.
SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_knvv
FROM knvv FOR ALL ENTRIES IN tab_vbak
WHERE kunnr = tab_vbak-kunnr.
ENDIF.
DATA:lv_memory_flag.
LOOP AT tab_vbak ASSIGNING FIELD-SYMBOL(<fs_vbak>).
wa_vbak = <fs_vbak>.
MOVE-CORRESPONDING wa_vbak TO wa_vbak_temp.
APPEND wa_vbak_temp TO tab_vbak_temp.
AT END OF vbeln.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_vbak-kunnr
IMPORTING
output = wa_vbak-kunnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_vbak-kunag
IMPORTING
output = wa_vbak-kunag.
SELECT SINGLE zterm INTO l_zterm FROM knvv
WHERE kunnr = wa_vbak-kunnr AND
vkorg = wa_vbak-vkorg AND
vtweg = wa_vbak-vtweg AND
spart = wa_vbak-spart.
ls_order_header_in-purch_no_c = wa_vbak-bstkd. "采购订单
ls_order_header_in-doc_type = 'ZOR3'. "wa_vbak-auart订单类型
ls_order_header_in-sales_org = '3500'. "wa_vbak-vkorg销售组织
ls_order_header_in-distr_chan = '90' . "wa_vbak-vtweg分销渠道
ls_order_header_in-division = '40'. "wa_vbak-spart产品组
ls_order_header_in-purch_date = sy-datum. "日期wa_vbak-bstdk
ls_order_header_in-pmnttrms = l_zterm.
ls_order_header_inx-doc_type = 'X'. "订单类型
ls_order_header_inx-sales_org = 'X'. "销售组织
ls_order_header_inx-distr_chan = 'X'. "分销渠道
ls_order_header_inx-division = 'X'. "产品组
ls_order_header_inx-purch_date = 'X'. "日期
ls_order_header_inx-pmnttrms = 'X'.
ls_order_header_inx-purch_no_c = 'X'.
"售达方
CLEAR lt_order_partners.
lt_order_partners-partn_role = 'AG'.
lt_order_partners-partn_numb = wa_vbak-kunnr.
APPEND lt_order_partners.
"送达方
CLEAR lt_order_partners.
lt_order_partners-partn_role = 'WE'.
lt_order_partners-partn_numb = wa_vbak-kunag.
APPEND lt_order_partners.
"收票方
CLEAR lt_order_partners.
lt_order_partners-partn_role = 'RE'.
lt_order_partners-partn_numb = wa_vbak-kunag.
APPEND lt_order_partners.
"付款方
CLEAR lt_order_partners.
lt_order_partners-partn_role = 'RG'.
lt_order_partners-partn_numb = wa_vbak-kunag.
APPEND lt_order_partners.
"pft 20191205 maggie 销售员
"CLEAR lt_order_partners.
"lt_order_partners-partn_role = 'ZA'.
"lt_order_partners-partn_numb = wa_vbak-partner.
" APPEND lt_order_partners.
-
IF wa_vbak-zremark3 IS NOT INITIAL.
-
lt_sales_text-text_id = '0004'.
-
lt_sales_text-langu = sy-langu.
-
lt_sales_text-text_line = wa_vbak-zremark3.
-
APPEND lt_sales_text.
-
CLEAR lt_sales_text.
-
ENDIF. "行项目数据 LOOP AT tab_vbak_temp INTO wa_vbak_temp. CLEAR ls_order_items_in. ls_order_items_in-itm_number = wa_vbak_temp-posnr."订单行号 ls_order_items_in-material = wa_vbak_temp-matnr."物料号 ls_order_items_in-target_qty = wa_vbak_temp-kwmeng."订单数量 ls_order_items_in-plant = '3500'."wa_vbak_temp-werks. ls_order_items_in-store_loc = '3201'."wa_vbak_temp-lgort. APPEND ls_order_items_in TO lt_order_items_in. CLEAR ls_order_items_inx. ls_order_items_inx-itm_number = wa_vbak_temp-posnr."订单行号 ls_order_items_inx-updateflag = 'I'. ls_order_items_inx-material = 'X'."物料号 ls_order_items_inx-target_qty = 'X'."订单数量 ls_order_items_inx-plant = 'X'. ls_order_items_inx-store_loc = 'X'. APPEND ls_order_items_inx TO lt_order_items_inx. CLEAR lt_order_schedules_in. lt_order_schedules_in-itm_number = wa_vbak_temp-posnr."订单行号 lt_order_schedules_in-sched_line = '0001'. lt_order_schedules_in-req_qty = wa_vbak_temp-kwmeng."订单数量 lt_order_schedules_in-req_date = sy-datum."wa_vbak_temp-etdat."订单数量 lt_order_schedules_in-date_type = '1'. APPEND lt_order_schedules_in. CLEAR:lt_order_schedules_inx. lt_order_schedules_inx-itm_number = wa_vbak_temp-posnr."订单行号 lt_order_schedules_inx-sched_line = '0001'. lt_order_schedules_inx-req_qty = 'X'."订单数量 lt_order_schedules_inx-date_type = 'X'. APPEND lt_order_schedules_inx.
-
"取定价过程
-
CLEAR:lt_t683v,lt_tvak,lt_knvv,lv_kalks,lv_kartv,lv_kalsm,lv_kschl,lv_stunr,lv_zaehk.
-
READ TABLE lt_knvv WITH KEY kunnr = wa_vbak-kunnr.
-
IF sy-subrc EQ 0.
-
lv_kalks = lt_knvv-kalks.
-
ENDIF.
-
READ TABLE lt_tvak WITH KEY auart = wa_vbak-auart.
-
IF sy-subrc EQ 0.
-
READ TABLE lt_t683v WITH KEY vkorg = wa_vbak-vkorg
-
vtweg = wa_vbak-vtweg
-
spart = wa_vbak-spart
-
kalvg = lt_tvak-kalvg
-
kalks = lv_kalks.
-
IF sy-subrc EQ 0.
-
lv_kalsm = lt_t683v-kalsm.
-
IF lv_kartv IS INITIAL .
-
READ TABLE lt_t683s WITH KEY kalsm = lv_kalsm kvewe = 'A' kappl = 'V' kobli = 'X'.
-
IF sy-subrc EQ 0.
-
lv_kschl = lt_t683s-kschl.
-
lv_stunr = lt_t683s-stunr.
-
lv_zaehk = lt_t683s-zaehk.
-
ENDIF.
-
ENDIF.
-
ENDIF.
-
ENDIF.
-
CLEAR lt_order_conditions_in.
-
lt_order_conditions_in-itm_number = wa_vbak_temp-posnr. "行项目号
-
lt_order_conditions_in-cond_type = lv_kschl ."lt_t683s-kschl.""wa_vbak_temp-kschl."定价条件
-
lt_order_conditions_in-cond_value = wa_vbak_temp-kbetr."金额
-
lt_order_conditions_in-currency = wa_vbak_temp-waerk."货币码
-
APPEND lt_order_conditions_in.
-
CLEAR lt_order_conditions_inx.
-
lt_order_conditions_inx-itm_number = wa_vbak_temp-posnr. "行项目号
-
lt_order_conditions_inx-cond_type = lv_kschl ."lt_t683s-kschl."'ZNET'."定价条件
-
lt_order_conditions_inx-updateflag = 'U'."I = insert U = modify
-
lt_order_conditions_inx-cond_value = 'X'.
-
lt_order_conditions_inx-currency = 'X'.
-
APPEND lt_order_conditions_inx.
-
IF wa_vbak_temp-itemtext IS NOT INITIAL.
-
lt_sales_text-itm_number = wa_vbak_temp-posnr.
-
lt_sales_text-text_id = '0001'.
-
lt_sales_text-langu = sy-langu.
-
lt_sales_text-text_line = wa_vbak_temp-itemtext.
-
APPEND lt_sales_text.
-
CLEAR lt_sales_text.
-
ENDIF. ENDLOOP. "创建SO不补充wbs 创建成功再补 CLEAR:lv_memory_flag. FREE MEMORY ID 'FLAG'. lv_memory_flag = 'X'. EXPORT lv_memory_flag TO MEMORY ID 'FLAG'. CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING order_header_in = ls_order_header_in order_header_inx = ls_order_header_inx " logic_switch = ls_logic_switch " IMPORTING " salesdocument = lv_vbeln TABLES return = lt_return order_items_in = lt_order_items_in order_items_inx = lt_order_items_inx order_partners = lt_order_partners order_schedules_in = lt_order_schedules_in order_schedules_inx = lt_order_schedules_inx. "order_conditions_in = lt_order_conditions_in "order_conditions_inx = lt_order_conditions_inx. LOOP AT lt_return WHERE type CA 'EAX'. lv_flag = 'X'. ENDLOOP. IF lv_flag = ''. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. LOOP AT lt_return. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = lt_return-id msgnr = lt_return-number msgv1 = lt_return-message_v1 msgv2 = lt_return-message_v2 msgv3 = lt_return-message_v3 msgv4 = lt_return-message_v4 IMPORTING message_text_output = l_string_temp. CONCATENATE l_string_temp l_string INTO l_string. CLEAR:lt_return. ENDLOOP. LOOP AT tab_vbak_temp INTO wa_vbak_temp . wa_vbak_temp-vbeln = lv_vbeln. wa_vbak_temp-type = 'S'. wa_vbak_temp-message = l_string. MODIFY tab_vbak_temp FROM wa_vbak_temp TRANSPORTING vbeln type message. IF wa_vbak_temp-pspid IS NOT INITIAL. CLEAR:lv_ps_psp_pnr,lv_prctr. CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT' EXPORTING input = wa_vbak_temp-pspid IMPORTING output = lv_ps_psp_pnr . IF sy-subrc EQ 0. DO . SELECT COUNT(*) FROM vbak WHERE vbeln = lv_vbeln. IF sy-subrc EQ 0. EXIT. ELSE. WAIT UP TO 1 SECONDS. ENDIF. ENDDO. SELECT SINGLE prctr INTO lv_prctr FROM prps WHERE pspnr = lv_ps_psp_pnr. "WBS 写不进去 so bapi UPDATE vbap SET ps_psp_pnr = lv_ps_psp_pnr prctr = lv_prctr WHERE vbeln = lv_vbeln AND posnr = wa_vbak_temp-posnr. COMMIT WORK AND WAIT . ENDIF. ENDIF. ENDLOOP. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. LOOP AT lt_return WHERE type <> 'S'. CALL FUNCTION 'MESSAGE_TEXT_BUILD' EXPORTING msgid = lt_return-id msgnr = lt_return-number msgv1 = lt_return-message_v1 msgv2 = lt_return-message_v2 msgv3 = lt_return-message_v3 msgv4 = lt_return-message_v4 IMPORTING message_text_output = l_string_temp. CONCATENATE l_string_temp l_string INTO l_string. CLEAR:lt_return. ENDLOOP. LOOP AT tab_vbak_temp INTO wa_vbak_temp . wa_vbak_temp-vbeln = ''. wa_vbak_temp-type = 'E'. wa_vbak_temp-message = l_string. MODIFY tab_vbak_temp FROM wa_vbak_temp TRANSPORTING vbeln type message. ENDLOOP. ENDIF. APPEND LINES OF tab_vbak_temp TO tab_return. REFRESH:tab_vbak_temp,lt_sales_text,lt_extensionin,lt_order_conditions_inx, lt_order_conditions_in,lt_order_schedules_inx,lt_order_schedules_in, lt_order_partners,lt_order_items_in,lt_return. CLEAR:wa_vbak,wa_vbak_temp,lv_vbeln,ls_order_header_in,l_string,l_string_temp,lv_flag,lv_change.
ENDAT.
ENDLOOP.REFRESH:tab_vbak.
tab_vbak[] = tab_return[].
ENDFUNCTION.
推荐阅读
-
ASP.NET MVC+LINQ开发一个图书销售站点(4):创建一个ASP.NET MVC应用的原型
-
C#利用时间和随即字符串创建唯一的订单编号
-
使用“消息服务框架”(MSF)实现分布式事务的三阶段提交协议(电商创建订单的示例)
-
使用nodejs调用C4C的Odata服务创建销售订单 nodejsCloudC4CSAP Cloud PlatformSAP云平台
-
SAP CRM销售订单UI上的字段对应的数据库表存储字段:请求开始和结束字段 CRMSAPSAP云平台SAP Cloud PlatformSAP成都研究院
-
获取销售订单行对应的总成本
-
OEOIMP-创建销售订单(R12.2.3)
-
创建销售订单的RFC
-
C#利用时间和随即字符串创建唯一的订单编号
-
关于支付宝付款,商城系统中订单取消或者删除之后,如何阻止用户用之前创建的支付宝订单付款!