标签:
广州某粮油公司的接口,因为OA太死板,所以这边接口统一做成字段,值 的形式传递。
抬头结构:ZMMS001
KOSTL 1 类型 KOSTL CHAR 10 0 成本中心 BLDAT 1 类型 BLDAT DATS 8 0 凭证中的凭证日期 XBLNR 1 类型 XBLNR CHAR 16 0 参考凭证编号
行项目结构:ZMMS002
ZEILE 1 类型 MBLPO NUMC 4 0 物料凭证中的项目 MATNR 1 类型 MATNR CHAR 18 0 物料号 WERKS 1 类型 WERKS_D CHAR 4 0 工厂 LGORT 1 类型 LGORT_D CHAR 4 0 库存地点 ERFMG 1 类型 ERFMG QUAN 13 3 以输入单位计的数量 SGTXT 1 类型 SGTXT CHAR 50 0 项目文本 ERFME 1 类型 ERFME UNIT 3 0 条目单位
函数代码:
FUNCTION ZMM_OAMB1A. *"---------------------------------------------------------------------- *"*"本地接口: *" TABLES *" T_TAB STRUCTURE ZJKS001 OPTIONAL *" T_TAB_I STRUCTURE ZJKS002 OPTIONAL *"---------------------------------------------------------------------- DATA:S_TAB TYPE ZJKS001."表头结构 DATA:S_TAB_I TYPE ZJKS002."表体结构 FIELD-SYMBOLS: <DYN_WA>,"表头 <DYN_LA>,"表体 <DYN_FIELD>."字段 DATA:GS_ZTMM_WADAT TYPE ZTMM_WADAT. DATA:GT_ZMB1A01 TYPE TABLE OF ZMB1A01, GS_ZMB1A01 LIKE LINE OF GT_ZMB1A01. DATA:LV_NUM TYPE N. DATA:LS_TABH TYPE ZMMS001, LS_TABI TYPE ZMMS002. DATA:LV_FUNC TYPE CHAR50."结构ID DATA:LV_XBLNR TYPE XBLNR1. DATA:GS_HEAD TYPE BAPI2017_GM_HEAD_01, GV_CODE TYPE BAPI2017_GM_CODE VALUE ‘03‘, GT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE, GS_ITEM TYPE BAPI2017_GM_ITEM_CREATE, GT_RETU TYPE TABLE OF BAPIRET2, GS_RETU TYPE BAPIRET2, GV_MDOC TYPE BAPI2017_GM_HEAD_RET-MAT_DOC. DEFINE MESGADD."返回消息赋值 S_TAB-FIELDNAME = &1. S_TAB-VALUE = &2. APPEND S_TAB TO T_TAB. END-OF-DEFINITION. "************************************************************正式程序 READ TABLE T_TAB INTO S_TAB WITH KEY FIELDNAME = ‘FUNCTION‘. IF SY-SUBRC = 0. LV_FUNC = S_TAB-VALUE. IF LV_FUNC = ‘OAMB1A‘. ELSE. REFRESH:T_TAB. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘引用错误函数,请联系管理员!‘. RETURN. ENDIF. ELSE. REFRESH:T_TAB. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘未指定函数!‘. RETURN. ENDIF. IF T_TAB[] IS INITIAL OR T_TAB_I[] IS INITIAL. REFRESH:T_TAB. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘传入参数不完整,需要完整的表头表体信息!‘. RETURN. ENDIF. ASSIGN LS_TABH TO <DYN_WA>."表头结构 ASSIGN LS_TABI TO <DYN_LA>."表体结构 LOOP AT T_TAB INTO S_TAB."表头数据装换 ASSIGN COMPONENT S_TAB-FIELDNAME OF STRUCTURE <DYN_WA> TO <DYN_FIELD>. IF SY-SUBRC = 0. <DYN_FIELD> = S_TAB-VALUE. ENDIF. ENDLOOP. IF LS_TABH-KOSTL IS INITIAL. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘成本中心不能为空!‘. ENDIF. GS_HEAD-REF_DOC_NO = LS_TABH-XBLNR. GS_HEAD-PR_UNAME = SY-UNAME. CALL FUNCTION ‘NUMBER_RANGE_ENQUEUE‘ EXPORTING OBJECT = ‘ZOALS‘ EXCEPTIONS FOREIGN_LOCK = 1 OBJECT_NOT_FOUND = 2 SYSTEM_FAILURE = 3 OTHERS = 4. IF SY-SUBRC = 0. CALL FUNCTION ‘NUMBER_GET_NEXT‘ EXPORTING NR_RANGE_NR = ‘01‘ OBJECT = ‘ZOALS‘ IGNORE_BUFFER = ‘X‘ IMPORTING NUMBER = GS_ZMB1A01-ZJLLSH EXCEPTIONS INTERVAL_NOT_FOUND = 1 NUMBER_RANGE_NOT_INTERN = 2 OBJECT_NOT_FOUND = 3 QUANTITY_IS_0 = 4 QUANTITY_IS_NOT_1 = 5 INTERVAL_OVERFLOW = 6 BUFFER_OVERFLOW = 7 OTHERS = 8. IF SY-SUBRC = 0. CALL FUNCTION ‘NUMBER_RANGE_DEQUEUE‘ EXPORTING OBJECT = ‘ZOALS‘ EXCEPTIONS OBJECT_NOT_FOUND = 1 OTHERS = 2. ENDIF. ENDIF. LOOP AT T_TAB_I INTO S_TAB_I."表体数据装换 AT NEW COL. CLEAR LS_TABI. ENDAT. ASSIGN COMPONENT S_TAB_I-FIELDNAME OF STRUCTURE <DYN_LA> TO <DYN_FIELD>. IF SY-SUBRC = 0. <DYN_FIELD> = S_TAB_I-VALUE. ENDIF. AT END OF COL. LV_NUM = LV_NUM + 1. IF LS_TABI-MATNR IS INITIAL. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘物料编码不能为空!‘. RETURN. ENDIF. IF LS_TABI-WERKS IS INITIAL. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘工厂编码不能为空!‘. RETURN. ENDIF. IF LS_TABI-LGORT IS INITIAL. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘库位编码不能为空!‘. RETURN. ENDIF. IF LS_TABI-ERFMG IS INITIAL. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘数量字段不能为空!‘. RETURN. ENDIF. IF LS_TABI-ERFME IS INITIAL. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘单位不能为空!‘. RETURN. ENDIF. CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘ EXPORTING INPUT = LS_TABI-MATNR IMPORTING OUTPUT = LS_TABI-MATNR. CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_INPUT‘ EXPORTING INPUT = LS_TABI-ERFME LANGUAGE = SY-LANGU IMPORTING OUTPUT = LS_TABI-ERFME EXCEPTIONS UNIT_NOT_FOUND = 1 OTHERS = 2. IF SY-SUBRC <> 0. ENDIF. GS_ITEM-MATERIAL = LS_TABI-MATNR. GS_ITEM-PLANT = LS_TABI-WERKS. IF GS_HEAD-DOC_DATE IS INITIAL. SELECT SINGLE * INTO CORRESPONDING FIELDS OF GS_ZTMM_WADAT FROM ZTMM_WADAT WHERE WERKS = LS_TABI-WERKS AND SDATE = SY-DATUM AND ETIME >= SY-UZEIT AND STIME <= SY-UZEIT. IF SY-SUBRC = 0. GS_HEAD-DOC_DATE = GS_ZTMM_WADAT-BUDAT. GS_HEAD-PSTNG_DATE = GS_ZTMM_WADAT-BUDAT. ELSE. GS_HEAD-DOC_DATE = SY-DATUM. GS_HEAD-PSTNG_DATE = SY-DATUM. ENDIF. ENDIF. GS_ITEM-STGE_LOC = LS_TABI-LGORT. GS_ITEM-MOVE_TYPE = ‘201‘. GS_ITEM-ENTRY_QNT = LS_TABI-ERFMG. GS_ITEM-ENTRY_UOM = LS_TABI-ERFME. IF LS_TABH-KOSTL IS INITIAL. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ ‘传递值中成本中心为空,请联系管理员!‘. RETURN. ENDIF. CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘ EXPORTING INPUT = LS_TABH-KOSTL IMPORTING OUTPUT = LS_TABH-KOSTL. * CONCATENATE ‘000‘ LS_TABH-KOSTL INTO GS_ITEM-COSTCENTER. * CONDENSE GS_ITEM-COSTCENTER NO-GAPS. GS_ITEM-COSTCENTER = LS_TABH-KOSTL. GS_ITEM-ITEM_TEXT = LS_TABI-SGTXT. APPEND GS_ITEM TO GT_ITEM. "ADD BY LY FOR LOG * GS_ZMB1A01-ZJLLSH = GS_ZMB1A01-POSNR = LV_NUM. GS_ZMB1A01-XBLNR = GS_HEAD-REF_DOC_NO. GS_ZMB1A01-KOSTL = GS_ITEM-COSTCENTER. GS_ZMB1A01-MATNR = GS_ITEM-MATERIAL. GS_ZMB1A01-WERKS = GS_ITEM-PLANT. GS_ZMB1A01-LGORT = GS_ITEM-STGE_LOC. GS_ZMB1A01-ERFMG = GS_ITEM-ENTRY_QNT. GS_ZMB1A01-ERFME = GS_ITEM-ENTRY_UOM. GS_ZMB1A01-DAT = SY-DATUM. GS_ZMB1A01-TIM = SY-UZEIT. APPEND GS_ZMB1A01 TO GT_ZMB1A01. "ADD BY LY FOR LOG ENDAT. ENDLOOP. CLEAR:LV_XBLNR. SELECT SINGLE XBLNR INTO LV_XBLNR FROM MKPF WHERE XBLNR = LS_TABH-XBLNR. IF LV_XBLNR IS NOT INITIAL. MESGADD:‘RETURN‘ ‘S‘. RETURN. ENDIF. CALL FUNCTION ‘BAPI_GOODSMVT_CREATE‘ EXPORTING GOODSMVT_HEADER = GS_HEAD GOODSMVT_CODE = GV_CODE IMPORTING * GOODSMVT_HEADRET = MATERIALDOCUMENT = GV_MDOC * MATDOCUMENTYEAR = TABLES GOODSMVT_ITEM = GT_ITEM RETURN = GT_RETU. READ TABLE GT_RETU INTO GS_RETU WITH KEY TYPE = ‘E‘. IF SY-SUBRC = 0. LOOP AT GT_RETU INTO GS_RETU WHERE TYPE = ‘E‘. MESGADD:‘RETURN‘ ‘E‘, ‘MESSAGE‘ GS_RETU-MESSAGE. ENDLOOP. CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. ELSE. LOOP AT GT_ZMB1A01 INTO GS_ZMB1A01. GS_ZMB1A01-MBLNR = GV_MDOC. MODIFY GT_ZMB1A01 FROM GS_ZMB1A01. ENDLOOP. MODIFY ZMB1A01 FROM TABLE GT_ZMB1A01. MESGADD:‘RETURN‘ ‘S‘, ‘MBLNR‘ GV_MDOC. CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘ EXPORTING WAIT = ‘X‘. ENDIF. ENDFUNCTION.
标签:
原文地址:http://www.cnblogs.com/sapSB/p/4815419.html