SAP_SD常用BAPI

2022-09-15 11:15:12 浏览数 (2)

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

          • 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
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
代码语言:javascript复制
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
*/

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

0 人点赞