BAPI_PO_CREATE1 创建采购订单实例
ABAP创建销售订单BAPI示例
ABAP创建销售订单BAPI⽰例ABAP中创建销售订单1.BAPI1. BAPI_SALESORDER_CREATEFROMDAT22. BAPI_CUSTOMERRETURN_CREATE3. SD_SALESDOCUMENT_CREATE2.BAPIBAPI_SALESORDER_CREATEFROMDAT2 业务对象限制为BUS2032BAPI_CUSTOMERRETURN_CREATE 业务对象限制为BUS2102SD_SALESDOCUMENT_CREATE 未限制业务对象类型BUS2030 客户询价单BUS2031 客户报价BUS2032 销售订单BUS2034 合同BUS2094 贷项订单BUS2096 借项订单BUS2102 退货订单BUS2103 后续免费送货订单BAPI_SALESORDER_CREATEFROMDAT2和BAPI_CUSTOMERRETURN_CREATE都在内部调⽤SD_SALESDOCUMENT_CREATE 对于不同订单类型(Z001,Z002…),配置了的SD凭证类型;可在TVAK表中VBTYP字段查看业务对象和SD凭证类型有绑定关系;⽐如Z008 Z009凭证,SD凭证类型为H(退货)所以需要使⽤业务对象类型BUS2102的BAPI;或者使⽤SD_SALESDOCUMENT_CREATE并设置参数BUSINESS_OBJECT = ‘BUS2102’3.4.5.此⽅法save_text切割的字符串结尾为空格时;会造成空格丢失,需要⾃⾏写逻辑处理处理逻辑:缩短切割长度(例如:120);然后判断前⼀⾏是否末尾为空格,如果空则将空格写⼊本⾏开头FUNCTION ZSD_IF0012.*"----------------------------------------------------------------------*"*"本地接⼝:*" IMPORTING*" VALUE(I_HEAD) TYPE ZSDS_CRM_IF007*" EXPORTING*" VALUE(RESULTCODE) TYPE CHAR1*" VALUE(RESULTMSG) TYPE BAPI_MSG*" VALUE(O_VBELN) TYPE VBELN*" TABLES*" T_ITEM STRUCTURE ZSDS_CRM_IF008*"----------------------------------------------------------------------DATA:WA_ORDER_HEADER_IN LIKE BAPISDHD1, "抬头WA_ORDER_HEADER_INX LIKE BAPISDHD1X, "抬头控制WA_LOGIC_SWITCH LIKE BAPISDLS, "内部控制参数GV_SALESDOCUMENT_EX LIKE BAPIVBELN-VBELN, "返回SO凭证号WA_ORDER_ITEMS_IN LIKE BAPISDITM, "⾏项⽬ORDER_ITEMS_IN LIKE TABLE OF BAPISDITM, "⾏项⽬WA_ORDER_ITEMS_INX LIKE BAPISDITMX, "⾏项⽬控制ORDER_ITEMS_INX LIKE TABLE OF BAPISDITMX, "⾏项⽬控制WA_ORDER_PARTNERS LIKE BAPIPARNR, "业务伙伴ORDER_PARTNERS LIKE TABLE OF BAPIPARNR, "业务伙伴WA_ORDER_SCHEDULES_IN LIKE BAPISCHDL, "计划⾏ORDER_SCHEDULES_IN LIKE TABLE OF BAPISCHDL, "计划⾏WA_ORDER_SCHEDULES_INX LIKE BAPISCHDLX, "计划⾏控制ORDER_SCHEDULES_INX LIKE TABLE OF BAPISCHDLX, "计划⾏控制WA_ORDER_CONDITIONS_IN LIKE BAPICOND, "定价条件ORDER_CONDITIONS_IN LIKE TABLE OF BAPICOND, "定价条件WA_ORDER_CONDITIONS_INX LIKE BAPICONDX, "定价条件控制ORDER_CONDITIONS_INX LIKE TABLE OF BAPICONDX, "定价条件控制WA_ORDER_TEXT LIKE BAPISDTEXT, "⽂本ORDER_TEXT LIKE TABLE OF BAPISDTEXT, "⽂本WA_EXTENSIONIN TYPE BAPIPAREX,ORDER_EXTENSIONIN TYPE TABLE OF BAPIPAREX,WA_RETURN LIKE BAPIRET2, "BAPI返回RETURN LIKE TABLE OF BAPIRET2. "BAPI返回DATA: WA_BAPE_VBAP TYPE BAPE_VBAP,WA_BAPE_VBAPX TYPE BAPE_VBAPX,WA_BAPE_VBAK TYPE BAPE_VBAK,WA_BAPE_VBAKX TYPE BAPE_VBAKX.DATA: WA_ITEM TYPE ZSDS_CRM_IF008,GS_LOGS TYPE ZALL_LOGS. "⽇志DATA: GT_DATA TYPE TABLE OF ZSDT_CRM_IF012, "业务数据WA_DATA TYPE ZSDT_CRM_IF012.DATA: GV_STRING TYPE STRING,GT_STRING TYPE TABLE OF CHAR_132,WA_STRING TYPE CHAR_132,GV_LENGTH TYPE I.SELECT *FROM ZMPPZB AS AFOR ALL ENTRIES IN @T_ITEMWHERE ZMPXX = @T_ITEM-ZMPXXINTO TABLE @DATA(GT_ZMPPZB).* 获取⽇志表流⽔号CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'EXPORTINGOBJECT = 'ZLOG001'EXCEPTIONSFOREIGN_LOCK = 1OBJECT_NOT_FOUND = 2SYSTEM_FAILURE = 3OTHERS = 4.IF SY-SUBRC EQ 0.* Implement suitable error handling hereCALL FUNCTION 'NUMBER_GET_NEXT'EXPORTINGNR_RANGE_NR = '01'OBJECT = 'ZLOG001'IMPORTINGNUMBER = GS_LOGS-SEQNR* QUANTITY =* RETURNCODE =EXCEPTIONSINTERVAL_NOT_FOUND = 1NUMBER_RANGE_NOT_INTERN = 2OBJECT_NOT_FOUND = 3QUANTITY_IS_0 = 4QUANTITY_IS_NOT_1 = 5INTERVAL_OVERFLOW = 6BUFFER_OVERFLOW = 7OTHERS = 8.IF SY-SUBRC <> 0.* Implement suitable error handling hereENDIF.CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'EXPORTINGOBJECT = 'ZLOG001'EXCEPTIONSOBJECT_NOT_FOUND = 1OTHERS = 2.IF SY-SUBRC <> 0.* Implement suitable error handling hereENDIF.ELSE.RAISE NUM_RANGE_ERROR .ENDIF.IF I_HEAD-SESSION_ID IS INITIAL.RESULTCODE = 'E'.RESULTMSG = |[SESSION_ID]不允许为空|.O_VBELN = ''.RETURN.ENDIF."Head extenntionSELECT SINGLE *FROM ZTXTGG AS AWHERE ZXTGG = @I_HEAD-ZXTGGINTO @DATA(WA_ZTXTGG).IF SY-SUBRC = 0.CLEAR WA_EXTENSIONIN.WA_BAPE_VBAK-ZXTGG = I_HEAD-ZXTGG.MOVE 'BAPE_VBAK' TO WA_EXTENSIONIN-STRUCTURE.CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_CEXPORTINGIM_VALUE = WA_BAPE_VBAKIMPORTINGEX_CONTAINER = WA_EXTENSIONIN-VALUEPART1.APPEND WA_EXTENSIONIN TO ORDER_EXTENSIONIN.CLEAR WA_EXTENSIONIN.WA_BAPE_VBAKX-ZXTGG = ABAP_TRUE.MOVE 'BAPE_VBAKX' TO WA_EXTENSIONIN-STRUCTURE.MOVE WA_BAPE_VBAPX TO WA_EXTENSIONIN-VALUEPART1.APPEND WA_EXTENSIONIN TO ORDER_EXTENSIONIN.ELSE.RESULTCODE = 'E'.RESULTMSG = '箱贴规格未维护,请联系SD顾问'.O_VBELN = ''.RETURN.ENDIF."SO Header TextCLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = I_HEAD-ZTEXTP. "整单包装要求CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.* WA_ORDER_TEXT-doc_number = ''. "凭证号 = ⽂本名,创建时为空WA_ORDER_TEXT-ITM_NUMBER = SPACE. "space = 000000 代表抬头⽂本 WA_ORDER_TEXT-TEXT_ID = 'Z001'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = I_HEAD-ZTEXTD. "整单送货地址CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = SPACE. "space = 000000 代表抬头⽂本WA_ORDER_TEXT-TEXT_ID = 'Z002'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = I_HEAD-ZTEXTI. "整单开票要求CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = SPACE. "space = 000000 代表抬头⽂本WA_ORDER_TEXT-TEXT_ID = 'Z003'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = I_HEAD-ZTEXTO. "其他->整单参数特性CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = SPACE. "space = 000000 代表抬头⽂本WA_ORDER_TEXT-TEXT_ID = 'Z004'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP."SO HeaderCLEAR: WA_ORDER_HEADER_IN,WA_ORDER_HEADER_INX.WA_ORDER_HEADER_IN-DOC_TYPE = I_HEAD-AUART. "销售凭证类型WA_ORDER_HEADER_IN-CREATED_BY = I_HEAD-ERNAM. "创建⼈WA_ORDER_HEADER_IN-SALES_ORG = I_HEAD-VKORG. "销售组织WA_ORDER_HEADER_IN-SALES_GRP = I_HEAD-VKGRP. "销售组WA_ORDER_HEADER_IN-DISTR_CHAN = I_HEAD-VTWEG. "分销渠道WA_ORDER_HEADER_IN-DIVISION = I_HEAD-SPART. "产品组WA_ORDER_HEADER_IN-REQ_DATE_H = I_HEAD-VDATU. "请求交货⽇期WA_ORDER_HEADER_IN-DOC_DATE = SY-DATUM. "凭证时间WA_ORDER_HEADER_IN-ORD_REASON = I_HEAD-AUGRU. "订单原因WA_ORDER_HEADER_IN-CURRENCY = I_HEAD-WAERK. "销售和分销凭证货币WA_ORDER_HEADER_IN-PMNTTRMS = I_HEAD-ZTERM. "付款条件代码WA_ORDER_HEADER_IN-INCOTERMS1 = I_HEAD-INCO1. "国际贸易条款(第 1 部分)WA_ORDER_HEADER_IN-H_CURR = I_HEAD-WAERS. "货币码WA_ORDER_HEADER_INX-DOC_TYPE = ABAP_TRUE..WA_ORDER_HEADER_INX-SALES_ORG = ABAP_TRUE.WA_ORDER_HEADER_INX-DISTR_CHAN = ABAP_TRUE.WA_ORDER_HEADER_INX-DIVISION = ABAP_TRUE.WA_ORDER_HEADER_INX-REQ_DATE_H = ABAP_TRUE.WA_ORDER_HEADER_INX-DOC_DATE = ABAP_TRUE.WA_ORDER_HEADER_INX-ORD_REASON = ABAP_TRUE.WA_ORDER_HEADER_INX-CURRENCY = ABAP_TRUE.WA_ORDER_HEADER_INX-PMNTTRMS = ABAP_TRUE.WA_ORDER_HEADER_INX-INCOTERMS1 = ABAP_TRUE.WA_ORDER_HEADER_INX-H_CURR = ABAP_TRUE.WA_ORDER_HEADER_INX-H_CURR = ABAP_TRUE."SO PartnerI_HEAD-ZKUNNRSP = |{ I_HEAD-ZKUNNRSP ALPHA = IN }|.I_HEAD-ZKUNNRSH = |{ I_HEAD-ZKUNNRSH ALPHA = IN }|.SELECT KUNNR,ANRED,NAME1,LAND1,PSTLZ,ORT01,STRASFROM KNA1WHERE KUNNR = @I_HEAD-ZKUNNRSP* ,@I_HEAD-ZKUNNRSHINTO TABLE @DATA(LT_PARTNERS).CLEAR WA_ORDER_PARTNERS.READ TABLE LT_PARTNERS INTO DATA(WA_PARTNERS) WITH KEY KUNNR = I_HEAD-ZKUNNRSP. IF SY-SUBRC = 0.WA_ORDER_PARTNERS-PARTN_ROLE = 'AG'. "售达⽅WA_ORDER_PARTNERS-PARTN_NUMB = I_HEAD-ZKUNNRSP. "售达⽅代码WA_ORDER_PARTNERS-TITLE = WA_PARTNERS-ANRED. "抬头->公司WA_ORDER_PARTNERS-NAME = WA_PARTNERS-NAME1. "名称1WA_ORDER_PARTNERS-COUNTRY = WA_PARTNERS-LAND1. "国家代码WA_ORDER_PARTNERS-POSTL_CODE = WA_PARTNERS-PSTLZ. "邮政编码WA_ORDER_PARTNERS-CITY = WA_PARTNERS-ORT01. "城市WA_ORDER_PARTNERS-STREET = WA_PARTNERS-STRAS. "街道APPEND WA_ORDER_PARTNERS TO ORDER_PARTNERS.ELSE.RESULTCODE = 'E'.RESULTMSG = '售达⽅不存在'.O_VBELN = ''.RETURN.ENDIF.CLEAR: WA_ORDER_PARTNERS,WA_PARTNERS.READ TABLE LT_PARTNERS INTO WA_PARTNERS WITH KEY KUNNR = I_HEAD-ZKUNNRSH. IF SY-SUBRC = 0.WA_ORDER_PARTNERS-PARTN_ROLE = 'WE'. "送达⽅WA_ORDER_PARTNERS-PARTN_NUMB = I_HEAD-ZKUNNRSH. "送达⽅代码WA_ORDER_PARTNERS-TITLE = WA_PARTNERS-ANRED. "抬头->公司WA_ORDER_PARTNERS-NAME = WA_PARTNERS-NAME1. "名称1WA_ORDER_PARTNERS-COUNTRY = WA_PARTNERS-LAND1. "国家代码WA_ORDER_PARTNERS-POSTL_CODE = WA_PARTNERS-PSTLZ. "邮政编码WA_ORDER_PARTNERS-CITY = WA_PARTNERS-ORT01. "城市WA_ORDER_PARTNERS-STREET = WA_PARTNERS-STRAS. "街道APPEND WA_ORDER_PARTNERS TO ORDER_PARTNERS.ELSE.RESULTCODE = 'E'.RESULTMSG = '送达⽅不存在'.O_VBELN = ''.RETURN.ENDIF."SO Condition HeaderCLEAR: WA_ORDER_CONDITIONS_IN,WA_ORDER_CONDITIONS_INX.WA_ORDER_CONDITIONS_IN-ITM_NUMBER = SPACE. "⾏项⽬ space = 抬头WA_ORDER_CONDITIONS_IN-COND_TYPE = 'ZF01'. "运费WA_ORDER_CONDITIONS_IN-CURRENCY = I_HEAD-WAERS. "货币码/%WA_ORDER_CONDITIONS_IN-COND_VALUE = I_HEAD-ZYSJG. "运费价格WA_ORDER_CONDITIONS_INX-ITM_NUMBER = SPACE.WA_ORDER_CONDITIONS_INX-COND_TYPE = 'ZF01'.WA_ORDER_CONDITIONS_INX-CURRENCY = ABAP_TRUE.WA_ORDER_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.APPEND WA_ORDER_CONDITIONS_IN TO ORDER_CONDITIONS_IN.APPEND WA_ORDER_CONDITIONS_INX TO ORDER_CONDITIONS_INX.CLEAR: WA_ORDER_CONDITIONS_IN,WA_ORDER_CONDITIONS_INX.WA_ORDER_CONDITIONS_IN-ITM_NUMBER = SPACE. "⾏项⽬ space = 抬头WA_ORDER_CONDITIONS_IN-COND_TYPE = 'ZF02'. "保险费WA_ORDER_CONDITIONS_IN-CURRENCY = I_HEAD-WAERS. "货币码WA_ORDER_CONDITIONS_IN-COND_VALUE = I_HEAD-ZBXJG. "保险价格WA_ORDER_CONDITIONS_INX-ITM_NUMBER = SPACE.WA_ORDER_CONDITIONS_INX-COND_TYPE = 'ZF02'.WA_ORDER_CONDITIONS_INX-CURRENCY = ABAP_TRUE.WA_ORDER_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.APPEND WA_ORDER_CONDITIONS_IN TO ORDER_CONDITIONS_IN.APPEND WA_ORDER_CONDITIONS_INX TO ORDER_CONDITIONS_INX."SO ITEMLOOP AT T_ITEM INTO WA_ITEM.IF WA_ITEM-POSNR IS INITIAL.RESULTCODE = 'E'.RESULTMSG = |[LINE:{ SY-TABIX }]⾏项⽬号不允许为空|.O_VBELN = ''.RETURN.ENDIF."Item extenntionREAD TABLE GT_ZMPPZB INTO DATA(WA_ZMPPZB) WITH KEY ZMPXX = WA_ITEM-ZMPXX. IF SY-SUBRC = 0.CLEAR WA_EXTENSIONIN.WA_BAPE_VBAP-POSNR = WA_ITEM-POSNR.WA_BAPE_VBAP-ZMPXX = WA_ZMPPZB-ZMPXX.WA_BAPE_VBAP-ZMPGG = WA_ZMPPZB-ZMPGG.WA_BAPE_VBAP-ZMPDX = WA_ZMPPZB-ZMPDX.WA_BAPE_VBAP-ZMPBM = WA_ZMPPZB-ZMPBM.MOVE 'BAPE_VBAP' TO WA_EXTENSIONIN-STRUCTURE.CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_CEXPORTINGIM_VALUE = WA_BAPE_VBAPIMPORTINGEX_CONTAINER = WA_EXTENSIONIN-VALUEPART1.APPEND WA_EXTENSIONIN TO ORDER_EXTENSIONIN.CLEAR WA_EXTENSIONIN.WA_BAPE_VBAPX-POSNR = WA_ITEM-POSNR.WA_BAPE_VBAPX-ZMPXX = ABAP_TRUE.WA_BAPE_VBAPX-ZMPGG = ABAP_TRUE.WA_BAPE_VBAPX-ZMPDX = ABAP_TRUE.WA_BAPE_VBAPX-ZMPBM = ABAP_TRUE.MOVE 'BAPE_VBAPX' TO WA_EXTENSIONIN-STRUCTURE.MOVE WA_BAPE_VBAPX TO WA_EXTENSIONIN-VALUEPART1.APPEND WA_EXTENSIONIN TO ORDER_EXTENSIONIN.ELSE.RESULTCODE = 'E'.RESULTMSG = '铭牌选项未维护,请联系SD顾问'.O_VBELN = ''.RETURN.ENDIF."保存业务数据WA_DATA-SEQNR = GS_LOGS-SEQNR.WA_DATA-ZINDEX = WA_ITEM-POSNR.MOVE-CORRESPONDING I_HEAD TO WA_DATA.MOVE-CORRESPONDING WA_ITEM TO WA_DATA.WA_DATA-ZDATE = SY-DATUM.WA_DATA-ZTIME = SY-UZEIT.WA_DATA-ZUSER = SY-UNAME.APPEND WA_DATA TO GT_DATA.CLEAR WA_DATA.WA_ITEM-MATNR = |{ WA_ITEM-MATNR ALPHA = IN }|.WA_ORDER_ITEMS_IN-ITM_NUMBER = WA_ITEM-POSNR. "⾏项⽬WA_ORDER_ITEMS_IN-MATERIAL = WA_ITEM-MATNR. "物料编号WA_ORDER_ITEMS_IN-TARGET_QTY = WA_ITEM-DZMENG. "⽬标数量(采⽤销售单位)WA_ORDER_ITEMS_IN-TARGET_QU = WA_ITEM-VRKME. "数量单位WA_ORDER_ITEMS_IN-SALES_UNIT = WA_ITEM-VRKME. "销售单位WA_ORDER_ITEMS_IN-INCOTERMS2L = I_HEAD-INCO2. "国际贸易条款位置 1WA_ORDER_ITEMS_IN-PLANT = '1100'. "⼯⼚* WA_ORDER_ITEMS_IN-STORE_LOC = WA_ITEM-LGORT. "库存地* WA_ORDER_ITEMS_IN-BATCH = WA_ITEM-CHARG. "批次WA_ORDER_ITEMS_INX-ITM_NUMBER = ABAP_TRUE.WA_ORDER_ITEMS_INX-MATERIAL = ABAP_TRUE.WA_ORDER_ITEMS_INX-TARGET_QTY = ABAP_TRUE.WA_ORDER_ITEMS_INX-TARGET_QU = ABAP_TRUE.WA_ORDER_ITEMS_INX-SALES_UNIT = ABAP_TRUE.WA_ORDER_ITEMS_INX-INCOTERMS2L = ABAP_TRUE.WA_ORDER_ITEMS_INX-PLANT = ABAP_TRUE.APPEND WA_ORDER_ITEMS_IN TO ORDER_ITEMS_IN.APPEND WA_ORDER_ITEMS_INX TO ORDER_ITEMS_INX."SCHEDULE LineCLEAR WA_ORDER_SCHEDULES_IN.WA_ORDER_SCHEDULES_IN-ITM_NUMBER = WA_ITEM-POSNR. "⾏项⽬WA_ORDER_SCHEDULES_IN-REQ_QTY = WA_ITEM-DZMENG. "数量APPEND WA_ORDER_SCHEDULES_IN TO ORDER_SCHEDULES_IN.CLEAR WA_ORDER_SCHEDULES_INX.WA_ORDER_SCHEDULES_INX-ITM_NUMBER = ABAP_TRUE.WA_ORDER_SCHEDULES_INX-REQ_QTY = ABAP_TRUE.APPEND WA_ORDER_SCHEDULES_INX TO ORDER_SCHEDULES_INX."SO Condition ItemCLEAR: WA_ORDER_CONDITIONS_IN,WA_ORDER_CONDITIONS_INX.WA_ORDER_CONDITIONS_IN-ITM_NUMBER = WA_ITEM-POSNR. "⾏项⽬WA_ORDER_CONDITIONS_IN-COND_TYPE = 'ZR01'. "含税价格WA_ORDER_CONDITIONS_IN-CURRENCY = I_HEAD-WAERK. "货币码WA_ORDER_CONDITIONS_IN-COND_VALUE = WA_ITEM-KBETR. "含税单价* WA_ORDER_CONDITIONS_IN-cond_unit = ''. "条件单位* WA_ORDER_CONDITIONS_IN-cond_p_unt = ''. "条件定价单位WA_ORDER_CONDITIONS_INX-ITM_NUMBER = WA_ITEM-POSNR.WA_ORDER_CONDITIONS_INX-COND_TYPE = 'ZR01'.WA_ORDER_CONDITIONS_INX-CURRENCY = ABAP_TRUE.WA_ORDER_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.APPEND WA_ORDER_CONDITIONS_IN TO ORDER_CONDITIONS_IN.APPEND WA_ORDER_CONDITIONS_INX TO ORDER_CONDITIONS_INX.CLEAR: WA_ORDER_CONDITIONS_IN,WA_ORDER_CONDITIONS_INX.WA_ORDER_CONDITIONS_IN-ITM_NUMBER = WA_ITEM-POSNR. "⾏项⽬WA_ORDER_CONDITIONS_IN-COND_TYPE = 'ZK07'. "折扣WA_ORDER_CONDITIONS_IN-CURRENCY = ''. "货币码/% space = %WA_ORDER_CONDITIONS_IN-COND_VALUE = WA_ITEM-ZPERCNT."折扣⽐例 WA_ORDER_CONDITIONS_INX-ITM_NUMBER = WA_ITEM-POSNR.WA_ORDER_CONDITIONS_INX-COND_TYPE = 'ZK07'.WA_ORDER_CONDITIONS_INX-CURRENCY = ABAP_TRUE.WA_ORDER_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.APPEND WA_ORDER_CONDITIONS_IN TO ORDER_CONDITIONS_IN.APPEND WA_ORDER_CONDITIONS_INX TO ORDER_CONDITIONS_INX.CLEAR: WA_ORDER_CONDITIONS_IN,WA_ORDER_CONDITIONS_INX.WA_ORDER_CONDITIONS_IN-ITM_NUMBER = WA_ITEM-POSNR. "⾏项⽬WA_ORDER_CONDITIONS_IN-COND_TYPE = 'ZDPG'. "价格体系WA_ORDER_CONDITIONS_IN-CURRENCY = ''. "货币码/% space = %WA_ORDER_CONDITIONS_IN-COND_VALUE = WA_ITEM-ZZDPG. "客户折扣⽐例 WA_ORDER_CONDITIONS_INX-ITM_NUMBER = WA_ITEM-POSNR.WA_ORDER_CONDITIONS_INX-COND_TYPE = 'ZDPG'.WA_ORDER_CONDITIONS_INX-CURRENCY = ABAP_TRUE.WA_ORDER_CONDITIONS_INX-COND_VALUE = ABAP_TRUE.APPEND WA_ORDER_CONDITIONS_IN TO ORDER_CONDITIONS_IN.APPEND WA_ORDER_CONDITIONS_INX TO ORDER_CONDITIONS_INX."SO Item TextCLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = WA_ITEM-ZTEXTBD. "物料基本描述CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = WA_ITEM-POSNR. "⽂本⾏项⽬WA_ORDER_TEXT-TEXT_ID = 'GRUN'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = WA_ITEM-ZTEXTAB. "⾏参数特性要求CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = WA_ITEM-POSNR. "⽂本⾏项⽬WA_ORDER_TEXT-TEXT_ID = 'Z001'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = WA_ITEM-ZTEXTAD. "⾏送货地址CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = WA_ITEM-POSNR. "⽂本⾏项⽬ WA_ORDER_TEXT-TEXT_ID = 'Z002'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = WA_ITEM-ZTEXTW. "受托加⼯备注CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = WA_ITEM-POSNR. "⽂本⾏项⽬ WA_ORDER_TEXT-TEXT_ID = 'Z003'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR: WA_ORDER_TEXT,GV_LENGTH,GT_STRING,WA_STRING.LV_STRING = WA_ITEM-ZTEXTX. "⾏维修信息备注CALL FUNCTION 'SCMS_STRING_TO_FTEXT'EXPORTINGTEXT = LV_STRINGIMPORTINGLENGTH = LV_LENGTHTABLESFTEXT_TAB = LT_STRING. "132长度切割⼀次LOOP AT LT_STRING INTO WA_STRING.CLEAR WA_ORDER_TEXT.WA_ORDER_TEXT-ITM_NUMBER = WA_ITEM-POSNR. "⽂本⾏项⽬ WA_ORDER_TEXT-TEXT_ID = 'Z007'. "⽂本IDWA_ORDER_TEXT-LANGU = 1. "语⾔代码1->中⽂WA_ORDER_TEXT-LANGU_ISO = 'ZH'. "语⾔ISO代码->zhIF SY-TABIX = 1.WA_ORDER_TEXT-FORMAT_COL = '*'. "标记列ELSE.WA_ORDER_TEXT-FORMAT_COL = '/'.ENDIF.WA_ORDER_TEXT-TEXT_LINE = WA_STRING.APPEND WA_ORDER_TEXT TO ORDER_TEXT.ENDLOOP.CLEAR WA_ITEM.ENDLOOP.CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'EXPORTINGaSALES_HEADER_IN = WA_ORDER_HEADER_INSALES_HEADER_INX = WA_ORDER_HEADER_INXCONVERT_PARVW_AUART = ABAP_ONLOGIC_SWITCH = WA_LOGIC_SWITCHIMPORTINGSALESDOCUMENT_EX = GV_SALESDOCUMENT_EXTABLESRETURN = RETURNSALES_ITEMS_IN = ORDER_ITEMS_INSALES_ITEMS_INX = ORDER_ITEMS_INXSALES_SCHEDULES_IN = ORDER_SCHEDULES_INSALES_SCHEDULES_INX = ORDER_SCHEDULES_INXSALES_CONDITIONS_IN = ORDER_CONDITIONS_INSALES_CONDITIONS_INX = ORDER_CONDITIONS_INXEXTENSIONIN = ORDER_EXTENSIONINSALES_PARTNERS = ORDER_PARTNERSSALES_TEXT = ORDER_TEXT.IF SY-SUBRC = 0 AND GV_SALESDOCUMENT_EX IS NOT INITIAL.RESULTCODE = 'S'.RESULTMSG = '销售订单创建成功'.O_VBELN = GV_SALESDOCUMENT_EX.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGWAIT = 'X'.ELSE.SELECT SINGLE *FROM @RETURN AS AWHERE TYPE = 'E'INTO @WA_RETURN.RESULTCODE = 'E'.RESULTMSG = |[MESSAGE NO.{ WA_RETURN-ID }{ WA_RETURN-NUMBER }]{ WA_RETURN-MESSAGE }|. O_VBELN = GV_SALESDOCUMENT_EX.CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.ENDIF.* 添加⽇志表记录GS_LOGS-SEQNR = GS_LOGS-SEQNR.GS_LOGS-ZIFNAME = 'ZSD_IF0012'.GS_LOGS-ZSYSTEM = 'CRM/SAP'.* 1代表调⽤其他系统接⼝,2代表被其他系统调⽤GS_LOGS-ZCALL = '2'.GS_LOGS-ZTYPE = RESULTCODE.GS_LOGS-ZMSG = RESULTMSG.GS_LOGS-ZDATE = SY-DATUM.GS_LOGS-ZTIME = SY-UZEIT.GS_LOGS-ZUSER = SY-UNAME.GS_LOGS-ZVALUE1 = 'CRM->SAP 销售订单创建接⼝'.GS_LOGS-ZVALUE2 = O_VBELN. " 销售订单号* 对应业务数据表GS_LOGS-ZTBNAME = 'ZSDT_CRM_IF012'.MODIFY ZALL_LOGS FROM GS_LOGS.MODIFY ZSDT_CRM_IF012 FROM TABLE GT_DATA.ENDFUNCTION.。
(仅供参考)SAP系统采购订单操作
采购订单流程1、目的:处理采购业务2、适用范围:所有采购业务的处理3、文件内容概述:⑴ 维护信息记录⑵ 根据第三方销售产生的采购申请创建采购定单、或者无参考创建采购订单⑶ 对采购定单收货⑷ 对采购定单做发票校验⑸ 创建固定资产的采购订单⑹ 打印采购订单4、流程操作步骤:(举例:公司代码1713、物料:60001、供应商1700)⑴ 维护信息记录操作见文档“维护信息记录主数据”采购信息记录被创建:5300000001⑵ 创建采购订单(有两种方式创建采购定单)① 根据采购申请单创建采购订单(查询采购申请单事务码:ME5A)系统路径 后勤—商品管理—采购—采购订单—创建—已知供应商/供应地点 事务码 ME21N按照系统路径或事务码操作进入如下屏幕:单击“”选择变式按钮,选择“采购申请”,进入下一屏幕:栏目名称 描述 R/O/N用户动作或结果 注意事项地点 O商品 O采购申请号 O 10000089 如果输入采购申请号,则其他字段不需要维护采购组织 O采购组 O回车,进入下一界面:将鼠标放置采购申请号10000089上方,按住左键不放将申请单号拖到“标准采购订单”左侧的方框内,进入下一界面:特别说明:●如果此采购申请单没有分配供应商,则需要输入“供应商”、“采购组织”●若采购的物料直接核算到费用中,则字段“A”输入:K成本中心●如果行项目的产品属于供应商赠送的,则在字段“免费”前打勾●“PO数量”可以根据实际采购的数量修改●如果这张采购申请单是手工创建或者运行MRP之后产生的,则允许一帐采购申请转换成多帐采购订单;如果采购申请单是第三方销售产生的,则一张采购申请单只能用于参考创建一次采购订单,不能多次创建,所以更改采购数量一定要谨慎。
保存,系统提示:② 手工创建采购订单系统路径 后勤—商品管理—采购—采购订单—创建—已知供应商/供应地点 事务码 ME21N按照系统路径或事务码操作进入如下屏幕:① 供应商:1700 ② 维护“抬头”参数:“机构数据”视图:栏目名称 描述R/O/N 用户动作或结果 注意事项采购组织 R 1000 采购组 R 713 公司代码R1713③ 行项目数据参数: 栏目名称描述R/O/N用户动作或结果注意事项抬头项目细节行项目只能选择“标准采购定单”A 帐户设置分类 O 如果物料直接核算到费用中,则输入K(成本中心)物料 物料号 R 60001PO数量 采购数量 R 1000OUN 单位 0 根据实际情况更改工厂 R 1713交货日期 O 根据实际情况更改免费 O 如果行项目的产品属于供应商赠送的,则在字段“免费”前打勾④ 项目细节参数:可以根据实际情况更改单价等如果没有维护信息记录,则需要维护“条件”视图:栏目名称 描述 R/O/N用户动作或结果 注意事项类型 价格类型 PBXX(总价格) PBXX或PB00(总价格)价格 物料单价 5 供应商发票为增值税发票则输入“无税单价”;普通发票则输入“总价”保存,系统提示:⑶ 对采购订单收货:有两种收货的方式:A.收货保存之后从财务的角度分析物料增加了库存,即反映到物料库存的质检状态或非限制状态B.收货保存之后从财务的角度分析物料没有增加库存,只是反映到GR冻结库存,待物料检验合格之后再下达冻结库存,增加物料的实际库存以下根据两种收货方式分别讲解:方式A:收货保存之后从财务的角度分析物料增加了库存,即反映到物料库存的质检状态或非限制状态系统路径 后勤—商品管理—库存管理—货物移动—货物移动(MIGO)事务码 MIGO按照系统路径或事务码操作进入如下屏幕:“采购订单”字段输入:4500000101“移动类型”:101(按采购定单收货到库存) (移动类型102:冲销101)回车,屏幕如下:栏目名称 描述 R/O/N用户动作或结果 注意事项OK 确定数据是否无误 R 选中 不选中表示不对此行项目收货UOE的量 实际收货数量 R 10批次 O 8899 如果物料进行了批量管理,则必须输入批次;没有进行栏目名称 描述 R/O/N用户动作或结果 注意事项批量管理的物料不要维护批次库存类型库存状态 O 一般选择“非限制使用”或“质量检验”状态生产日期 O 2003.07.01 如果物料进行批次管理,则必须输入生产日期,否则不需维护保存时提示,产生了物料凭证和财务凭证。
ME21N USING BAPI_PO_CREATE1
*&--------------------------------------------------------------**& FUNCTION:ZRFC_MM_ME21N*& Module : Function Group 2012*$ Short Text Create Purchase Order*& Function Group ZGRFC_MM*& Maraco MC_CONDITION_INSERT*& Short Text 创建采购订单函数*&--------------------------------------------------------------**& Created : Gary.C (2008.07.29) From Hanhe Information Technoligy CD. LTD.*& Modified : Name (Date) From* Intention : 1. User could use this function to create purchase order.*&--------------------------------------------------------------*FUNCTION zrfc_mm_me21n.*"---------------------------------------------------------------------- *"*"Local interface:*" IMPORTING*" VALUE(PO_HEADER) LIKE BAPIMEPOHEADER STRUCTURE BAPIMEPOHEADER*" OPTIONAL*" VALUE(PO_HEADERX) LIKE BAPIMEPOHEADERX STRUCTURE*" BAPIMEPOHEADERX OPTIONAL*" EXPORTING*" VALUE(EP_PONUMBER) LIKE BAPIMEPOHEADER-PO_NUMBER*" VALUE(EP_MSG) TYPE CHAR255*" VALUE(EP_SUBRC) LIKE SY-SUBRC*" VALUE(EP_FRGKE) LIKE EKKO-FRGKE*" TABLES*" ET_LOG STRUCTURE BAPIRET2 OPTIONAL*" IT_POITEM STRUCTURE ZBAPIMEPOITEM OPTIONAL*" IT_POITEMX STRUCTURE BAPIMEPOITEMX OPTIONAL*" IT_POCOND STRUCTURE BAPIMEPOCOND OPTIONAL*" IT_POCONDX STRUCTURE BAPIMEPOCONDX OPTIONAL*" IT_DELIVERY_SCHEDULE STRUCTURE BAPIMEPOSCHEDULE OPTIONAL*" IT_DELIVERY_SCHEDULEX STRUCTURE BAPIMEPOSCHEDULX OPTIONAL*" IT_POHEADER_TEXT STRUCTURE ZRFC_ME21N_TEXTSEVICE OPTIONAL*" IT_POITEM_TEXT STRUCTURE ZRFC_ME21N_TEXTSEVICE1 OPTIONAL*" IT_PO_REL_CODE STRUCTURE ZRFC_ME21N_REL_CODE OPTIONAL*" IT_POITEMCOND STRUCTURE ZME21NPOCOND OPTIONAL*"----------------------------------------------------------------------*&---------------------------------Global variant-----------------------------*DATA: gp_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,gp_potext_header LIKE bapimepotextheader OCCURS 0 WITH HEADER LINE,gp_potext_item LIKE bapimepotext OCCURS 0 WITH HEADER LINE.DATA: gc_vendor LIKE lfa1-lifnr,gc_country LIKE lfa1-land1,gc_frgke LIKE ekko-frgke.CLEAR gc_country.*&---------------------------------Po Header-----------------------------* po_headerx-doc_type = 'X'. "Document_type.po_headerx-vendor = 'X'. "Supplyer.po_headerx-purch_org = 'X'. "Purchase orgnization.po_headerx-pur_group = 'X'. "Purchase Group*&-----addition_datapo_headerx-vper_start = 'X'. "validity date start.po_headerx-vper_end = 'X'. "validity date end.*&-----Paymentpo_headerx-pmnttrms = 'X'. "Code for Paymentpo_headerx-incoterms1 = 'X'. "Interetional incoming terms 1po_headerx-incoterms2 = 'X'. "Interetional incoming terms 2*&-----Add ZeroPERFORM f_add_zero USING po_header-vendor.PERFORM f_add_zero USING po_header-purch_org.*&---------------------------------Po Item-----------------------------* IF it_poitem[] IS INITIAL.ep_msg = '行项目不能为空'.ep_subrc = -1.EXIT.ENDIF.LOOP AT it_poitem.it_poitem-po_item(4) = sy-tabix. "Po item No.it_poitemx-po_item(4) = sy-tabix.it_poitemx-po_itemx = 'X'. "Po item Noit_poitemx-material = 'X'. "Material No.it_poitemx-quantity = 'X'. "Quantityit_poitemx-net_price = 'X'. "Net Priceit_poitemx-plant = 'X'. "Plant.it_poitemx-preq_name = 'X'. "Prchase_Requirmenter's Name .it_poitemx-preq_no = 'X'. "Prchase_Requirment No.it_poitemx-preq_item = 'X'. "Prchase_Requirment Item.*&-----Detailit_poitemx-over_dlv_tol = 'X'. "Over Delivery Toleranceit_poitemx-under_dlv_tol = 'X'. "Under Delivery Tolerance*&-----Tax Codeit_poitemx-tax_code = 'X'. "Tax Code*&-----Add ZeroPERFORM f_add_zero USING it_poitem-material.PERFORM f_add_zero USING it_poitem-preq_no.MODIFY it_poitem.APPEND it_poitemx.ENDLOOP.*&-----Delivery ScheduleIF it_delivery_schedule[] IS INITIAL.ep_msg = '请输入行项目交货计划日期'.ep_subrc = -1.EXIT.ENDIF.LOOP AT it_delivery_schedule.it_delivery_schedule-po_item(4) = sy-tabix. "Po item No.it_delivery_schedulex-po_item(4) = sy-tabix.it_delivery_schedulex-po_itemx = 'X'.it_delivery_schedulex-delivery_date = 'X'. "Delivery_Date.MODIFY it_delivery_schedule.APPEND it_delivery_schedulex.ENDLOOP.*&---------------------------------Text-service-----------------------------* *&---Po_Header_TextLOOP AT it_poheader_text. "PO抬头文本---活价标识F01IF it_poheader_text-text_head01 IS NOT INITIAL.gp_potext_header-text_line = it_poheader_text-text_head01.gp_potext_header-text_id = 'F01'.APPEND gp_potext_header.ENDIF.IF it_poheader_text-text_head02 IS NOT INITIAL. "PO抬头文本---保险费F02gp_potext_header-text_line = it_poheader_text-text_head02.gp_potext_header-text_id = 'F02'.APPEND gp_potext_header.ENDIF.IF it_poheader_text-text_head03 IS NOT INITIAL. "PO抬头文本---码头、港建费F03 gp_potext_header-text_line = it_poheader_text-text_head03.gp_potext_header-text_id = 'F03'.APPEND gp_potext_header.ENDIF.IF it_poheader_text-text_head04 IS NOT INITIAL. "PO抬头文本---商检费F04gp_potext_header-text_line = it_poheader_text-text_head04.gp_potext_header-text_id = 'F04'.APPEND gp_potext_header.ENDIF.IF it_poheader_text-text_head05 IS NOT INITIAL. "PO抬头文本---采购类型F05gp_potext_header-text_line = it_poheader_text-text_head05.gp_potext_header-text_id = 'F05'.APPEND gp_potext_header.ENDIF.IF it_poheader_text-text_head06 IS NOT INITIAL. "PO抬头文本---发运地F06gp_potext_header-text_line = it_poheader_text-text_head06.gp_potext_header-text_id = 'F06'.APPEND gp_potext_header.ENDIF.IF it_poheader_text-text_head07 IS NOT INITIAL. "PO抬头文本---备注F07gp_potext_header-text_line = it_poheader_text-text_head07.gp_potext_header-text_id = 'F07'.APPEND gp_potext_header.ENDIF.IF it_poheader_text-text_head08 IS NOT INITIAL. "PO抬头文本---合同号F08gp_potext_header-text_line = it_poheader_text-text_head08.gp_potext_header-text_id = 'F08'.APPEND gp_potext_header.ENDIF.ENDLOOP.LOOP AT it_poitem_text. "Warning:Po_Number And Po_item must reference to IT_POITEM-PO_ITEM.IF it_poitem_text-text_item01 IS NOT INITIAL. "采购单行项目文本----运费f01gp_potext_item-text_line = it_poitem_text-text_item01.gp_potext_item-po_item = it_poitem_text-po_item.gp_potext_item-text_id = 'F01'.APPEND gp_potext_item.ENDIF.IF it_poitem_text-text_item02 IS NOT INITIAL. "采购单行项目文本----运输方式F02gp_potext_item-text_line = it_poitem_text-text_item02.gp_potext_item-po_item = it_poitem_text-po_item.gp_potext_item-text_id = 'F02'.APPEND gp_potext_item.ENDIF.IF it_poitem_text-text_item03 IS NOT INITIAL. "采购单行项目文本----费用支付情况F03 gp_potext_item-text_line = it_poitem_text-text_item03.gp_potext_item-po_item = it_poitem_text-po_item.gp_potext_item-text_id = 'F03'.APPEND gp_potext_item.ENDIF.IF it_poitem_text-text_item04 IS NOT INITIAL. "采购单行项目文本----备注F04gp_potext_item-text_line = it_poitem_text-text_item04.gp_potext_item-po_item = it_poitem_text-po_item.gp_potext_item-text_id = 'F04'.APPEND gp_potext_item.ENDIF.IF it_poitem_text-text_item05 IS NOT INITIAL. "采购单行项目文本----杂费F05gp_potext_item-text_line = it_poitem_text-text_item05.gp_potext_item-po_item = it_poitem_text-po_item.gp_potext_item-text_id = 'F05'.APPEND gp_potext_item.ENDIF.IF it_poitem_text-text_item06 IS NOT INITIAL. "采购单行项目文本----车船号F06gp_potext_item-text_line = it_poitem_text-text_item06.gp_potext_item-po_item = it_poitem_text-po_item.gp_potext_item-text_id = 'F06'.APPEND gp_potext_item.ENDIF.IF it_poitem_text-text_item07 IS NOT INITIAL. "采购单行项目文本----质量标准F07gp_potext_item-text_line = it_poitem_text-text_item07.gp_potext_item-po_item = it_poitem_text-po_item.gp_potext_item-text_id = 'F07'.APPEND gp_potext_item.ENDIF.ENDLOOP.*&---------------------------------Check Input-----------------------------*IF po_header-incoterms1 IS NOT INITIAL.IF po_header-incoterms2 IS INITIAL .ep_msg = '请检查国际贸易付款条件的输入'.ep_subrc = -1.EXIT.ENDIF.ENDIF.gc_vendor = po_header-vendor.SELECT SINGLE lfa1~land1 INTO gc_country FROM lfa1 WHERE lfa1~lifnr = gc_vendor.IF gc_country EQ 'CN'.READ TABLE it_poitem WITH KEY tax_code = ''.IF sy-subrc = 0.ep_msg = '请输入税务代码'.ep_subrc = -1.EXIT.ENDIF.ENDIF.*&---------------------------------Condition-----------------------------*LOOP AT it_poitem.IF gc_country EQ 'CN'.mc_condition_insert it_poitem-pbxx_value it_poitem-pbxx_unit 'PBXX'. "总价格:单价(元/吨)* mc_condition_insert it_poitem-znf101_value it_poitem-znf101_unit 'ZNF1'. "进项增值税mc_condition_insert it_poitem-znf501_value it_poitem-znf501_unit 'ZNF5'. "运费(值)mc_condition_insert it_poitem-znf6_value it_poitem-znf6_unit 'ZNF6'. "运费/数量mc_condition_insert it_poitem-znf401_value it_poitem-znf401_unit 'ZNF4'. "运费税率 %, 默认7.0% mc_condition_insert it_poitem-znf701_value it_poitem-znf701_unit 'ZNF7'. "杂费(值)* mc_condition_insert it_poitem-znfb01_value it_poitem-znfb01_unit 'ZNFB'. "不含税运费mc_condition_insert it_poitem-znf801_value it_poitem-znf801_unit 'ZNF8'. "杂费(数量)ELSE.mc_condition_insert it_poitem-pbxx_value it_poitem-pbxx_unit 'PBXX'. "总价格:单价(元/吨)mc_condition_insert it_poitem-znf202_value it_poitem-znf202_unit 'ZNF2'. "关税mc_condition_insert it_poitem-znf302_value it_poitem-znf302_unit 'ZNF3'. "消费税mc_condition_insert it_poitem-znf902_value it_poitem-znf902_unit 'ZNF9'. "保险费/数量mc_condition_insert it_poitem-znfa02_value it_poitem-znfa02_unit 'ZNFA'. "其它费用/数量mc_condition_insert it_poitem-znfc02_value it_poitem-znfc02_unit 'ZNFC'. "其它费用(值) mc_condition_insert it_poitem-znf6_value it_poitem-znf6_unit 'ZNF6'. "运费/数量ENDIF.ENDLOOP.*&---------------------------------Date Translation-----------------------------*CALL FUNCTION 'BAPI_PO_CREATE1'EXPORTINGpoheader = po_headerpoheaderx = po_headerxno_price_from_po = 'X'IMPORTINGexppurchaseorder = ep_ponumberTABLESreturn = et_logpoitem = it_poitempoitemx = it_poitemxposchedule = it_delivery_scheduleposchedulex = it_delivery_schedulexpotextheader = gp_potext_headerpotextitem = gp_potext_itempocond = it_pocondpocondx = it_pocondxEXCEPTIONSOTHERS = -1.IF ep_ponumber NE space.READ TABLE et_log WITH KEY type = 'E'.IF sy-subrc = 0.ep_msg = '无法创建采购订单,请查看错误日志'.ep_subrc = -1.ROLLBACK WORK.ELSE.LOOP AT et_log.IF et_log-type = 'W'.ep_msg = '订单已经成功创建但出现系统警告,请查看ET_LOG日志'.ep_subrc = 0.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.ELSE.* READ TABLE et_log WITH KEY type = 'E'.* IF sy-subrc = 0.* ep_msg = '无法创建采购订单,请查看错误日志'.* ep_subrc = -1.* ROLLBACK WORK.ep_msg = '创建采购订单成功'.ep_subrc = 0.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.ENDIF.ENDLOOP.ENDIF.ELSE.ROLLBACK WORK.ep_msg = '创建采购订单失败,请查看错误日志'.ep_subrc = -1.EXIT.ENDIF.****&---------------------------------Po Release status-----------------------------* IF ep_subrc = 0.SELECT SINGLE ekko~frgke INTO gc_frgke FROM ekko WHERE ekko~ebeln = ep_ponumber.ep_frgke = gc_frgke.ENDIF.**&---------------------------------Po Release-----------------------------** LOOP AT it_po_rel_code.* CALL FUNCTION 'BAPI_PO_RELEASE'* EXPORTING* purchaseorder = ep_ponumber* po_rel_code = it_po_rel_code-rel_code** USE_EXCEPTIONS = 'X'** NO_COMMIT = ' '** IMPORTING** REL_STATUS_NEW =** REL_INDICATOR_NEW =** RET_CODE =** TABLES** RETURN =** EXCEPTIONS** AUTHORITY_CHECK_FAIL = 1** DOCUMENT_NOT_FOUND = 2** ENQUEUE_FAIL = 3** PREREQUISITE_FAIL = 4** RELEASE_ALREADY_POSTED = 5** RESPONSIBILITY_FAIL = 6** OTHERS = 7* .** ENDLOOP.**----------------------mc_condition_insert------------------ DEFINE mc_condition_insert.if ( &1 is not initial ) or ( &2 is not initial ).it_pocond-itm_number = it_poitem-po_item.it_pocond-cond_type = &3 .it_pocond-cond_value = &1. "it_poitem-pbxx01_value.it_pocond-cond_unit = &2 . "it_poitem-pbxx01_unit.it_pocond-change_id = 'U'.it_pocond-currency = &4.it_pocond-cond_p_unt = &5.append it_pocond.it_pocondx-itm_number = it_poitem-po_item.it_pocondx-change_id = 'X'.* it_pocondx-itm_number = 'X'.it_pocondx-itm_numberx = 'X'.it_pocondx-cond_type = 'X'. "Condition type.if &4 is not initial.it_pocondx-currency = 'X'.endif.if &1 is not initial.it_pocondx-cond_value = 'X'. "Condition value.endif.*** it_pocondx-currency = 'X'. "Currency*** it_pocondx-cond_p_unt = 'X'. "Condition per unit if &2 is not initial.it_pocondx-cond_unit = 'X'. "Condition unit.endif.if &5 is not initial.it_pocondx-cond_p_unt = 'X'. "Condition value. endif.append it_pocondx.endif.END-OF-DEFINITION.ENDFUNCTION.。
[BAPI]使用BAPI_GOODSMVT_CREATE创建委外订单(subcontrac。。。
[BAPI]使⽤BAPI_GOODSMVT_CREATE创建委外订单(subcontrac。
下⾯介绍⼀下使⽤bapi BAPI_GOODSMVT_CREATE为委外订单创建物料移动凭证。
例⼦代码:*&---------------------------------------------------------------------**& Report YTEST_SUBCONTRACT_MIGO*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT ytest_subcontract_migo.DATA:lt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE,l_doc TYPE mseg-mblnr,l_year TYPE mseg-mjahr,lt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create WITH HEADER LINE,lwa_header TYPE bapi2017_gm_head_01,lwa_code TYPE bapi2017_gm_code.DATA:l_line_id TYPE mseg-line_id VALUE '000000',l_parent_id TYPE mseg-parent_id VALUE '000000',l_line_depth TYPE mseg-line_depth VALUE '00'.lwa_code-gm_code = '01' . "MB01lwa_header-pstng_date = sy-datum. "凭证中的过帐⽇期lwa_header-doc_date = sy-datum. "凭证中的凭证⽇期lwa_header-pr_uname = sy-uname. "⽤户名lwa_header-ref_doc_no = '123456'. "参考订单lwa_header-header_txt = 'Header text'. "抬头⽂本* 物料lt_item-material = '000000410000000043'.* ⼯⼚lt_item-plant = '1286'.* 批次号lt_item-batch = '1808031000'.* 移动类型lt_item-move_type = '101'.* 库存地点lt_item-stge_loc = '1103'.* 基本单位数量lt_item-entry_qnt = 57040.* 输⼊单位lt_item-entry_uom = 'KG'.* 订单单位数量lt_item-po_pr_qnt = 57040.* 订单价格单位(采购)lt_item-orderpr_un = 'KG'.* 采购订单号lt_item-po_number = 4400000011.* 采购凭证的项⽬编号lt_item-po_item = '00010'.lt_item-mvt_ind = 'B'.* 凭证⾏的唯⼀标识l_line_id = l_line_id + 1.l_parent_id = l_line_id.lt_item-line_id = l_line_id.APPEND lt_item.CLEAR:lt_item.lt_item-move_type = '543'.* 物料编号lt_item-material = '000000410000000044'.* ⼯⼚lt_item-plant = '1286'.lt_item-spec_stock = 'O'.* 批次号lt_item-batch = '0000000004'.* 数量lt_item-entry_qnt = 3600.* 基本计量单位lt_item-entry_uom = 'KG'.* 上⼀⾏的识别码lt_item-parent_id = l_parent_id.* 凭证⾏的唯⼀标识l_line_id = l_line_id + 1.lt_item-line_id = l_line_id.* 凭证中⾏层次结构级别l_line_depth = '01'.lt_item-line_depth = l_line_depth.APPEND lt_item.CALL FUNCTION'BAPI_GOODSMVT_CREATE'EXPORTINGgoodsmvt_header = lwa_headergoodsmvt_code = lwa_code* TESTRUN = ' '* GOODSMVT_REF_EWM =* GOODSMVT_PRINT_CTRL =IMPORTING* GOODSMVT_HEADRET =materialdocument = l_docmatdocumentyear = l_yearTABLESgoodsmvt_item = lt_itemreturn = lt_return.LOOP AT lt_return WHERE type CA 'AEX'.EXIT.ENDLOOP.IF sy-subrc = 0.CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK'.WRITE:'Failed'.ELSE.CALL FUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.WRITE:'物料凭证号:', l_doc.ENDIF.代码不复杂,需要注意的是字段line_id,parent_id,line_depth要填写正确,line_id是⽤来唯⼀标识⾏项⽬的,委外⾏要正确制定上层⾏项⽬ID,也就是把上层⾏项⽬的line_ID填到委外⾏的parent_ID字段中,line_depth也要按层次填⼊01...如果⾏项⽬字段填写不正确有时会出现M7 387错误。
使用BAPI_PO_CREATE1批量创建采购订单(1)
使用BAPI_PO_CREATE1批量创建采购订单(1)使用BAPI_PO_CREATE1批量创建采购订单*&---------------------------------------------------------------------**& Report ZMM_UPLOAD_PO*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT zmm_upload_po.DATA:BEGIN OF gt_data OCCURS 0,bsart TYPE string,"采购凭证类型lifnr TYPE string,"供应商帐户号ekorg TYPE string,"采购组织ekgrp TYPE string,"采购组bukrs TYPE string,"公司代码ihrez TYPE string,"您的参考ebelp TYPE string,"采购凭证的项目编号knttp TYPE string,"科目分配类别txz01 TYPE string,"短文本menge TYPE string,"采购订单数量meins TYPE string,"采购订单的计量单位eeind TYPE string,"交货日期Wnetpr TYPE string,"净价waers TYPE string,"货币 Wmatkl TYPE string,"物料组werks TYPE string,"工厂bednr TYPE string,"需求跟踪号afnam TYPE string,"需求者/请求者姓名mwskz TYPE string,"销售税代码sakto TYPE string,"总帐科目kostl TYPE string,"成本中心anln1 TYPE string,"资产aufnr TYPE string,"订单str1 TYPE string,"行项目文本-来自采购申请项目详细清单str2 TYPE string,"行项目文本-规格型号str3 TYPE string,"行项目文本-RFQ Referencebstae TYPE string,"确认控制END OF gt_data.DATA: BEGIN OF gt_out OCCURS 0,text(255),END OF gt_out.DATA: poheader LIKE TABLE OF bapimepoheader WITH HEADER LINE , poheaderx LIKE TABLE OF bapimepoheaderx WITH HEADER LINE, return LIKE TABLE OF bapiret2 WITH HEADER LINE,poitem LIKE TABLE OF bapimepoitem WITH HEADER LINE,poitemx LIKE TABLE OF bapimepoitemx WITH HEADER LINE, poschedule LIKE TABLE OF bapimeposchedule WITH HEADER LINE, poschedulex LIKE TABLE OF bapimeposchedulx WITH HEADER LINE, poaccount LIKE TABLE OF bapimepoaccount WITH HEADER LINE, poaccountx LIKE TABLE OF bapimepoaccountx WITH HEADER LINE, pocond LIKE TABLE OF bapimepocond WITH HEADER LINE,pocondx LIKE TABLE OF bapimepocondx WITH HEADER LINE, potextitem LIKE TABLE OF bapimepotext WITH HEADER LINE. DATA: epo LIKE bapimepoheader-po_number.DATA: l_return LIKE return.DATA: lv_message(255).CONSTANTS: con VALUE 'X'.DATA: pp_file TYPE string.DATA: lifnr TYPE elifn.DATA: netpr TYPE bprei.DATA: bstae TYPE bstae.PARAMETERS:p_file(128) .AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.PERFORM get_file.START-OF-SELECTION.PERFORM get_data.PERFORM create_po.PERFORM write_out.*&---------------------------------------------------------------------**& Form GET_FILE*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM get_file .CALL FUNCTION 'WS_FILENAME_GET'EXPORTINGdef_filename = p_filemask = ',*.txt,*.TXT.'mode = 'O'title = 'File Name'IMPORTINGfilename = p_fileEXCEPTIONSinv_winsys = 1no_batch = 2selection_cancel = 3selection_error = 4OTHERS = 5.pp_file = p_file.ENDFORM. " GET_FILE*&---------------------------------------------------------------------**& Form GET_DATA*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM get_data .CALL FUNCTION 'GUI_UPLOAD'EXPORTINGfilename = pp_filefiletype = 'ASC'has_field_separator = 'X'* HEADER_LENGTH = 0read_by_line = 'X'* DAT_MODE = ' '* CODEPAGE = ' '* IGNORE_CERR = ABAP_TRUE* REPLACEMENT = '#'* CHECK_BOM = ' '* VIRUS_SCAN_PROFILE =* NO_AUTH_CHECK = ' '* IMPORTING* FILELENGTH =* HEADER =TABLESdata_tab = gt_dataEXCEPTIONSfile_open_error = 1file_read_error = 2no_batch = 3gui_refuse_filetransfer = 4invalid_type = 5no_authority = 6unknown_error = 7bad_data_format = 8header_not_allowed = 9separator_not_allowed = 10header_too_long = 11unknown_dp_error = 12access_denied = 13dp_out_of_memory = 14disk_full = 15dp_timeout = 16OTHERS = 17.IF sy-subrc <> 0.CASE sy-subrc.WHEN 1.MESSAGE 'FILE_OPEN_ERROR ' TYPE 'E'.WHEN 2.MESSAGE 'FILE_READ_ERROR ' TYPE 'E'.WHEN 3.MESSAGE 'NO_BATCH' TYPE 'E'.WHEN 4.MESSAGE 'GUI_REFUSE_FILETRANSFER ' TYPE 'E'. WHEN 5.MESSAGE 'INVALID_TYPE ' TYPE 'E'.WHEN 6.MESSAGE ' NO_AUTHORITY' TYPE 'E'.WHEN 7.MESSAGE 'UNKNOWN_ERROR' TYPE 'E'.WHEN 8.MESSAGE 'BAD_DATA_FORMAT ' TYPE 'E'.WHEN 9.MESSAGE 'HEADER_NOT_ALLOWED' TYPE 'E'.WHEN 10.MESSAGE 'SEPARATOR_NOT_ALLOWED' TYPE 'E'.WHEN 11.MESSAGE 'HEADER_TOO_LONG ' TYPE 'E'.WHEN 12.MESSAGE 'UNKNOWN_DP_ERROR' TYPE 'E'.WHEN 13.MESSAGE ' ACCESS_DENIED ' TYPE 'E'.WHEN 14.MESSAGE 'DP_OUT_OF_MEMORY ' TYPE 'E'.WHEN 15.MESSAGE 'DISK_FULL ' TYPE 'E'.WHEN 16.MESSAGE 'DP_TIMEOUT' TYPE 'E'.WHEN 17.MESSAGE ' OTHERS ' TYPE 'E'.WHEN OTHERS.ENDCASE.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.ENDFORM. " GET_DATA*&---------------------------------------------------------------------**& Form CREATE_PO*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM create_po .LOOP AT gt_data.AT NEW ihrez.CLEAR lifnr.lifnr = gt_data-lifnr.CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'EXPORTINGinput = lifnrIMPORTINGoutput = lifnr.poheader-doc_type = gt_data-bsart.poheader-vendor = lifnr.poheader-purch_org = gt_data-ekorg.poheader-pur_group = gt_data-ekgrp.poheader-comp_code = gt_data-bukrs.poheader-ref_1 = gt_data-ihrez.poheader-doc_date = sy-datum.poheader-langu = sy-langu.poheader-currency = gt_data-waers."货币poheaderx-doc_type = con.poheaderx-vendor = con.poheaderx-purch_org = con.poheaderx-pur_group = con.poheaderx-comp_code = con.poheaderx-ref_1 = con.poheaderx-doc_date = con.poheaderx-langu = con.poheaderx-currency = con."货币ENDAT.CLEAR netpr.netpr = gt_data-netpr.CLEAR bstae.bstae = gt_data-bstae.CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTINGinput = bstaeIMPORTINGoutput = bstae.poitem-po_item = gt_data-ebelp. "采购凭证的项目编号poitem-acctasscat = gt_data-knttp."科目分配类别poitem-short_text = gt_data-txz01."短文本poitem-quantity = gt_data-menge."采购订单数量poitem-po_unit = gt_data-meins ."采购订单的计量单位poitem-net_price = netpr."净价poitem-matl_group = gt_data-matkl."物料组poitem-plant = gt_data-werks. "工厂poitem-trackingno = gt_data-bednr."需求跟踪号poitem-preq_name = gt_data-afnam."需求者/请求者姓名poitem-tax_code = gt_data-mwskz."销售税代码poitem-conf_ctrl = bstae."确认控制代码APPEND poitem.CLEAR poitem.poitemx-po_item = gt_data-ebelp. "采购凭证的项目编号poitemx-acctasscat = con ."科目分配类别poitemx-short_text = con."短文本poitemx-quantity = con."采购订单数量poitemx-po_unit = con ."采购订单的计量单位poitemx-net_price = con."净价poitemx-matl_group = con."物料组poitemx-plant = con."工厂poitemx-trackingno = con."需求跟踪号poitemx-preq_name = con."需求者/请求者姓名poitemx-tax_code = con."销售税代码poitemx-conf_ctrl = con."确认控制代码poitemx-ret_item = con."退货项目APPEND poitemx.CLEAR poitemx.poschedule-po_item = gt_data-ebelp. "采购凭证的项目编号poschedule-sched_line = gt_data-ebelp. "采购凭证的项目编号poschedule-del_datcat_ext = 'D'."交货日期的类别poschedule-delivery_date = gt_data-eeind."交货日期poschedule-quantity = gt_data-menge."采购订单数量APPEND poschedule.CLEAR poschedule.poschedulex-po_item = gt_data-ebelp. "采购凭证的项目编号poschedulex-sched_line = gt_data-ebelp. "采购凭证的项目编号poschedulex-del_datcat_ext = con."交货日期的类别poschedulex-delivery_date = con."交货日期poschedulex-quantity = con."采购订单数量APPEND poschedulex.CLEAR poschedulex.poaccount-po_item = gt_data-ebelp. "采购凭证的项目编号poaccount-gl_account = gt_data-sakto."总帐科目poaccount-costcenter = gt_data-kostl."成本中心poaccount-asset_no = gt_data-anln1."主资产号poaccount-orderid = gt_data-aufnr."订单号poaccount-co_area = 'BELL'."成本控制APPEND poaccount.CLEAR poaccount.poaccountx-po_item = gt_data-ebelp. "采购凭证的项目编号poaccountx-gl_account = con."总帐科目poaccountx-costcenter = con."成本中心poaccountx-asset_no = con."主资产号poaccountx-orderid = con."订单号poaccountx-co_area = con."成本控制APPEND poaccountx.CLEAR poaccountx.potextitem-po_item = gt_data-ebelp. "采购凭证的项目编号potextitem-text_id = 'F03'."来自采购申请项目详细清单potextitem-text_line = gt_data-str1."行项目文本-来自采购申请项目详细清单APPEND potextitem.CLEAR potextitem.potextitem-po_item = gt_data-ebelp. "采购凭证的项目编号potextitem-text_id = 'F04'." 规格/型号potextitem-text_line = gt_data-str2."行项目文本-规格型号APPEND potextitem.CLEAR potextitem.potextitem-po_item = gt_data-ebelp. "采购凭证的项目编号potextitem-text_id = 'F09'." RFQ Referencepotextitem-text_line = gt_data-str3."行项目文本- RFQ Reference APPEND potextitem.CLEAR potextitem.AT END OF ihrez.CALL FUNCTION 'BAPI_PO_CREATE1'EXPORTINGpoheader = poheaderpoheaderx = poheaderx* POADDRVENDOR =* TESTRUN =* MEMORY_UNCOMPLETE =* MEMORY_COMPLETE =* POEXPIMPHEADER =* POEXPIMPHEADERX =* VERSIONS =* NO_MESSAGING =* NO_MESSAGE_REQ =* NO_AUTHORITY =* NO_PRICE_FROM_PO =IMPORTINGexppurchaseorder = epo* EXPHEADER =* EXPPOEXPIMPHEADER =TABLESreturn = returnpoitem = poitempoitemx = poitemx* POADDRDELIVERY =poschedule = poscheduleposchedulex = poschedulexpoaccount = poaccount* POACCOUNTPROFITSEGMENT =poaccountx = poaccountx* POCONDHEADER =* POCONDHEADERX =* POCOND =* POCONDX =* POLIMITS =* POCONTRACTLIMITS =* POSERVICES =* POSRVACCESSVALUES =* POSERVICESTEXT =* EXTENSIONIN =* EXTENSIONOUT =* POEXPIMPITEM =* POEXPIMPITEMX =* POTEXTHEADER =potextitem = potextitem* ALLVERSIONS =* POPARTNER =* POCOMPONENTS =* POCOMPONENTSX =* POSHIPPING =* POSHIPPINGX =* POSHIPPINGEXP =.LOOP AT return WHERE type = 'E' OR type = 'A'. ENDLOOP.IF sy-subrc = 0.CLEAR: lv_message.CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. LOOP AT return INTO l_return WHERE type = 'E' . CONCATENATE lv_message l_return-message ';'INTO lv_message.ENDLOOP.CONCATENATE gt_data-ihrez lv_message INTO gt_out-text.APPEND gt_out.CLEAR gt_out.ELSE.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.CONCATENATE epo '创建成功' INTO gt_out-text.APPEND gt_out.CLEAR gt_out.ENDIF.REFRESH: poitem,poitemx,poschedule,poschedulex,poaccount,poaccountx,potextitem ,poheader,poheaderx,return.CLEAR: poitem,poitemx,poschedule,poschedulex,poaccount,poaccountx,potextitem ,poheader,poheaderx,return.ENDAT.ENDLOOP.ENDFORM. " CREATE_PO*&---------------------------------------------------------------------**& Form WRITE_OUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM write_out .LOOP AT gt_out.WRITE: / gt_out-text.ENDLOOP.ENDFORM.。
采购申请相关bapi
P_BNFPO FOR EBANBNFPO,
P_MATNR FOR EBANMATNR,
P_DISPO FOR EBANDISPO,
P_EKGRP FOR EBANEKGRP,
P_LFDAT FOR EBANLFDAT,
P_FIXKZ FOR EBANFIXKZ. SELECTIO N-SCREEN END OF BLOCK BLK01. SELECTIO N-SCREEN BEGIN OF BLOCK BLK02 WITH FRAME TITLE TEXTT02. PARAMETE RS:RB_1 RADIOB39;X',
EPSTP LIKE T163YEPSTP,
END OF IT_EBAN. DATA IT_EBAN1 LIKE TABLE OF IT_EBAN WITH HEADER LINE.
DATA : BEGIN OF WA_ITAB,
WERKS LIKE EBANWERKS , "工厂
BSART LIKE EBANBSART, "凭证类 别
AND EBAKZ = ''
AND LOEKZ NE 'X'.
ENDIF.
IF IT_EBAN[ ] IS NOT INITIAL.
DATA:I_N AME1 LIKE LFA1NAME1,
I_NAME2 LIKE LFA1NAME2,
I_NAME3 LIKE LFA1NAME3,
I_NAME4 LIKE LFA1NAME4.
* --> p1 text * <-p2 text *--------------------------------------------------------------* FORM GET_DATA .
SAP物料订单创建、下达、报工、收货与投料(ABAP代码)
SAP物料订单创建、下达、报工、收货与投料(ABAP代码)对主体订单下的某一类物料通过MRP控制者的判断,可以对此类物料进行自动创建生产订单,自动下达,报工、收货,最后对主体订单投料。
1、新增加一个MRP控制者:泵送钢管类物料的MRP控制者必须设置为168.2、根据输入条件读取主体订单(剔除CLSD、TECO、DLT)的OBOM清单,挑取MRP控制者为钢管(168)胶管(170)(泵送钢管订单、泵送胶管订单)下达钢管、胶管的生产订单(订单类型为PP51)。
3、程序在下达钢管、胶管的生产订单时候,要判断物料的MRP 类型是否是ND,若是ND的话,程序报错,则提示需要将该物料改为PD。
计划员手动修正MRP参数。
4、下达生产订单时,按物料编码将数量汇总下达钢管、胶管订单,基本完成日期取当天。
5、订单下达后(REL状态)模拟CO15报完工。
6、订单报完工后模拟MB31收货(移动类型为101,库存地点取MRP2视图生产仓储地)。
7、入库后模拟MB1A(移动类型为261,库存地点取MRP2视图的生产仓储地)对预留投料到对应的主体生产订单。
8、可选择部分MRP控制者未168的物料下生产订单9、在下了生产订单后,如果OBOM中增加了物料的数量,则对差异数量下单REPORT ZR_MM_GLDDCL.TABLES: AFKO,RESB,MARC,MAKT,ZGLDDCL.DATA: BEGIN OF GT_RESB OCCURS 0,AUFNR LIKE RESB-AUFNR,WERKS LIKE RESB-WERKS,RSPOS LIKE RESB-RSPOS,MATNR LIKE RESB-MATNR,MEINS LIKE RESB-MEINS,BDMNG LIKE RESB-BDMNG,ENMNG LIKE RESB-ENMNG,END OF GT_RESB.DATA: BEGIN OF ITAB_SHOW OCCURS 0, CHKID(1),WERKS LIKE RESB-WERKS,MATNR LIKE RESB-MATNR,MAKTX LIKE MAKT-MAKTX, '物料描述MEINS LIKE RESB-MEINS, '基本单位XLOEK LIKE RESB-XLOEK, '删除标识BDMNG LIKE RESB-BDMNG, '需求数量ENMNG LIKE RESB-ENMNG, '提取数量RGEKZ LIKE RESB-RGEKZ, '反冲DISPO LIKE MARC-DISPO, 'MRP控制者DISMM LIKE MARC-DISMM, 'MRP类型LGPRO LIKE MARC-LGPRO, '生产仓储地SCDDH LIKE RESB-AUFNR, '生成的生产订单号YCXX1(100), 'PD,ND异常判断YCXX2(100), '订单创建YCXX3(100), '下达YCXX4(100), '报工YCXX5(100), '收货END OF ITAB_SHOW.DATA: BEGIN OF GT_DDTL OCCURS 0, AUFNR LIKE RESB-AUFNR,WERKS LIKE RESB-WERKS,RSPOS LIKE RESB-RSPOS,MATNR LIKE RESB-MATNR,MEINS LIKE RESB-MEINS,BDMNG LIKE RESB-BDMNG,ENMNG LIKE RESB-ENMNG,LGPRO LIKE MARC-LGPRO,YCXX1(100),END OF GT_DDTL.DATA: BEGIN OF GT_AFKO OCCURS 0,RSNUM LIKE RESB-RSNUM,AUFNR LIKE AFKO-AUFNR,END OF GT_AFKO.DATA: BEGIN OF GT_MARC OCCURS 0,MATNR LIKE MARC-MATNR,DISPO LIKE MARC-DISPO,DISMM LIKE MARC-DISMM,LGPRO LIKE MARC-LGPRO,WERKS LIKE MARC-WERKS,END OF GT_MARC.DATA: BEGIN OF GT_MAKT OCCURS 0,MATNR LIKE MAKT-MATNR,MAKTX LIKE MAKT-MAKTX,END OF GT_MAKT.DATA: BEGIN OF BDCDATA OCCURS 0.INCLUDE STRUCTURE BDCDATA.DATA: END OF BDCDATA.DATA: BDCMESS LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.DATA: BDC_MODE(1).DATA: P_MODE LIKE CTU_PARAMS-DISMODE VALUE 'N'.DATA: IN_ZGLDDCL LIKE ZGLDDCL OCCURS 0 WITH HEADER LINE.DATA: GT_ZGLDDCL LIKE ZGLDDCL OCCURS 0 WITH HEADER LINE.DATA: TL_ZGLDDCL LIKE ZGLDDCL OCCURS 0 WITH HEADER LINE.DATA: FLAG_SUCCESS(1).RANGES: R_RSNUM FOR RESB-RSNUM.RANGES: R_MATNR FOR RESB-MATNR.*&--------------------------------------------------------------------**& 屏幕显示*&--------------------------------------------------------------------*SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.PARAMETERS: P_WERKS LIKE RESB-WERKS OBLIGATORY DEFAULT '1802','工厂P_DISPO LIKE MARC-DISPO DEFAULT '168'. 'MRP控制者SELECT-OPTIONS: S_AUFNR FOR AFKO-AUFNR.'生产订单SELECTION-SCREEN: END OF BLOCK B1.*&--------------------------------------------------------------------**& 程序执行*&--------------------------------------------------------------------*START-OF-SELECTION.PERFORM AUTHORITY_CHECK.PERFORM INPUT_CHECK.PERFORM GET_DATA.PERFORM SHOW.*&---------------------------------------------------------------------**& Form GET_DATA*&---------------------------------------------------------------------*FORM GET_DATA .DATA:LV_OBJNR TYPE AUFK-OBJNR,LV_LINE TYPE BSVX-STTXT,LV_LOEKZ TYPE AUFK-LOEKZ,LV_FLAG TYPE CHAR1.* 剔除订单状态为 CLSD、TECO、DLT、CRTD OBOM清单CLEAR: GT_AFKO,GT_AFKO[].SELECT RSNUM AUFNR INTO TABLE GT_AFKOFROM AFKOWHERE AUFNR IN S_AUFNR.IF GT_AFKO[] IS INITIAL.MESSAGE '该订单预留不存在!' TYPE 'S'.STOP.ENDIF.LOOP AT GT_AFKO.* 订单的对象号SELECT SINGLE OBJNR INTO LV_OBJNRFROM AUFKWHERE AUFNR = GT_AFKO-AUFNRAND LOEKZ = ''.IF LV_OBJNR IS NOT INITIAL.* 取得订单的订单状态CALL FUNCTION 'STATUS_TEXT_EDIT'EXPORTINGOBJNR = LV_OBJNRSPRAS = SY-LANGUIMPORTINGLINE = LV_LINEEXCEPTIONSOBJECT_NOT_FOUND = 1OTHERS = 2.IF LV_LINE CS 'TECO' OR LV_LINE CS 'CLSD' ORLV_LINE CS 'DLT' OR LV_LINE CS 'CRTD'.DELETE GT_AFKO.ENDIF.ENDIF.ENDLOOP.IF GT_AFKO[] IS INITIAL.MESSAGE '该订单预留不存在!' TYPE 'S'.STOP.ELSE.LOOP AT GT_AFKO.R_RSNUM-SIGN = 'I'.R_RSNUM-OPTION = 'EQ'.R_RSNUM-LOW = GT_AFKO-RSNUM.APPEND R_RSNUM.CLEAR R_RSNUM.ENDLOOP.ENDIF.SELECT AUFNR WERKS RSNUM RSPOS MATNR MEINS BDMNG ENMNG INTOCORRESPONDING FIELDS OF TABLE GT_RESBFROM RESBWHERE RSNUM IN R_RSNUMAND XLOEK <> 'X' '删除的AND DUMPS <> 'X' '虚拟件AND DBSKZ <> 'E' '父子订单物料,排除AND BDMNG <> '0'.LOOP AT GT_RESB.MOVE-CORRESPONDING GT_RESB TO ITAB_SHOW.COLLECT ITAB_SHOW.ENDLOOP.* 判断物料是否为钢管或胶管IF ITAB_SHOW[] IS NOT INITIAL.SELECT MATNR DISPO DISMM LGPRO WERKS INTO TABLE GT_MARCFROM MARCFOR ALL ENTRIES IN ITAB_SHOWWHERE MATNR = ITAB_SHOW-MATNRAND WERKS = ITAB_SHOW-WERKS.ENDIF.SORT GT_MARC BY MATNR.LOOP AT ITAB_SHOW.READ TABLE GT_MARC WITH KEY MATNR = ITAB_SHOW-MATNR BINARY SEARCH.IF SY-SUBRC = 0.ITAB_SHOW-DISPO = GT_MARC-DISPO.ITAB_SHOW-DISMM = GT_MARC-DISMM.ITAB_SHOW-LGPRO = GT_MARC-LGPRO.IF GT_MARC-DISMM = 'ND'.ITAB_SHOW-YCXX1 = 'MRP类型为ND,请手动修正MRP参数。
SAP常用到的BAPI
SAP项目中开发用到的BAPI:MM模块1、BAPI_MATERIAL_SAVEDATA 创建物料主数据注意参数EXTENSIONIN的使用,可以创建自定义字段例如WA_BAPI_TE_MARA-MATERIAL = ITAB_UP-MATNR.T_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MARA'.T_EXTENSIONIN-VALUEPART1 = WA_BAPI_TE_MARA.APPEND T_EXTENSIONIN.WA_BAPI_TE_MARAX-MATERIAL = ITAB_UP-MATNR.T_EXTENSIONINX-STRUCTURE = 'BAPI_TE_MARAX'.T_EXTENSIONINX-VALUEPART1 = WA_BAPI_TE_MARAX.APPEND T_EXTENSIONINX.2、BAPI_OBJCL_CREATE 分类视图的创建3、BAPI_OBJCL_GETCLASSES 分类视图得到详细信息4、BAPI_MATERIAL_SAVEREPLICA 物料视图的扩充5、BAPI_GOODSMVT_CREATE 创建物料凭证注意表T158G可以决定goodsmvt_code6、BAPI_GOODSMVT_CANCEL 冲销物料凭证7、BAPI_PR_CREATE 创建PR8、BAPI_PO_CREATE1 创建PO9、BAPI_PO_CHANGE 修改PO和删除PO10、WS_REVERSE_GOODS_ISSUE 冲销交货单的过账发货11、BAPI_RESERVATION_CREATE1 创建预留12、BAPI_RESERVATION_CHANGE 修改和删除预留SD模块1、BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单2、SD_SALESDOCUMENT_CREATE 创建销售订单3、BAPI_OUTB_DELIVERY_CREATE_SLS 根据销售订单创建交货单4、BAPI_BILLINGDOC_CREATEMULTIPLE 创建发票,注意参数ref_doc_ca5、BAPI_SALESORDER_CHANGE 修改或者删除销售订单6、MB_CANCEL_GOODS_MOVEMENT 冲销交货单的过账发货7、BAPI_BILLINGDOC_CANCEL 发票的冲销PM模块1、BAPI_OBJCL_CREATE 、BAPI_OBJCL_CHANGE、BAPI_OBJCL_GETDETAIL计量点通用属性导入2、MEASUREM_DOCUM_RFC_SINGLE_001 计量凭证创建FI模块1、K_HIERARCHY_TABLES_READ 成本要素组明细2、BAPI_ACC_DOCUMENT_POST 创建会计凭证3、BAPI_ACC_DOCUMENT_REV_POST 反冲会计凭证PS模块1、BAPI_PS_INITIALIZATION、BAPI_BUS2001_CREATE、BAPI_PS_PRECOMMIT 创建项目定义2、BAPI_PS_INITIALIZATION、BAPI_BUS2054_CREATE_MULTI、BAPI_PS_PRECOMMIT 创建WBS 创建WBS的时候,注意参数wbs_left和wbs_up,这个是创建有层级的WBS必须要填写的3、KBPP_EXTERN_UPDATE_CO 修改项目和WBS的预算BAPI_MATERIAL_SAVEDATA 建立/更改物料主档BAPI_OBJCL_CREATE 建立/更改物料主档分类BAPI_OBJCL_CHANGE 建立/更改物料主档分类CLMM_MAINTAIN_CLASSIFICATIONS 批量建立/更改物料主档分类CLAF_CLASSIFICATION_OF_OBJECTS 显示物料主档分类特性值BAPI_MATERIAL_EXISTENCECHECK 检查物料主档是否存在BAPI_MATERIAL_GETLIST 显示物料主档明细BAPI_PO_CREATE1 建立采购单BAPI_PO_CHANGE 更改采购单BAPI_PO_GETDETAIL 显示采购单明细BAPI_PO_RELEASE 核发采购单BAPI_REQUISITION_CREATE 建立请购单BAPI_REQUISITION_CHANGE 更改请购单BAPI_REQUISITION_GETDETAIL 显示请购单明细BAPI_REQUISITION_RELEASE_GEN 核发请购单BAPI_CHARACT_CREATE 建立特性BAPI_CHARACT_CHANGE 更改特性BAPI_CHARACT_DELETE 删除特性BAPI_CHARACT_RENAME 重新命名特性BAPI_CHARACT_GETDETAIL 读取特性属性BAPI_CHARACT_ADDLONGTEXT 设定特性或数值的长文BAPI_CHARACT_REMOVELONGTEXT 删除特性或数值的长文BAPI_CHARACT_GETLONGTEXT 读取数值的特性长文CARD_CHARACTERISTIC_READ 显示特性值的值列表BAPI_CLASS_CREATE 建立类别BAPI_CLASS_CHANGE 变更类别BAPI_CLASS_DELETE 删除类别BAPI_CLASS_GETDETAIL 读取类别资讯(取分类下特性及特性值) BAPI_CLASS_EXISTENCECHECK 检查物件存在性BAPI_VENDOR_GETDETAIL 显示供应商明细BAPI_VENDOR_EXISTENCECHECK 检查存在性BAPI_MATERIALGROUP_GET_LIST 读取物料群组/物料群组说明BAPI_GOODSMVT_CREATE 过帐物料异动BAPI_GOODSMVT_CANCEL 冲帐(取消)物料异动BAPI_GOODSMVT_GETDETAIL 显示物料异动明细BAPI_GOODSMVT_GETITEMS 显示物料文件的明细清单。
bapi 批量创建po的案例
bapi批量创建PO一、概述在SAP系统中,使用BAPI(Business Application Programming Interface)批量创建采购订单(PO)是一项常见的操作。
BAPI是一种已定义好的函数模块,可以被外部系统调用,实现SAP系统数据的批量处理。
在企业日常运营中,需要大量的采购订单时,使用BAPI批量创建PO可以提高工作效率,减少手工操作的时间和错误率。
下面将以一个实际案例为例,介绍如何使用BAPI批量创建PO。
二、案例分析某公司在进行年度采购计划时,需要针对上千个物料编码创建对应的采购订单。
为了提高工作效率,决定使用BAPI进行批量创建PO操作。
在这个案例中,我们将以SAP系统中的BAPI_PO_CREATE1函数模块为例,详细介绍如何使用BAPI批量创建PO。
三、操作步骤1. 准备工作在进行批量创建PO之前,首先需要对数据进行准备。
这包括准备好需要采购的物料编码、采购数量、交货日期等相关信息,通常可以从公司的ERP系统中导出相关数据并存储为Excel或CSV格式。
2. 调用BAPI_PO_CREATE1在SAP系统中,可以通过SE37事务码来查找并调用函数模块。
在此案例中,我们将通过SE37找到BAPI_PO_CREATE1函数模块,并进行调用。
在调用BAPI时,需要将准备好的采购订单数据作为输入参数传递给BAPI_PO_CREATE1函数。
3. 处理返回结果调用BAPI_PO_CREATE1后,系统将返回相应的执行结果。
需要对返回的结果进行处理,检查是否有创建失败的采购订单,以及失败的原因。
在处理返回结果时,可以将成功创建的PO信息反馈给相关部门或人员,同时对失败的情况进行错误处理和重试操作。
四、注意事项在使用BAPI批量创建PO时,需要注意以下几个方面:1. 数据准备的准确性和完整性在进行批量创建PO之前,务必对数据进行准确性和完整性的检查,确保数据的准备工作没有遗漏和错误。
SAP常用BAPI
SAP常用BAPI订单BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单BAPISDORDER_GETDETAILEDLIST 销售订单明细BAPI_SALESORDER_GETLIST 销售订单列表BAPI_SALESORDER_CHANGE 修改销售订单交货单BAPI_OUTB_DELIVERY_READ_SLS 根据销售订单创建交货单,得到交货单创建初始页面所需的数据BAPI_OUTB_DELIVERY_GETDETAIL 根据交货单号读取单据的详细内容BAPI_OUTB_DELIVERY_CREATE_SLS 根据销售订单创建交货单BAPI_OUTB_DELIVERY_CHANGE 根据交货单号修改、删除单据的详细内容采购订单BAPI_PO_CREATEREF_PR 根据采购申请创建采购订单,得到采购订单创建初始页面所需的数据BAPI_READ_GOODS_RECEIPT 根据采购订单创建收货,得到货物接收初始页面所需的数据BAPI_PO_RELEASE 审批采购订单BAPI_PO_RESET_RELEASE 取消审批采购订单BAPI_PO_CHANGE 修改采购订单BAPI_PO_CREATE1 创建采购订单BAPI_PO_GETDETAIL1 采购订单明细BAPI_PO_GET_LIST 采购订单列表BAPI_PO_GETITEMS 采购订单明细列表报价单BAPI_QUOTATION_GETDETAILBOS 报价单明细BAPI_CUSTOMERQUOTATION_CHANGE 修改销售订单BAPI_QUOTATION_CREATEFROMDATA2 创建报价单功能描述事务码BAPI函数名称检验批修改建议批QA02 暂未找到查看检验批明细QA03 BAPI_INSPLOT_GETDETAIL检验结果记录检验点结果QE11 BAPI_INSPPOINT_CREATEFROMDATA 修改检验点结果QE12 BAPI_INSPPOINT_CHANGE显示检验点结果明细QE13 BAPI_INSPPOINT_GETREQUIREMENTS缺陷检验记录缺陷QF01 QFFE_FAILURE_RECORDING修改缺陷QF02 暂未找到显示缺陷QF03 暂未找到使用决策记录使用决策QA11 BAPI_INSPLOT_SETUSAGEDECISION修改使用决策QA12 暂未找到显示使用决策QA13 暂未找到质量结果通知单创建质量通知单QM01 BAPI_QNOTIFICAT_CREATE修改质量通知单QM02 BAPI_QUALNOT_MODIFY_DATA显示质量通知单明细QM03 BAPI_QUALNOT_GETDETAIL检验批清单检验批清单列表QA32 BAPI_INSPLOT_GETLIST 选择检验批。
SAP 常用BAPI
订单BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单BAPISDORDER_GETDETAILEDLIST 销售订单明细BAPI_SALESORDER_GETLIST 销售订单列表BAPI_SALESORDER_CHANGE 修改销售订单交货单BAPI_OUTB_DELIVERY_READ_SLS 根据销售订单创建交货单,得到交货单创建初始页面所需的数据BAPI_OUTB_DELIVERY_GETDETAIL 根据交货单号读取单据的详细内容BAPI_OUTB_DELIVERY_CREATE_SLS 根据销售订单创建交货单BAPI_OUTB_DELIVERY_CHANGE 根据交货单号修改、删除单据的详细内容采购订单BAPI_PO_CREATEREF_PR 根据采购申请创建采购订单,得到采购订单创建初始页面所需的数据BAPI_READ_GOODS_RECEIPT 根据采购订单创建收货,得到货物接收初始页面所需的数据BAPI_PO_RELEASE 审批采购订单BAPI_PO_RESET_RELEASE 取消审批采购订单BAPI_PO_CHANGE 修改采购订单BAPI_PO_CREATE1 创建采购订单BAPI_PO_GETDETAIL1 采购订单明细BAPI_PO_GET_LIST 采购订单列表BAPI_PO_GETITEMS 采购订单明细列表报价单BAPI_QUOTATION_GETDETAILBOS 报价单明细BAPI_CUSTOMERQUOTATION_CHANGE 修改销售订单BAPI_QUOTATION_CREATEFROMDATA2 创建报价单功能描述事务码BAPI函数名称检验批修改建议批QA02 暂未找到查看检验批明细QA03 BAPI_INSPLOT_GETDETAIL检验结果记录检验点结果QE11 BAPI_INSPPOINT_CREATEFROMDATA修改检验点结果QE12 BAPI_INSPPOINT_CHANGE显示检验点结果明细QE13 BAPI_INSPPOINT_GETREQUIREMENTS缺陷检验记录缺陷QF01 QFFE_FAILURE_RECORDING修改缺陷QF02 暂未找到显示缺陷QF03 暂未找到使用决策记录使用决策QA11 BAPI_INSPLOT_SETUSAGEDECISION修改使用决策QA12 暂未找到显示使用决策QA13 暂未找到质量结果通知单创建质量通知单QM01 BAPI_QNOTIFICAT_CREATE修改质量通知单QM02 BAPI_QUALNOT_MODIFY_DATA显示质量通知单明细QM03 BAPI_QUALNOT_GETDETAIL检验批清单检验批清单列表QA32 BAPI_INSPLOT_GETLIST 选择检验批。
SAP采购订单-参照创建
采购订单_参照创建一.说明采购订单除手工直接创建外,还可以参照其它凭证创建的,参照的凭证有采购申请、合同、计划协议等。
本示例的采购订单是参照采购申请创建的,物料需求部门创建采购申请后转至采购部门,采购部门根据申请创建采购订单,在创建过程中需要确定供应商、价格等货源相关信息。
采购申请项目的类型为标准型,创建的订单项目类型也为标准型。
主要技术要点是搜索采购申请,将申请的数据复制到采购订单中。
操作中的细节参考《采购订单_标准型》,本文档只描述不同部分。
二.参照凭证及操作数据说明创建采购订单参照的凭证是一张采购申请,采购申请中只有物料编号、需求数量,而无供应商、价格等信息,也就是货源尚未确定,在创建采购订单中需要将这些信息补充完整。
三.操作在前台输入事物码ME21N进入操作界面,如果界面中未见凭证概览子窗口,则点击工具条上“凭证概览打开”按钮(),子窗口打开后如图1所示(红框部分为凭证概览子窗口)。
图1 创建采购订单初始界面(红框部分为凭证概览子窗口)图1中的凭证概览子窗口部分集成了方便操作人员的各种工具,本例需要查找采购申请,点击选择变式按钮(),出现下拉菜单如图2所示,点击“采购申请”菜单项,进入图3界面。
(如果采购申请和创建采购订单都是登录用户,可以点击“我的采购申请”菜单项,跳过搜索步骤)。
图2 选择变式下拉菜单图3 采购申请搜索条件界面图3是采购申请搜索条件界面,可根据查找范围填入工厂、采购申请编号等数值,点击运行按钮()或按回车键进行搜索。
如果未搜索到需要的申请订单,则再返回图3界面填写合适的搜索条目继续搜索。
如果搜索到则如图4所示。
图4 搜索到的采购申请从图4的凭证概览子窗口可以看到采购申请已找到。
这时有两种方法可以创建采购订单:选中申请订单条目,点击复制按钮();或选中申请订单条目后,将其拖至采购订单窗口左上部的的采购车图标内(图中红箭头标示)。
此动作完成后界面如图5所示。
图5 采购订单(补充货源信息)当申请的信息复制到采购订单中,还缺供应商等信息,按图5所示将供应商、采购组织等信息补齐。
SAP采购订单_参照创建
采购订单_参照创建一.说明采购订单除手工直接创建外,还可以参照其它凭证创建的,参照的凭证有采购申请、合同、计划协议等。
本示例的采购订单是参照采购申请创建的,物料需求部门创建采购申请后转至采购部门,采购部门根据申请创建采购订单,在创建过程中需要确定供应商、价格等货源相关信息。
采购申请项目的类型为标准型,创建的订单项目类型也为标准型。
主要技术要点是搜索采购申请,将申请的数据复制到采购订单中。
操作中的细节参考《采购订单_标准型》,本文档只描述不同部分。
二.参照凭证及操作数据说明创建采购订单参照的凭证是一张采购申请,采购申请中只有物料编号、需求数量,而无供应商、价格等信息,也就是货源尚未确定,在创建采购订单中需要将这些信息补充完整。
三.操作在前台输入事物码ME21N进入操作界面,如果界面中未见凭证概览子窗口,则点击工具条上“凭证概览打开”按钮(),子窗口打开后如图1所示(红框部分为凭证概览子窗口)。
图1 创建采购订单初始界面(红框部分为凭证概览子窗口)图1中的凭证概览子窗口部分集成了方便操作人员的各种工具,本例需要查找采购申请,点击选择变式按钮(),出现下拉菜单如图2所示,点击“采购申请”菜单项,进入图3界面。
(如果采购申请和创建采购订单都是登录用户,可以点击“我的采购申请”菜单项,跳过搜索步骤)。
图2 选择变式下拉菜单图3 采购申请搜索条件界面图3是采购申请搜索条件界面,可根据查找范围填入工厂、采购申请编号等数值,点击运行按钮()或按回车键进行搜索。
如果未搜索到需要的申请订单,则再返回图3界面填写合适的搜索条目继续搜索。
如果搜索到则如图4所示。
图4 搜索到的采购申请从图4的凭证概览子窗口可以看到采购申请已找到。
这时有两种方法可以创建采购订单:选中申请订单条目,点击复制按钮();或选中申请订单条目后,将其拖至采购订单窗口左上部的的采购车图标内(图中红箭头标示)。
此动作完成后界面如图5所示。
图5 采购订单(补充货源信息)当申请的信息复制到采购订单中,还缺供应商等信息,按图5所示将供应商、采购组织等信息补齐。
SAP采购订单参照创建
采购订单_参照创建一.说明采购订单除手工直接创建外,还可以参照其它凭证创建的,参照的凭证有采购申请、合同、计划协议等。
本示例的采购订单是参照采购申请创建的,物料需求部门创建采购申请后转至采购部门,采购部门根据申请创建采购订单,在创建过程中需要确定供应商、价格等货源相关信息。
采购申请项目的类型为标准型,创建的订单项目类型也为标准型。
主要技术要点是搜索采购申请,将申请的数据复制到采购订单中。
操作中的细节参考《采购订单_标准型》,本文档只描述不同部分。
二.参照凭证及操作数据说明创建采购订单参照的凭证是一张采购申请,采购申请中只有物料编号、需求数量,而无供应商、价格等信息,也就是货源尚未确定,在创建采购订单中需要将这些信息补充完整。
三.操作在前台输入事物码ME21N进入操作界面,如果界面中未见凭证概览子窗口,则点击工具条上“凭证概览打开”按钮(),子窗口打开后如图1所示(红框部分为凭证概览子窗口)。
图1 创建采购订单初始界面(红框部分为凭证概览子窗口)图1中的凭证概览子窗口部分集成了方便操作人员的各种工具,本例需要查找采购申请,点击选择变式按钮(),出现下拉菜单如图2所示,点击“采购申请”菜单项,进入图3界面。
(如果采购申请和创建采购订单都是登录用户,可以点击“我的采购申请”菜单项,跳过搜索步骤)。
图2 选择变式下拉菜单图3 采购申请搜索条件界面图3是采购申请搜索条件界面,可根据查找范围填入工厂、采购申请编号等数值,点击运行按钮()或按回车键进行搜索。
如果未搜索到需要的申请订单,则再返回图3界面填写合适的搜索条目继续搜索。
如果搜索到则如图4所示。
图4 搜索到的采购申请从图4的凭证概览子窗口可以看到采购申请已找到。
SAP BAPI 生产工单创建及修改
SAP标准工单创建bapi: BAPI_PRODORD_CREATE但是使用此bapi 有如下缺点:1.后台另起线程更新数据库,即使BAPI_TRANSACTION_COMMIT(加上wait参数也无法保证当前时点已更新到数据库)即,当需要工单创建后,后续操作时,此bapi无法满足需要(比如创建工单之后,调用下达function自动下达)2.此BAPI 输入参数很有限.当需要额外参数时,就无法满足需求(比如创建样件,试制工单不限制收货数量),创建工单时,外部输入组件信息也无法满足.-----------------------------------------------------------------------------示例: 通过接口创建工单(并传入工单组件信息).*当创建工单的同时,可以使用如下方式:不提交数据库CALL FUNCTION 'COXT_BAPI_ORDER_CREATE'EXPORTINGIS_HEADER = LS_ORDERDATAI_ORDER_CATEGORY = '10'* IV_RESET = 'X'IV_ORDER_POST = ' 'IV_COMMIT = ' 'IMPORTINGES_RETURN = LS_RETURNE_ORDER_NUMBER = LV_ORDER_NUMBERE_ORDER_TYPE = LV_ORDER_TYPE*提交数据库且会等待直到工单完成*****************************************************CO_ZV_ORDER_POST是个比较有趣的function , 提交之前,会读取(SAPLCOBH)AFPO_BT等数据,即,可以使用fs修改抬头或者组件数据.比如需要在创建订单时,设置无限制收货(可添加如下代码).ASSIGN ('(SAPLCOBH)AFPO_BT[]') TO <FT_AFPO_BT>.LOOP AT <FT_AFPO_BT> ASSIGNING <FS_AFPO_BT>.<FS_AFPO_BT>-UEBTK = 'X'.ENDLOOP.设置组件反冲可使用如下代码:ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <FT_RESB_BT>.LOOP AT <FT_RESB_BT> ASSIGNING <FS_RESB_BT>.<FS_RESB_BT>-RGEKZ = 'X'.ENDLOOP.*当然,也可以在CO_ZV_ORDER_POST函数中增强去实现以上功能.**************************************************CALL FUNCTION 'CO_ZV_ORDER_POST'EXPORTINGCOMMIT_FLAG = SPACEEXT_FLG = 'X'TRANS_TYP = 'H'NO_GUI_MESSAGE = 'X'NO_DIALOG = 'X'IMPORTINGfirst_aufnr = LV_ORDER_NUMBER** TABLES** CAUFVD_NUM_EXP = ET_ORD_KEY_MAPEXCEPTIONSNO_CHANGE = 1UPDATE_REJECT = 2BUDGET_REJECT = 3OTHERS = 4.IF SY-SUBRC = 0.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGWAIT = 'X'.endif.*删除原工单组件信息.可使用:BAPI_NETWORK_COMP_REMOVE 或者:CO_XT_COMPONENTS_DELETE*新增工单组件可使用:CO_XT_COMPONENT_ADDCALL FUNCTION 'CO_XT_COMPONENT_ADD'EXPORTINGIS_ORDER_KEY = LV_ORDER_NUMBERI_MATERIAL = LV_MATERIALIS_REQU_QUAN = LS_REQU_QUANI_OPERATION = LV_OPERATIONI_SEQUENCE = LV_SEQUENCEIS_STORAGE_LOCATION = LS_STORAGE_LOCATIONIS_STORAGE_LOCATIONX = LS_STORAGE_LOCATIONX I_BATCH = LV_BATCHI_BATCHX = LV_BATCHXI_POSTP = LV_POSTPI_POSNO = LV_POSITIONNOIMPORTINGES_BAPIRETURN = LS_RETURNE_ERROR_OCCURRED = LV_ERROR.ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <FT_RESB_BT>.LOOP AT <FT_RESB_BT> ASSIGNING <FS_RESB_BT>.LV_NUMC = SY-TABIX * 10.<FS_RESB_BT>-POSNR = LV_NUMC.<FS_RESB_BT>-RGEKZ = ''."设置反冲标识CLEAR LV_NUMC.ENDLOOP.CALL FUNCTION 'CO_ZV_ORDER_POST'EXPORTINGCOMMIT_FLAG = SPACEEXT_FLG = 'X'TRANS_TYP = 'V'NO_DIALOG = 'X'commit work and wait.。
SAP BAPI 生产工单创建及修改
SAP标准工单创建bapi: BAPI_PRODORD_CREATE但是使用此bapi 有如下缺点:1.后台另起线程更新数据库,即使BAPI_TRANSACTION_COMMIT(加上wait参数也无法保证当前时点已更新到数据库)即,当需要工单创建后,后续操作时,此bapi无法满足需要(比如创建工单之后,调用下达function自动下达)2.此BAPI 输入参数很有限.当需要额外参数时,就无法满足需求(比如创建样件,试制工单不限制收货数量),创建工单时,外部输入组件信息也无法满足.-----------------------------------------------------------------------------示例: 通过接口创建工单(并传入工单组件信息).*当创建工单的同时,可以使用如下方式:不提交数据库CALL FUNCTION 'COXT_BAPI_ORDER_CREATE'EXPORTINGIS_HEADER = LS_ORDERDATAI_ORDER_CATEGORY = '10'* IV_RESET = 'X'IV_ORDER_POST = ' 'IV_COMMIT = ' 'IMPORTINGES_RETURN = LS_RETURNE_ORDER_NUMBER = LV_ORDER_NUMBERE_ORDER_TYPE = LV_ORDER_TYPE*提交数据库且会等待直到工单完成*****************************************************CO_ZV_ORDER_POST是个比较有趣的function , 提交之前,会读取(SAPLCOBH)AFPO_BT等数据,即,可以使用fs修改抬头或者组件数据.比如需要在创建订单时,设置无限制收货(可添加如下代码).ASSIGN ('(SAPLCOBH)AFPO_BT[]') TO <FT_AFPO_BT>.LOOP AT <FT_AFPO_BT> ASSIGNING <FS_AFPO_BT>.<FS_AFPO_BT>-UEBTK = 'X'.ENDLOOP.设置组件反冲可使用如下代码:ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <FT_RESB_BT>.LOOP AT <FT_RESB_BT> ASSIGNING <FS_RESB_BT>.<FS_RESB_BT>-RGEKZ = 'X'.ENDLOOP.*当然,也可以在CO_ZV_ORDER_POST函数中增强去实现以上功能.**************************************************CALL FUNCTION 'CO_ZV_ORDER_POST'EXPORTINGCOMMIT_FLAG = SPACEEXT_FLG = 'X'TRANS_TYP = 'H'NO_GUI_MESSAGE = 'X'NO_DIALOG = 'X'IMPORTINGfirst_aufnr = LV_ORDER_NUMBER** TABLES** CAUFVD_NUM_EXP = ET_ORD_KEY_MAPEXCEPTIONSNO_CHANGE = 1UPDATE_REJECT = 2BUDGET_REJECT = 3OTHERS = 4.IF SY-SUBRC = 0.CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGWAIT = 'X'.endif.*删除原工单组件信息.可使用:BAPI_NETWORK_COMP_REMOVE 或者:CO_XT_COMPONENTS_DELETE*新增工单组件可使用:CO_XT_COMPONENT_ADDCALL FUNCTION 'CO_XT_COMPONENT_ADD'EXPORTINGIS_ORDER_KEY = LV_ORDER_NUMBERI_MATERIAL = LV_MATERIALIS_REQU_QUAN = LS_REQU_QUANI_OPERATION = LV_OPERATIONI_SEQUENCE = LV_SEQUENCEIS_STORAGE_LOCATION = LS_STORAGE_LOCATIONIS_STORAGE_LOCATIONX = LS_STORAGE_LOCATIONX I_BATCH = LV_BATCHI_BATCHX = LV_BATCHXI_POSTP = LV_POSTPI_POSNO = LV_POSITIONNOIMPORTINGES_BAPIRETURN = LS_RETURNE_ERROR_OCCURRED = LV_ERROR.ASSIGN ('(SAPLCOBC)RESB_BT[]') TO <FT_RESB_BT>.LOOP AT <FT_RESB_BT> ASSIGNING <FS_RESB_BT>.LV_NUMC = SY-TABIX * 10.<FS_RESB_BT>-POSNR = LV_NUMC.<FS_RESB_BT>-RGEKZ = ''."设置反冲标识CLEAR LV_NUMC.ENDLOOP.CALL FUNCTION 'CO_ZV_ORDER_POST'EXPORTINGCOMMIT_FLAG = SPACEEXT_FLG = 'X'TRANS_TYP = 'V'NO_DIALOG = 'X'commit work and wait.。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
poheaderx-pur_group = 'X'.
poheaderx-doc_date = 'X'.
"物料数量资料
poitem-po_item = '00010'. " 項次編號
poitem-material = '000000000010001451'. " 料號
poschedulex-quantity = 'X'.
APPEND poschedulex.
CLEAR poschedulex.
poschedule-po_item = '00010'. "采购凭证的项目编号
poschedule-sched_line = '0002'. "采购凭证的项次
poitem-net_price = '1.2'. " 單價
poitem-preq_name = 'TEST' . " 申請人
APPEND poitem.
CLEAR poitem.
poitemx-po_item = '00010' .
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = return
poitem Leabharlann = poitem "poheader-doc_cat = 'F'.
poheaderx-comp_code = 'X'.
poheaderx-doc_type = 'X'.
poheaderx-creat_date = 'X'.
poheaderx-vendor = 'X'.
poheaderx-langu = 'X'.
*参考 /s/blog_45a448f50100d4dz.html
*参考 /shiyanghua/archive/2008/08/20/2800473.aspx
REPORT ztest1.
DATA: poheader LIKE TABLE OF bapimepoheader WITH HEADER LINE ,
* POACCOUNT =
* POACCOUNTPROFITSEGMENT =
* POACCOUNTX =
* POCONDHEADER =
* POCONDHEADERX =
poitem-plant = '1101'. " 工廠
poitem-stge_loc = '101'. " 倉別
poitem-quantity = '150'. " 數量
poitem-po_unit = 'EA'. " 單位
poitemx = poitemx
* POADDRDELIVERY =
poschedule = poschedule
poschedulex = poschedulex
"采购单表头资料
poheader-comp_code = '1100'. "公司代码
poheader-doc_type = 'NB'. "单据类别
poheader-creat_date = '20101115'. "创建日期
poheader-vendor = '0000100091'. "供应商代号
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
IMPORTING
exppurchaseorder = exppurchaseorder
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
poheaderx = poheaderx
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
poheaderx LIKE TABLE OF bapimepoheaderx WITH HEADER LINE,
return LIKE TABLE OF bapiret2 WITH HEADER LINE,
poitem LIKE TABLE OF bapimepoitem WITH HEADER LINE,
poschedule-del_datcat_ext = 'D'. "交货日期的类别
poschedule-delivery_date = '20101118'."交货日期
poschedule-quantity = '50'. "采购订单数量
APPEND poschedule.
poitemx-net_price = 'X'.
poitemx-preq_name = 'X'.
APPEND poitemx.
CLEAR poitemx.
"排程资料
poschedule-po_item = '00010'. "采购凭证的项目编号
poschedule-sched_line = '0001'. "采购凭证的项次
* POEXPIMPITEMX =
* POTEXTHEADER =
* POTEXTITEM =
* ALLVERSIONS =
* POPARTNER =
poheader-langu = sy-langu. "语言
poheader-purch_org = '1100'. "采购组织
poheader-pur_group = '108'. "采购组
poheader-doc_date = '20101115'. "凭证日期
poaccount LIKE TABLE OF bapimepoaccount WITH HEADER LINE,
poaccountx LIKE TABLE OF bapimepoaccountx WITH HEADER LINE,
pocond LIKE TABLE OF bapimepocond WITH HEADER LINE,
pocondx LIKE TABLE OF bapimepocondx WITH HEADER LINE,
potextitem LIKE TABLE OF bapimepotext WITH HEADER LINE,
exppurchaseorder LIKE bapimepoheader-po_number.
.
IF sy-subrc = 0.
poitemx-po_itemx = 'X'.
poitemx-material = 'X'.
poitemx-plant = 'X'.
poitemx-stge_loc = 'X'.
poitemx-quantity = 'X'.
poitemx-po_unit = 'X'.
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
CLEAR poschedule.
poschedulex-po_item = '00010'.
poschedulex-sched_line = '0002'.
poschedulex-del_datcat_ext = 'X'.
poschedulex-delivery_date = 'X'.
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
poschedulex-quantity = 'X'.
APPEND poschedulex.
CLEAR poschedulex.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = poheader
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
CLEAR poschedule.
poschedulex-po_item = '00010'.
poschedulex-sched_line = '0001'.
poschedulex-del_datcat_ext = 'X'.