点击此处---> 群内免费提供SAP练习系统(在群公告中)
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
2016-11-30
今天抽时间研究了一下BAPI_MATERIAL_SAVEREPLICA
觉得这个bapi 很给力,请注意增强和BAPI_MATERIAL_SAVEdata 是不一样的
需要扩展 BAPI_TE_E1MARA..
我这项目mara 有自定义必输字段,所以使用了BAPI_TE_E1MARA.
TABLES MARA. DATA LT_BAPIE1MATHEADER TYPE TABLE OF BAPIE1MATHEADER WITH HEADER LINE. FIELD-SYMBOLS TYPE BAPIE1MATHEADER. DATA LT_MARA TYPE TABLE OF MARA WITH HEADER LINE. DATA LT_MARC TYPE TABLE OF MARC WITH HEADER LINE. DATA LT_BAPIE1MARA TYPE TABLE OF BAPIE1MARA WITH HEADER LINE. DATA LT_BAPIE1MARAX TYPE TABLE OF BAPIE1MARAX WITH HEADER LINE. DATA LT_BAPIE1MAKT TYPE TABLE OF BAPIE1MAKT WITH HEADER LINE. DATA LT_MAKT TYPE TABLE OF MAKT WITH HEADER LINE. DATA LT_BAPIE1PAREX TYPE TABLE OF BAPIE1PAREX WITH HEADER LINE. DATA LT_BAPIE1PAREXX TYPE TABLE OF BAPIE1PAREXX WITH HEADER LINE. DATA LT_BAPIE1MARC TYPE TABLE OF BAPIE1MARC WITH HEADER LINE. DATA LT_BAPIE1MARCX TYPE TABLE OF BAPIE1MARCX WITH HEADER LINE. DATA LS_BAPI_TE_E1MARA TYPE BAPI_TE_E1MARA. DATA LS_BAPI_TE_E1MARAX TYPE BAPI_TE_E1MARAX. *PARAMETERS P_MATNR TYPE MATNR. SELECT-OPTIONS S_MATNR FOR MARA-MATNR. PARAMETERS P_MATNT TYPE MATNR DEFAULT '999999999999999999'. START-OF-SELECTION. SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_MARA FROM MARA WHERE MATNR IN S_MATNR. LOOP AT LT_MARA. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = LT_MARA-MATNR IMPORTING OUTPUT = LT_MARA-MATNR. LT_MARA-MATNR+0(1) = 'Z'. LT_BAPIE1MATHEADER-FUNCTION = 'INS'. LT_BAPIE1MATHEADER-MATERIAL = LT_MARA-MATNR. LT_BAPIE1MATHEADER-IND_SECTOR = LT_MARA-MBRSH. LT_BAPIE1MATHEADER-MATL_TYPE = LT_MARA-MTART. LT_BAPIE1MATHEADER-BASIC_VIEW = 'X'. LT_BAPIE1MATHEADER-STORAGE_VIEW = 'X'. LT_BAPIE1MATHEADER-PURCHASE_VIEW = 'X'. APPEND LT_BAPIE1MATHEADER. CLEAR LT_BAPIE1MATHEADER. CALL FUNCTION 'ZBXYZ_CONVERT_LINE' EXPORTING IS_LINE = LT_MARA * IV_CLEAR = 'X' CHANGING CS_LINE = LT_BAPIE1MARA. LT_BAPIE1MARA-FUNCTION = 'INS'. APPEND LT_BAPIE1MARA. CALL FUNCTION 'ZBXYZ_CHECK_UPDFLAG' EXPORTING IS_LINE = LT_BAPIE1MARA CHANGING CS_LINEX = LT_BAPIE1MARAX. LT_BAPIE1MARAX-FUNCTION = 'INS'. APPEND LT_BAPIE1MARAX. MOVE-CORRESPONDING LT_MARA TO LS_BAPI_TE_E1MARA. LS_BAPI_TE_E1MARA-MATERIAL = LT_MARA-MATNR. LT_BAPIE1PAREX-FUNCTION = 'INS'. LT_BAPIE1PAREX-MATERIAL = LT_MARA-MATNR. LT_BAPIE1PAREX-STRUCTURE = 'BAPI_TE_E1MARA'. LT_BAPIE1PAREX-VALUEPART1 = LS_BAPI_TE_E1MARA. APPEND LT_BAPIE1PAREX. CLEAR LT_BAPIE1PAREX. LS_BAPI_TE_E1MARAX-MATERIAL = LT_MARA-MATNR. LS_BAPI_TE_E1MARAX-ZPRDNAM = 'X'. "自定义必输字段。。。项目需求! LS_BAPI_TE_E1MARAX-ZPRDTYP = 'X'. LT_BAPIE1PAREXX-FUNCTION = 'INS'. LT_BAPIE1PAREXX-MATERIAL = LT_MARA-MATNR. LT_BAPIE1PAREXX-STRUCTURE = 'BAPI_TE_E1MARAX'. LT_BAPIE1PAREXX-VALUEPART1 = LS_BAPI_TE_E1MARAX. APPEND LT_BAPIE1PAREXX. CLEAR LT_BAPIE1PAREXX. ENDLOOP. SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_MAKT FROM MAKT WHERE MATNR IN S_MATNR. LOOP AT LT_MAKT. CALL FUNCTION 'ZBXYZ_CONVERT_LINE' EXPORTING IS_LINE = LT_MAKT * IV_CLEAR = 'X' CHANGING CS_LINE = LT_BAPIE1MAKT. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = LT_MAKT-MATNR IMPORTING OUTPUT = LT_MAKT-MATNR. LT_MAKT-MATNR+0(1) = 'Z'. LT_BAPIE1MAKT-MATERIAL = LT_MAKT-MATNR . LT_BAPIE1MAKT-FUNCTION = 'INS'. APPEND LT_BAPIE1MAKT. CLEAR LT_BAPIE1MAKT. ENDLOOP. SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_MARC FROM MARC WHERE MATNR IN S_MATNR. LOOP AT LT_MARC. CALL FUNCTION 'ZBXYZ_CONVERT_LINE' EXPORTING IS_LINE = LT_MARC * IV_CLEAR = 'X' CHANGING CS_LINE = LT_BAPIE1MARC. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = LT_MARC-MATNR IMPORTING OUTPUT = LT_MARC-MATNR. LT_MARC-MATNR+0(1) = 'Z'. LT_BAPIE1MARC-FUNCTION = 'INS'. LT_BAPIE1MARC-MATERIAL = LT_MARC-MATNR . APPEND LT_BAPIE1MARC . CALL FUNCTION 'ZBXYZ_CHECK_UPDFLAG' EXPORTING IS_LINE = LT_BAPIE1MARC CHANGING CS_LINEX = LT_BAPIE1MARCX. LT_BAPIE1MARCX-FUNCTION = 'INS'. LT_BAPIE1MARCX-MATERIAL = LT_MARC-MATNR . APPEND LT_BAPIE1MARCX. ENDLOOP. DATA LS_BAPIRET2 TYPE BAPIRET2. DATA LT_BAPIRET2 TYPE TABLE OF BAPIRET2. CALL FUNCTION 'BAPI_MATERIAL_SAVEREPLICA' EXPORTING NOAPPLLOG = 'X' NOCHANGEDOC = 'X' TESTRUN = SPACE INPFLDCHECK = SPACE * FLAG_CAD_CALL = ' ' * NO_ROLLBACK_WORK = ' ' * FLAG_ONLINE = ' ' IMPORTING RETURN = LS_BAPIRET2 TABLES HEADDATA = LT_BAPIE1MATHEADER CLIENTDATA = LT_BAPIE1MARA CLIENTDATAX = LT_BAPIE1MARAX PLANTDATA = LT_BAPIE1MARC PLANTDATAX = LT_BAPIE1MARCX * FORECASTPARAMETERS = * FORECASTPARAMETERSX = * PLANNINGDATA = * PLANNINGDATAX = * STORAGELOCATIONDATA = * STORAGELOCATIONDATAX = * VALUATIONDATA = * VALUATIONDATAX = * WAREHOUSENUMBERDATA = * WAREHOUSENUMBERDATAX = * SALESDATA = * SALESDATAX = * STORAGETYPEDATA = * STORAGETYPEDATAX = MATERIALDESCRIPTION = LT_BAPIE1MAKT * UNITSOFMEASURE = * UNITSOFMEASUREX = * INTERNATIONALARTNOS = * MATERIALLONGTEXT = * TAXCLASSIFICATIONS = * PRTDATA = * PRTDATAX = EXTENSIONIN = LT_BAPIE1PAREX EXTENSIONINX = LT_BAPIE1PAREXX * FORECASTVALUES = * UNPLNDCONSUMPTION = * TOTALCONSUMPTION = RETURNMESSAGES = LT_BAPIRET2 .
体验了一下,感觉超给力