SAP_SD常用BAPI

SAP_SD常用BAPI1、创建销售订单:BAPI_SALESORDER_CREATEFROMDAT22、创建退货销售订单:BAPI_CUSTOMERRETURN_CREATE3、根据销售订单生成交货单:BAPI_DELIVERYPROCESSING_EXEC4、修改外向交货单:BAPI_OUTB_DELIVERY_CHANGE5、修改内向交货单:BAPI_INB_DELIVERY_CHANGE6、交…

大家好,又见面了,我是你们的朋友全栈君。

1、创建销售订单:BAPI_SALESORDER_CREATEFROMDAT2
2、创建退货销售订单:BAPI_CUSTOMERRETURN_CREATE
3、根据销售订单生成交货单:BAPI_DELIVERYPROCESSING_EXEC
4、修改外向交货单:BAPI_OUTB_DELIVERY_CHANGE
5、修改内向交货单:BAPI_INB_DELIVERY_CHANGE
6、交货单发货过账:WS_DELIVERY_UPDATE
7、VF01/VF04开票:BAPI_BILLINGDOC_CREATEMULTIPLE
DATA: gt_vbak TYPE TABLE OF vbak WITH HEADER LINE,
gt_vbap TYPE TABLE OF vbap WITH HEADER LINE,
gt_billingdatain TYPE TABLE OF bapivbrk WITH HEADER LINE,
gt_conditiondatain TYPE TABLE OF bapikomv WITH HEADER LINE,
gt_errors TYPE TABLE OF bapivbrkerrors WITH HEADER LINE.
*-------------------------------------------------------------------------
*            BAPI 赋值
*-------------------------------------------------------------------------
FORM frm_ready_billing .
DATA: lv_message TYPE bapi_msg.
REFRESH: gt_vbfa[],gt_likp[].
* "找交货单号
SELECT * FROM vbfa INTO CORRESPONDING FIELDS OF TABLE gt_vbfa FOR ALL ENTRIES IN gt_alv WHERE vbelv = gt_alv-vbeln AND vbtyp_n = 'J'. IF gt_vbfa[] IS NOT INITIAL. SELECT * FROM likp INTO CORRESPONDING FIELDS OF TABLE gt_likp FOR ALL ENTRIES IN gt_vbfa WHERE vbeln = gt_vbfa-vbeln. ENDIF. "---同一销售组织、开票类型、客户,统一开票 SORT gt_alv BY fkara vkorg kunnr. SORT gt_vbfa BY vbelv. SORT gt_konv BY knumv. LOOP AT gt_alv INTO gw_alv. READ TABLE gt_vbfa WITH KEY vbelv = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. LOOP AT gt_vbfa FROM sy-tabix. IF gt_vbfa-vbelv <> gw_alv-vbeln. EXIT. ENDIF. gv_count = gv_count + 1. gt_billingdatain-ref_doc = gt_vbfa-vbelv. "凭证号 gt_billingdatain-ref_item = gt_vbfa-posnv. gt_billingdatain-doc_number = gt_vbfa-vbeln. "交货单号 gt_billingdatain-itm_number = gt_vbfa-posnn. " gt_billingdatain-doc_type = gw_alv-auart. "销售凭证类型 gt_billingdatain-ref_doc_ca = 'C'. "SD 凭证类别 gt_billingdatain-ordbilltyp = gw_alv-fkara. "开票类型 gt_billingdatain-salesorg = gw_alv-vkorg. "销售组织 READ TABLE gt_vbak WITH KEY vbeln = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. gt_billingdatain-distr_chan = gt_vbak-vtweg. "分销渠道 gt_billingdatain-division = gt_vbak-spart. "产品组 READ TABLE gt_konv WITH KEY knumv = gt_vbak-knumv BINARY SEARCH. IF sy-subrc EQ 0. LOOP AT gt_konv FROM sy-tabix. IF gt_konv-knumv NE gt_vbak-knumv. EXIT. ENDIF. gt_conditiondatain-data_index = gv_count. gt_conditiondatain-cond_curr = gt_konv-waers. APPEND gt_conditiondatain. ENDLOOP. ENDIF. ENDIF. gt_billingdatain-ship_to = gw_alv-kunnr. "客户 gt_billingdatain-sold_to = gt_billingdatain-ship_to. "售达方 gt_billingdatain-bill_to = gt_billingdatain-ship_to. "开票方 gt_billingdatain-payer = gt_billingdatain-ship_to. "付款方 READ TABLE gt_vbkd WITH KEY vbeln = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. gt_billingdatain-payment_terms = gt_vbkd-zterm. "付款方式 gt_billingdatain-incoterms1 = gt_vbkd-inco1. "国际贸易条款1 gt_billingdatain-incoterms2 = gt_vbkd-inco2. "国际贸易条款2 ENDIF. READ TABLE gt_vbap WITH KEY vbeln = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. gt_billingdatain-plant = gt_vbap-werks. "工厂 gt_billingdatain-material = gt_vbap-matnr. "物料 gt_billingdatain-currency = gt_vbap-waerk. "currency ENDIF. gt_billingdatain-req_qty = abs( gt_vbfa-rfmng ). "数量 gt_billingdatain-sales_unit = gt_vbfa-meins. "单位 gt_billingdatain-bill_date = pr_sdate. "开票日期 gt_billingdatain-price_date = pr_sdate. "开票日期 APPEND gt_billingdatain. ENDLOOP. ELSE. CLEAR gt_vbap. " vbap READ TABLE gt_vbap WITH KEY vbeln = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. CLEAR gt_vbap. LOOP AT gt_vbap FROM sy-tabix. IF gt_vbap-vbeln NE gw_alv-vbeln. EXIT. ENDIF. gv_count = gv_count + 1. gt_billingdatain-ref_doc = gt_vbap-vbeln. "凭证号 gt_billingdatain-ref_item = gt_vbap-posnr. gt_billingdatain-doc_number = gt_vbap-vbeln. "交货单号 gt_billingdatain-itm_number = gt_vbap-posnr. gt_billingdatain-doc_type = gw_alv-auart. "销售凭证类型 gt_billingdatain-ref_doc_ca = 'C'. "SD 凭证类别 gt_billingdatain-ordbilltyp = gw_alv-fkara. "开票类型 gt_billingdatain-salesorg = gw_alv-vkorg. "销售组织 READ TABLE gt_vbak WITH KEY vbeln = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. gt_billingdatain-distr_chan = gt_vbak-vtweg. "分销渠道 gt_billingdatain-division = gt_vbak-spart. "产品组 LOOP AT gt_konv FROM sy-tabix. IF gt_konv-knumv NE gt_vbak-knumv. EXIT. ENDIF. gt_conditiondatain-data_index = gv_count. gt_conditiondatain-cond_curr = gt_konv-waers. APPEND gt_conditiondatain. ENDLOOP. ENDIF. gt_billingdatain-ship_to = gw_alv-kunnr. "客户 gt_billingdatain-sold_to = gt_billingdatain-ship_to. "售达方 gt_billingdatain-bill_to = gt_billingdatain-ship_to. "开票方 gt_billingdatain-payer = gt_billingdatain-ship_to. "付款方 READ TABLE gt_vbkd WITH KEY vbeln = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. gt_billingdatain-payment_terms = gt_vbkd-zterm. "付款方式 gt_billingdatain-incoterms1 = gt_vbkd-inco1. "国际贸易条款1 gt_billingdatain-incoterms2 = gt_vbkd-inco2. "国际贸易条款2 ENDIF. READ TABLE gt_vbap WITH KEY vbeln = gw_alv-vbeln BINARY SEARCH. IF sy-subrc = 0. gt_billingdatain-plant = gt_vbap-werks. "工厂 gt_billingdatain-material = gt_vbap-matnr. "物料 gt_billingdatain-currency = gt_vbap-waerk. "currency ENDIF. gt_billingdatain-req_qty = abs( gt_vbap-zmeng ). "数量 gt_billingdatain-sales_unit = gt_vbap-zieme. "单位 gt_billingdatain-bill_date = pr_sdate. "开票日期 gt_billingdatain-price_date = pr_sdate. "开票日期 APPEND gt_billingdatain. ENDLOOP. ENDIF. ENDIF. "---同一销售组织、单据类型、客户,统一开票 AT END OF kunnr. PERFORM frm_order_billing CHANGING lv_message. "开票 CLEAR gt_billingdatain[]. CLEAR gv_count. gv_item = 10. ENDAT. ENDLOOP. * 开票异常 IF NOT gv_flagx IS INITIAL. CONCATENATE '错误:开票失败,' lv_message INTO lv_message. MESSAGE lv_message TYPE cn_fail. * 开票成功 ELSEIF gv_flagw = space AND gv_flagx = space. MESSAGE s284 DISPLAY LIKE cn_succ. * 开票出现错误,但可开票,出警告 ELSEIF NOT gv_flagw IS INITIAL AND gv_flagx = space. CONCATENATE '警告:开票成功,' lv_message INTO lv_message. MESSAGE lv_message TYPE cn_warn. ENDIF. ENDFORM. " FRM_READY_BILLING *------------------------------------------------------------------------- * CALL BAPI *------------------------------------------------------------------------- FORM frm_order_billing CHANGING pv_message. DATA: lt_success TYPE TABLE OF bapivbrksuccess WITH HEADER LINE, lt_return TYPE TABLE OF bapiret1 WITH HEADER LINE. SORT gt_billingdatain BY ref_doc. REFRESH: lt_return[],lt_success[],gt_errors[]. * Test Run CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE' EXPORTING * CREATORDATAIN = testrun = 'X' * posting = 'X' TABLES billingdatain = gt_billingdatain conditiondatain = gt_conditiondatain * CCARDDATAIN = * TEXTDATAIN = errors = gt_errors return = lt_return success = lt_success. IF NOT gt_errors[] IS INITIAL. gv_flagx = cn_flagx. ENDIF. IF NOT lt_return[] IS INITIAL. LOOP AT lt_return WHERE type = 'E'. CONCATENATE lt_return-message ' ' INTO pv_message. ENDLOOP. gv_flagw = cn_flagx. ENDIF. IF gv_flagx IS INITIAL. * Post Run CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE' EXPORTING * CREATORDATAIN = testrun = '' * posting = 'X' TABLES billingdatain = gt_billingdatain conditiondatain = gt_conditiondatain * CCARDDATAIN = * TEXTDATAIN = errors = gt_errors return = lt_return success = lt_success. IF NOT lt_success[] IS INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. ENDIF. ENDFORM. " FRM_ORDER_BILLING
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/163896.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号