本文主要是介绍BAPI:创建销售订单(VA01),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
业务:如果用户自己填写了销售价格,根据填写的价格维护销售订单定价条件,如果没填则根据配置的定价条件自动带出。
*&---------------------------------------------------------------------*
*& Form FRM_SALESDOCUMENT_CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*FORM FRM_SALESDOCUMENT_CREATE .DATA: LW_SALES_HEADER_IN LIKE BAPISDHD1,LW_SALES_HEADER_INX LIKE BAPISDHD1X,LW_LOGIC_SWITCH TYPE BAPISDLS,LV_SALESDOCUMENT_EX LIKE BAPIVBELN-VBELN,LT_SALES_ITEMS_IN LIKE TABLE OF BAPISDITM WITH HEADER LINE,LT_SALES_ITEMS_INX LIKE TABLE OF BAPISDITMX WITH HEADER LINE,LT_SALES_SCHEDULES_IN LIKE TABLE OF BAPISCHDL WITH HEADER LINE,LT_SALES_SCHEDULES_INX LIKE TABLE OF BAPISCHDLX WITH HEADER LINE,LT_SALES_CONDITIONS_IN LIKE TABLE OF BAPICOND WITH HEADER LINE,LT_SALES_CONDITIONS_INX LIKE TABLE OF BAPICONDX WITH HEADER LINE,LT_SALES_TEXT LIKE TABLE OF BAPISDTEXT WITH HEADER LINE,LT_SALES_PARTNERS_IN LIKE TABLE OF BAPIPARNR WITH HEADER LINE,LT_RETURN LIKE TABLE OF BAPIRET2 WITH HEADER LINE.DATA: L_ANSWER TYPE C,LW_KWMENG TYPE KWMENG,LW_COND_VALUE TYPE BAPIKBETR1,LW_COND_VALUE1 TYPE BAPIKBETR1,LW_SCHED_LINE TYPE ETENR VALUE '0001',LW_ITM_NUM TYPE POSNR_VA .CLEAR: LT_SALES_ITEMS_IN, LT_SALES_ITEMS_INX,LT_SALES_SCHEDULES_IN, LT_SALES_SCHEDULES_INX,LT_SALES_CONDITIONS_IN,LT_SALES_CONDITIONS_INX,LT_SALES_PARTNERS_IN,LT_RETURN.CLEAR :GT_ZTSD003[],GT_YTLIST1[].GT_YTLIST1[] = GT_YTLIST[].SORT GT_YTLIST1 BY VBELN.DELETE GT_YTLIST1 WHERE FLAG <> ABAP_ON.SELECT *INTO CORRESPONDING FIELDS OF TABLE GT_ZTSD003FROM ZTSD003FOR ALL ENTRIES IN GT_YTLIST1WHERE VBELN = GT_YTLIST1-VBELN.SORT GT_ZTSD003 BY MATNR.**=> sales order headerIF LW_SALES_HEADER_IN IS INITIAL.LW_SALES_HEADER_IN-DOC_TYPE = GS_XSBC-AUART. " 销售凭证类型LW_SALES_HEADER_IN-SALES_ORG = GS_XSBC-VKORG. " 销售机构LW_SALES_HEADER_IN-DISTR_CHAN = GS_XSBC-VTWEG. " 分销渠道LW_SALES_HEADER_IN-DIVISION = GS_XSBC-SPART. " 产品组LW_SALES_HEADER_INX-DOC_TYPE = ABAP_TRUE.LW_SALES_HEADER_INX-SALES_ORG = ABAP_TRUE.LW_SALES_HEADER_INX-DISTR_CHAN = ABAP_TRUE.LW_SALES_HEADER_INX-DIVISION = ABAP_TRUE.ENDIF.IF LT_SALES_PARTNERS_IN[] IS INITIAL.CLEAR : LT_SALES_PARTNERS_IN.LT_SALES_PARTNERS_IN-PARTN_ROLE = 'AG'. "LT_SALES_PARTNERS_IN-PARTN_NUMB = GS_XSBC-KUNAG. " 售达方APPEND LT_SALES_PARTNERS_IN.CLEAR LT_SALES_PARTNERS_IN.LT_SALES_PARTNERS_IN-PARTN_ROLE = 'WE'. "LT_SALES_PARTNERS_IN-PARTN_NUMB = GS_XSBC-KUNWE." 送达方APPEND LT_SALES_PARTNERS_IN.CLEAR LT_SALES_PARTNERS_IN.ENDIF.LOOP AT GT_ZTSD003 INTO GS_ZTSD003.LW_KWMENG = GS_ZTSD003-KWMENG + LW_KWMENG.LW_COND_VALUE = GS_ZTSD003-ZKBETR_XS.LW_COND_VALUE1 = GS_ZTSD003-ZKBETR_ZD.**=> sales order itemLT_SALES_ITEMS_IN-MATERIAL = GS_ZTSD003-MATNR. " 物料LT_SALES_ITEMS_IN-PLANT = GS_ZTSD003-WERKS. " 工厂LT_SALES_ITEMS_IN-STORE_LOC = GS_ZTSD003-LGORT. " 库存地点LT_SALES_ITEMS_INX-MATERIAL = ABAP_TRUE.LT_SALES_ITEMS_INX-PLANT = ABAP_TRUE.LT_SALES_ITEMS_INX-STORE_LOC = ABAP_TRUE.AT END OF MATNR.LW_ITM_NUM = LW_ITM_NUM + 10.
**=> sales order itemLT_SALES_ITEMS_IN-ITM_NUMBER = LW_ITM_NUM.LT_SALES_ITEMS_INX-ITM_NUMBER = LW_ITM_NUM.
*APPEND: LT_SALES_ITEMS_IN, LT_SALES_ITEMS_INX.CLEAR: LT_SALES_ITEMS_IN, LT_SALES_ITEMS_INX." 计划行号LT_SALES_SCHEDULES_IN-ITM_NUMBER = LW_ITM_NUM.LT_SALES_SCHEDULES_IN-SCHED_LINE = LW_SCHED_LINE. " L_TABIX.LT_SALES_SCHEDULES_IN-REQ_DATE = SY-DATUM. " 计划行日期LT_SALES_SCHEDULES_IN-REQ_QTY = LW_KWMENG. " 以销售单位计的 订单数量LT_SALES_SCHEDULES_INX-ITM_NUMBER = LW_ITM_NUM.LT_SALES_SCHEDULES_INX-SCHED_LINE = LW_SCHED_LINE.LT_SALES_SCHEDULES_INX-REQ_DATE = ABAP_TRUE.LT_SALES_SCHEDULES_INX-REQ_QTY = ABAP_TRUE.APPEND: LT_SALES_SCHEDULES_IN, LT_SALES_SCHEDULES_INX.CLEAR: LT_SALES_SCHEDULES_IN, LT_SALES_SCHEDULES_INX,LW_KWMENG.*----- 条件IF LW_COND_VALUE NE 0 AND LW_COND_VALUE1 NE 0.
*----- 复制不变定价因素且重定税款LW_LOGIC_SWITCH-PRICING = 'G'.LT_SALES_CONDITIONS_IN-ITM_NUMBER = LW_ITM_NUM.LT_SALES_CONDITIONS_IN-COND_TYPE = 'ZPR1'. " 条件类型 定价条件LT_SALES_CONDITIONS_IN-COND_VALUE = LW_COND_VALUE. " 价格 定价比率LT_SALES_CONDITIONS_IN-CURRENCY = 'CNY'. " 货币码LT_SALES_CONDITIONS_INX-ITM_NUMBER = LW_ITM_NUM.LT_SALES_CONDITIONS_INX-COND_TYPE = 'ZPR1'.LT_SALES_CONDITIONS_INX-CURRENCY = ABAP_TRUE.LT_SALES_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.APPEND: LT_SALES_CONDITIONS_IN,LT_SALES_CONDITIONS_INX.CLEAR: LT_SALES_CONDITIONS_IN,LT_SALES_CONDITIONS_INX,LW_COND_VALUE.LT_SALES_CONDITIONS_IN-ITM_NUMBER = LW_ITM_NUM.LT_SALES_CONDITIONS_IN-COND_TYPE = 'ZPR2'. " 条件类型 定价条件LT_SALES_CONDITIONS_IN-COND_VALUE = LW_COND_VALUE1. " 价格 定价比率LT_SALES_CONDITIONS_IN-CURRENCY = 'CNY'. " 货币码LT_SALES_CONDITIONS_INX-ITM_NUMBER = LW_ITM_NUM.LT_SALES_CONDITIONS_INX-COND_TYPE = 'ZPR2'.LT_SALES_CONDITIONS_INX-CURRENCY = ABAP_TRUE.LT_SALES_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.APPEND: LT_SALES_CONDITIONS_IN,LT_SALES_CONDITIONS_INX.CLEAR: LT_SALES_CONDITIONS_IN,LT_SALES_CONDITIONS_INX,LW_COND_VALUE.ENDIF.ENDAT.ENDLOOP.CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'EXPORTINGSALES_HEADER_IN = LW_SALES_HEADER_INSALES_HEADER_INX = LW_SALES_HEADER_INXCONVERT_PARVW_AUART = ABAP_ONLOGIC_SWITCH = LW_LOGIC_SWITCHIMPORTINGSALESDOCUMENT_EX = LV_SALESDOCUMENT_EXTABLESRETURN = LT_RETURNSALES_ITEMS_IN = LT_SALES_ITEMS_INSALES_ITEMS_INX = LT_SALES_ITEMS_INXSALES_SCHEDULES_IN = LT_SALES_SCHEDULES_INSALES_SCHEDULES_INX = LT_SALES_SCHEDULES_INXSALES_CONDITIONS_IN = LT_SALES_CONDITIONS_INSALES_CONDITIONS_INX = LT_SALES_CONDITIONS_INXSALES_PARTNERS = LT_SALES_PARTNERS_IN.IF SY-SUBRC EQ 0 AND LV_SALESDOCUMENT_EX IS NOT INITIAL.GT_YTLIST-ZVBELN_S = LV_SALESDOCUMENT_EX.MODIFY GT_YTLIST TRANSPORTING ZVBELN_S WHERE FLAG = ABAP_ON .LOOP AT GT_YTLIST WHERE FLAG = ABAP_ON.UPDATE ZTSD004 SET ZVBELN_S = LV_SALESDOCUMENT_EXWHERE VBELN = GT_YTLIST-VBELN.ENDLOOP.MESSAGE S020(ZMSG) WITH LV_SALESDOCUMENT_EX.COMMIT WORK.ELSE.LOOP AT LT_RETURN WHERE TYPE = 'E'.MESSAGE LT_RETURN-MESSAGE TYPE 'S' DISPLAY LIKE 'E'.EXIT.ENDLOOP.ROLLBACK WORK.ENDIF.ENDFORM.
这篇关于BAPI:创建销售订单(VA01)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!