本文主要是介绍SAP_ABAP_SD_BAPI清单案例教程——销售订单创建_BAPI_SALESORDER_CREATEFROMDAT2_VA01_S4版本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
SAP ABAP 顾问(开发工程师)能力模型_Terry谈企业数字化的博客-CSDN博客目标:基于对SAP abap 顾问能力模型的梳理,给一年左右经验的abaper 快速成长为三年经验提参考ALV/REPORT|SMARTFROM|SCREEN|OLE|BAPI|BDC|PI|IDOC|RFC|API|WEBSERVICE|Enhancement|UserExits|Badi|Debughttps://blog.csdn.net/java_zhong1990/article/details/132469977
一 背景说明
SAP BAPI(Business Application Programming Interface)是SAP系统中的一组规范和标准,用于从SAP系统中获取数据、输入数据和更新数据。这些API允许开发者以编程方式与SAP系统交互,而无需编写大量的自定义代码。
1.1 BAPI清单
销售订单创建 | BAPI_BILLINGDOC_CREATEMULTIPLE |
交货单创建 | BAPI_OUTB_DELIVERY_CREATE_SLS |
交货单过帐 | WS_DELIVERY_UPDATE |
销售订单开票 | BAPI_BILLINGDOC_CREATEMULTIPLE |
二 实施步骤
2.1 Copy代码 直接可使用
2.2 案例模版涉及样例内容
抬头 | 增强 | 文本 | 合作伙伴 | 行表 | 计划行表 | 条件表
function zfm_sd_create_so.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IN_HEADER) LIKE ZSSD_SOHEADER STRUCTURE ZSSD_SOHEADER
*" EXPORTING
*" VALUE(VBELN) TYPE VBELN
*" REFERENCE(ZSTATUS) TYPE CHAR1
*" TABLES
*" IN_ITEM STRUCTURE ZSSD_SOITEM
*" IT_RETURN STRUCTURE BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------" 抬头data ls_order_header_in like bapisdhd1.data ls_order_header_inx like bapisdhd1x." 增强data lt_extensionin type table of bapiparex.data ls_bape_vbak type bape_vbak.data ls_bape_vbakx type bape_vbakx.data ls_bape_vbap type bape_vbap.data ls_bape_vbapx type bape_vbapx." 文本data lt_order_text type table of bapisdtext.data ls_bapisdtext type bapisdtext." 合作伙伴data lt_order_partners type table of bapiparnr.data ls_order_partners type bapiparnr." 行表data lt_order_items_in type table of bapisditm.data ls_order_items_in type bapisditm.data lt_order_items_inx type table of bapisditmx.data ls_order_items_inx type bapisditmx." 计划行表data lt_order_schedules_in type table of bapischdl.data ls_order_schedules_in type bapischdl.data lt_order_schedules_inx type table of bapischdlx.data ls_order_schedules_inx type bapischdlx." 条件表data lt_order_conditions_in type table of bapicond.data ls_order_conditions_in type bapicond.data lt_order_conditions_inx type table of bapicondx.data ls_order_conditions_inx type bapicondx."1,订单抬头字段赋值ls_order_header_in-doc_type = in_header-doc_type. "订单类型ls_order_header_inx-doc_type = 'X'. "订单类型ls_order_header_in-sales_org = in_header-sales_org. "销售组织ls_order_header_inx-sales_org = 'X'. "销售组织ls_order_header_in-distr_chan = in_header-distr_chan. "分销渠道ls_order_header_inx-distr_chan = 'X'. "分销渠道ls_order_header_in-division = in_header-division. "产品组ls_order_header_inx-division = 'X'. "产品组ls_order_header_in-req_date_h = in_header-req_date_h. "默认为当前日期ls_order_header_inx-req_date_h = 'X'. "默认为当前日期ls_order_header_in-purch_date = in_header-purch_date. "默认为当前日期ls_order_header_inx-purch_date = 'X'. "默认为当前日期ls_order_header_in-ord_reason = in_header-ord_reason. "订单原因ls_order_header_inx-ord_reason = 'X'. "订单原因ls_order_header_in-price_date = in_header-price_date. "默认为当前日期ls_order_header_inx-price_date = 'X'. "默认为当前日期ls_order_header_in-purch_no_c = in_header-purch_no_c. "客户合同号码ls_order_header_inx-purch_no_c = 'X'. "客户合同号码
* ls_order_header_in-ship_type = in_header-ship_type. "运输方式
* ls_order_header_inx-ship_type = 'X'. "运输方式"2,增强字段赋值ls_bape_vbak-zwsjg_flag = in_header-zwsjg_flag. "不含税价格ls_bape_vbakx = 'X'.append ls_bape_vbak to lt_extensionin.append ls_bape_vbakx to lt_extensionin."3,抬头文本赋值ls_bapisdtext-text_id = 'ZSH1'."文本 IDls_bapisdtext-langu = sy-langu. ."语言代码ls_bapisdtext-text_line = in_header-note1."文本行
* ls_bapisdtext-doc_number= ."销售凭证
* ls_bapisdtext-itm_number= ."销售凭证项目
* ls_bapisdtext-langu_iso= ."2 字符 SAP 语言代码
* ls_bapisdtext-format_col-= ."标记列
* ls_bapisdtext-function= ."功能append ls_bapisdtext to lt_order_text.clear ls_bapisdtext.ls_bapisdtext-text_id = 'ZSH2'."文本 IDls_bapisdtext-langu = sy-langu. ."语言代码ls_bapisdtext-text_line = in_header-note2."文本行append ls_bapisdtext to lt_order_text.clear ls_bapisdtext."4,售达方 送达方 赋值clear ls_order_partners.ls_order_partners-partn_role = 'AG'.ls_order_partners-partn_numb = in_header-sale_kunnr. "售达方append ls_order_partners to lt_order_partners.clear ls_order_partners.ls_order_partners-partn_role = 'WE'.ls_order_partners-partn_numb = in_header-send_kunnr. "送达方append ls_order_partners to lt_order_partners.loop at in_item[] into in_item.ls_order_items_in-itm_number = in_item-posnr. "客户合同行项目号码ls_order_items_inx-itm_number = in_item-posnr. "客户合同行项目号码ls_order_items_in-po_itm_no = in_item-posnr. "客户合同行项目号码ls_order_items_inx-po_itm_no = 'X'. "客户合同行项目号码ls_order_items_in-material_long = in_item-material_long. "物料号码ls_order_items_inx-material_long = 'X'. "物料号码ls_order_items_in-cust_mat35 = in_item-cus_matnr. "客户物料号码ls_order_items_inx-cust_mat35 = 'X'. "客户物料号码ls_order_items_in-plant = in_item-werks. "工厂ls_order_items_inx-plant = 'X'. "工厂ls_order_items_in-store_loc = in_item-lgort. "库存地点ls_order_items_inx-store_loc = 'X'. "库存地点ls_order_items_in-target_qty = in_item-zmeng. "订单数量ls_order_items_inx-target_qty = 'X'. "订单数量append ls_order_items_in to lt_order_items_in.append ls_order_items_inx to lt_order_items_inx."其中:VBAP- ZKDMAT:二级客户物料号码,扩展字段采用EXTENSIONIN的方式进行处理;ls_bape_vbap-posnr = in_item-posnr.ls_bape_vbapx-posnr = in_item-posnr.ls_bape_vbap-zkdmat = in_item-zlevel_matnr.ls_bape_vbapx-zkdmat = 'X'.append ls_bape_vbap to lt_extensionin.append ls_bape_vbapx to lt_extensionin."行项目备注1,赋值到对应的文本上,文本ID和文本对象如下所示:clear ls_bapisdtext.ls_bapisdtext-itm_number = in_item-posnr ."销售凭证项目ls_bapisdtext-text_id = 'ZSI1'."文本 IDls_bapisdtext-langu = sy-langu. ."语言代码ls_bapisdtext-text_line = in_item-note1."文本行append ls_bapisdtext to lt_order_text.ls_order_schedules_in-itm_number = in_item-posnr."当前的行项目号码ls_order_schedules_inx-itm_number = in_item-posnr."当前的行项目号码ls_order_schedules_in-date_type = in_item-abdat." 交货日期ls_order_schedules_inx-date_type = 'X'." 交货日期ls_order_schedules_in-req_qty = in_item-zmeng."订单数量ls_order_schedules_inx-req_qty = 'X'."订单数量append ls_order_schedules_in to lt_order_schedules_in.append ls_order_schedules_inx to lt_order_schedules_inx.ls_order_conditions_in-itm_number = in_item-posnr."当前的行项目号码ls_order_conditions_inx-itm_number = in_item-posnr."当前的行项目号码ls_order_conditions_in-cond_type = 'ZPR0' ."ls_order_conditions_inx-cond_type = 'X' ."ls_order_conditions_in-cond_value = in_item-zkbetr."价格ls_order_conditions_inx-cond_value = 'X'."价格ls_order_conditions_in-currency = in_item-waerk."货币ls_order_conditions_inx-currency = 'X'."货币ls_order_conditions_in-cond_p_unt = in_item-zkpein."价格因子ls_order_conditions_inx-cond_p_unt = 'X'."价格因子ls_order_conditions_in-curr_iso = in_item-waerk."货币
* ls_order_conditions_inx-curr_iso = 'X'."货币 "X结构中不存在 curr_isoappend ls_order_conditions_in to lt_order_conditions_in.append ls_order_conditions_inx to lt_order_conditions_inx.endloop.call function 'BAPI_SALESORDER_CREATEFROMDAT2'exportingorder_header_in = ls_order_header_inorder_header_inx = ls_order_header_inximportingsalesdocument = vbelntablesreturn = it_returnorder_items_in = lt_order_items_inorder_items_inx = lt_order_items_inxorder_partners = lt_order_partnersorder_schedules_in = lt_order_schedules_inorder_schedules_inx = lt_order_schedules_inxorder_conditions_in = lt_order_conditions_inorder_conditions_inx = lt_order_conditions_inxextensionin = lt_extensionin.if sy-subrc = 0 and vbeln is not initial.call function 'BAPI_TRANSACTION_COMMIT' "BAPI事务提交exportingwait = 'X'.zstatus = 'S'.else.zstatus = 'E'.endif.endfunction.
这篇关于SAP_ABAP_SD_BAPI清单案例教程——销售订单创建_BAPI_SALESORDER_CREATEFROMDAT2_VA01_S4版本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!