FUNCTION Z_SD_SALESORDER_CREATE. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" REFERENCE(IM_HEADER) LIKE VBAK STRUCTURE VBAK *" EXPORTING *" VALUE(EX_SALESORDER) TYPE VBELN *" TABLES *" IT_ITEM STRUCTURE VBAP *" IT_RETURN STRUCTURE BAPIRET2 OPTIONAL *"---------------------------------------------------------------------- PERFORM FRM_INIT_SALESORDER_HEADER USING IM_HEADER. PERFORM FRM_INIT_SALESORDER_ITEM TABLES IT_ITEM USING IM_HEADER. PERFORM FRM_INIT_SOPARTNER USING IM_HEADER-KUNNR. PERFORM FRM_INIT_SALESORDER_CONDITION TABLES IT_ITEM. PERFORM FRM_CREATE_SALESORDER CHANGING EX_SALESORDER. * APPEND LINES OF GT_RETURN TO IT_RETURN. IT_RETURN[] = GT_RETURN[]. ENDFUNCTION.
FORM FRM_INIT_SALESORDER_HEADER USING P_HEADER STRUCTURE VBAK. CLEAR GS_SALESORDER_HEADER. * Mandatory entries: GS_SALESORDER_HEADER-DOC_TYPE = 'ZRWF'."入网费 GS_SALESORDER_HEADER-SALES_ORG = '8001'. "Sales organization GS_SALESORDER_HEADER-DISTR_CHAN = '20'. "Distribution channel GS_SALESORDER_HEADER-DIVISION = '00'. " Division * Optional entries: GS_SALESORDER_HEADER-DOC_DATE = SY-DATUM. "Document date (订单日期) GS_SALESORDER_HEADER-REF_1 = P_HEADER-IHREZ. "Customer PO No. (POS订单号码) * GS_SALESORDER_HEADER-ORD_REASON = U_HEADER-ZDDLX. "Order reason. (订单类型) * GS_SALESORDER_HEADER-TELEPHONE = U_HEADER-ZLXDH. "Telephone Number. (联系电话) * GS_SALESORDER_HEADER-NAME = U_HEADER-ZLSR. "Name of order. (联系人) ** GS_SALESORDER_HEADER-DOC_DATE = SY-DATUM. "Name of order. (联系人) * Change index GS_SALESORDER_HEADERX-UPDATEFLAG = 'I'. "Sales document type GS_SALESORDER_HEADERX-DOC_TYPE = 'X'. "Sales document type GS_SALESORDER_HEADERX-SALES_ORG = 'X'. "Sales organization GS_SALESORDER_HEADERX-DISTR_CHAN = 'X'. "Distribution channel GS_SALESORDER_HEADERX-DIVISION = 'X'. " Division GS_SALESORDER_HEADERX-DOC_DATE = 'X'. "Document date (订单日期) GS_SALESORDER_HEADERX-REF_1 = 'X'. "Customer PO No. (POS订单号码) * GS_SALESORDER_HEADERX-ORD_REASON = 'X'. "Order reason. (订单类型) * GS_SALESORDER_HEADERX-TELEPHONE = 'X'. "Telephone Number. (联系电话) * GS_SALESORDER_HEADERX-NAME = 'X'. "Name of order. (联系人) * GS_SALESORDER_HEADERX-DOC_DATE = 'X'. "Name of order. (联系人) CLEAR GS_LOGIC_SWITCH. * GS_LOGIC_SWITCH-COND_HANDL = 'X'. GS_LOGIC_SWITCH-PRICING = 'G'. ENDFORM. " FRM_INIT_SALESORDER_HEADER
FORM FRM_INIT_SALESORDER_ITEM TABLES IT_ITEM STRUCTURE VBAP USING P_HEADER STRUCTURE VBAK. DATA : LS_ITEM TYPE VBAP, LV_MATNR TYPE MATNR, LV_POSNR TYPE POSNR. CLEAR : GS_SALESORDER_ITEM, GT_SALESORDER_ITEM, GT_SALESORDER_CONDITIONS, GT_SALESORDER_CONDITIONX. CLEAR : GS_SALESORDER_SCHLINE, GT_SALESORDER_SCHLINE, GS_SALESORDER_SCHLINEX, GT_SALESORDER_SCHLINEX. CLEAR LV_POSNR. LOOP AT IT_ITEM INTO LS_ITEM. ADD 10 TO LV_POSNR. *** Items * Convert Article no. (商品款号) PERFORM FRM_CONVERT_ARTICLE USING LS_ITEM-MATNR CHANGING LV_MATNR. GS_SALESORDER_ITEM-ITM_NUMBER = LV_POSNR."'10'. "Item (行项目号) GS_SALESORDER_ITEM-MATERIAL = LV_MATNR."70 ”Article (商品款号) GS_SALESORDER_ITEM-BATCH = LS_ITEM-CHARG."70 ”Article (商品款号) GS_SALESORDER_ITEM-PLANT = LS_ITEM-WERKS."P_HEADER-WERKS. "Site () GS_SALESORDER_ITEM-STORE_LOC = LS_ITEM-LGORT."Storage location GS_SALESORDER_ITEM-TARGET_QTY = '1'."Target quantity in sales units (商品件数) * gs_salesorder_item-target_qu = 'ST'. APPEND GS_SALESORDER_ITEM TO GT_SALESORDER_ITEM. GS_SALESORDER_ITEMX-UPDATEFLAG = 'I'. GS_SALESORDER_ITEMX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_ITEMX-MATERIAL = 'X'. GS_SALESORDER_ITEMX-BATCH = 'X'. GS_SALESORDER_ITEMX-PLANT = 'X'. GS_SALESORDER_ITEMX-STORE_LOC = 'X'. * gs_salesorder_itemx-sales_unit = 'X'. GS_SALESORDER_ITEMX-TARGET_QTY = 'X'. * gs_salesorder_itemx-target_qu = 'X'. APPEND GS_SALESORDER_ITEMX TO GT_SALESORDER_ITEMX. *** Scheuld line CLEAR GS_SALESORDER_SCHLINE. GS_SALESORDER_SCHLINE-ITM_NUMBER = LV_POSNR. GS_SALESORDER_SCHLINE-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINE-REQ_QTY = '1'. * gs_salesorder_schline-req_date = '20140830'. APPEND GS_SALESORDER_SCHLINE TO GT_SALESORDER_SCHLINE. CLEAR GS_SALESORDER_SCHLINEX. GS_SALESORDER_SCHLINEX-ITM_NUMBER = LV_POSNR. GS_SALESORDER_SCHLINEX-SCHED_LINE = '0001'. GS_SALESORDER_SCHLINEX-UPDATEFLAG = 'I'. * gs_salesorder_schlinex-req_date = 'X'. GS_SALESORDER_SCHLINEX-REQ_QTY = 'X'. APPEND GS_SALESORDER_SCHLINEX TO GT_SALESORDER_SCHLINEX. * Conditions CLEAR GS_SALESORDER_CONDITIONS. GS_SALESORDER_CONDITIONS-ITM_NUMBER = LV_POSNR. * GS_SALESORDER_CONDITIONS-COND_COUNT = '10'. GS_SALESORDER_CONDITIONS-COND_TYPE = 'ZF01'. GS_SALESORDER_CONDITIONS-COND_VALUE = LS_ITEM-NETPR. * GS_SALESORDER_CONDITIONS-CONDVALUE = '10'. GS_SALESORDER_CONDITIONS-CURRENCY = 'CNY'. APPEND GS_SALESORDER_CONDITIONS TO GT_SALESORDER_CONDITIONS. CLEAR GS_SALESORDER_CONDITIONX. GS_SALESORDER_CONDITIONX-ITM_NUMBER = LV_POSNR. * GS_SALESORDER_CONDITIONS-COND_COUNT = '10'. GS_SALESORDER_CONDITIONX-COND_TYPE = 'ZF01'. GS_SALESORDER_CONDITIONX-UPDATEFLAG = 'I'. GS_SALESORDER_CONDITIONX-COND_VALUE = 'X'. * GS_SALESORDER_CONDITIONX-CONDVALUE = 'X'. GS_SALESORDER_CONDITIONX-CURRENCY = 'X'. APPEND GS_SALESORDER_CONDITIONX TO GT_SALESORDER_CONDITIONX. ENDLOOP. ENDFORM. " FRM_INIT_SALESORDER_ITEM
FORM FRM_INIT_SOPARTNER USING P_CUSTOMER. DATA : LV_KUNNR TYPE KUNNR. * Convert customer no. to internal no.(客户编码) CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = P_CUSTOMER IMPORTING OUTPUT = LV_KUNNR. * WE Ship to , AG Sold to CLEAR GS_SALESORDER_PARTNER. * gs_salesorder_partner-itm_number = '10'." GS_SALESORDER_PARTNER-PARTN_ROLE = 'WE'."SP GS_SALESORDER_PARTNER-PARTN_NUMB = LV_KUNNR. "(客户编码) * gs_salesorder_partner-name = u_header-zkhmc. "Name (客户名称) APPEND GS_SALESORDER_PARTNER TO GT_SALESORDER_PARTNER. ENDFORM. " FRM_INIT_SOPARTNER
FORM FRM_INIT_SALESORDER_CONDITION TABLES IT_ITEM STRUCTURE VBAP. ENDFORM. " FRM_INIT_SALESORDER_CONDITION
FORM FRM_CREATE_SALESORDER CHANGING P_SALESORDER. DATA : LV_SALESORDER TYPE BAPIVBELN-VBELN, LV_ERROR. REFRESH GT_RETURN. CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING ORDER_HEADER_IN = GS_SALESORDER_HEADER ORDER_HEADER_INX = GS_SALESORDER_HEADERX LOGIC_SWITCH = GS_LOGIC_SWITCH IMPORTING SALESDOCUMENT = LV_SALESORDER TABLES RETURN = GT_RETURN ORDER_ITEMS_IN = GT_SALESORDER_ITEM ORDER_ITEMS_INX = GT_SALESORDER_ITEMX ORDER_PARTNERS = GT_SALESORDER_PARTNER ORDER_SCHEDULES_IN = GT_SALESORDER_SCHLINE ORDER_SCHEDULES_INX = GT_SALESORDER_SCHLINEX ORDER_CONDITIONS_IN = GT_SALESORDER_CONDITIONS ORDER_CONDITIONS_INX = GT_SALESORDER_CONDITIONX. LOOP AT GT_RETURN INTO GS_RETURN WHERE TYPE = 'E' OR TYPE = 'X' OR TYPE = 'A'. EXIT. ENDLOOP. IF SY-SUBRC EQ 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. P_SALESORDER = LV_SALESORDER. ENDIF. REFRESH : GT_SALESORDER_ITEM, GT_SALESORDER_ITEMX, GT_SALESORDER_PARTNER, GT_SALESORDER_SCHLINE, GT_SALESORDER_SCHLINEX, GT_SALESORDER_CONDITIONS, GT_SALESORDER_CONDITIONX. ENDFORM. " FRM_CREATE_SALESORDER
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/18701.html