MMCC这个事务码没用过,也是才听到的,都是业务搞起来的。。。然后感觉这个东西有点意思,就搞搞咯
网上找的一篇文章,自己修改的。改了默认收货工厂为创建时的工厂,因为这边一直报收货工厂必输。。。不管是不是配置问题,反正可以解决。
*&---------------------------------------------------------------------* *& Report ZLYTEST_MATERIAL *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZLYTEST_MATERIAL. SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME. PARAMETERS: P_WERKS0 LIKE MARC-WERKS DEFAULT '2001', P_VKORG0 LIKE MVKE-VKORG DEFAULT '2001', P_DISNSO LIKE MVKE-VTWEG DEFAULT '00', P_MBRSH LIKE MARA-MBRSH DEFAULT 'C'. SELECTION-SCREEN: END OF BLOCK B1. SELECTION-SCREEN: BEGIN OF BLOCK B2 WITH FRAME. PARAMETERS: P_MATNR LIKE MARA-MATNR DEFAULT '4000888'. PARAMETERS: P_BUKRS LIKE T001-BUKRS. PARAMETERS: P_BWKEY LIKE T001K-BWKEY. PARAMETERS: P_MATCFG LIKE MARA-MATNR DEFAULT '4000020'. SELECTION-SCREEN: END OF BLOCK B2. START-OF-SELECTION. DATA: GT_MARC TYPE TABLE OF MARC. DATA: GT_MARA TYPE TABLE OF MARA. DATA : STR_CLIENTDATA LIKE BAPI_MARA_GA, STR_PLANTDATA LIKE BAPI_MARC_GA, STR_FORECASTPARAMETERS LIKE BAPI_MPOP_GA, STR_PLANNINGDATA LIKE BAPI_MPGD_GA, STR_STORAGELOCATIONDATA LIKE BAPI_MARD_GA, STR_VALUATIONDATA LIKE BAPI_MBEW_GA, STR_SALESDATA LIKE BAPI_MVKE_GA, STR_WAREHOUSENUMBERDATA LIKE BAPI_MLGN_GA, STR_STORAGETYPEDATA LIKE BAPI_MLGT_GA, STR_PRTDATA LIKE BAPI_MFHM_GA, STR_LIFOVALUATIONDATA LIKE BAPI_MYMS_GA, TAB_GET_ALL_R TYPE TABLE OF BAPIRETURN. DATA:TAB_MATERIALDESCRIPTION TYPE TABLE OF BAPI_MAKT_GA WITH HEADER LINE, TAB_UNITSOFMEASURE TYPE TABLE OF BAPI_MARM_GA, TAB_INTERNATIONALARTNOS TYPE TABLE OF BAPI_MEAN_GA, TAB_MATERIALLONGTEXT TYPE TABLE OF BAPI_MLTX_GA, TAB_TAXCLASSIFICATIONS TYPE TABLE OF BAPI_MLAN_GA, TAB_MATERIALDESCRIPTION1 TYPE TABLE OF BAPI_MAKT WITH HEADER LINE. DATA: BEGIN OF TAB_HEAD. INCLUDE STRUCTURE BAPIMATHEAD. DATA: END OF TAB_HEAD. DATA: BEGIN OF TAB_PLANTDATA. INCLUDE STRUCTURE BAPI_MARC. DATA: END OF TAB_PLANTDATA. DATA: BEGIN OF TAB_PLANTDATAX. INCLUDE STRUCTURE BAPI_MARCX. DATA: END OF TAB_PLANTDATAX. DATA: BEGIN OF TAB_CLIENT. INCLUDE STRUCTURE BAPI_MARA. DATA: END OF TAB_CLIENT. DATA: BEGIN OF TAB_CLIENTX. INCLUDE STRUCTURE BAPI_MARAX. DATA: END OF TAB_CLIENTX. DATA: BEGIN OF TAB_SALESDATA. INCLUDE STRUCTURE BAPI_MVKE. DATA: END OF TAB_SALESDATA. DATA: BEGIN OF TAB_SALESDATAX. INCLUDE STRUCTURE BAPI_MVKEX. DATA: END OF TAB_SALESDATAX. DATA : BEGIN OF TAB_RETURN. INCLUDE STRUCTURE BAPIRET2 . DATA : END OF TAB_RETURN. DATA : TAB_RETURN_MSGS TYPE TABLE OF BAPI_MATRETURN2 . DATA: TAB_FORECAST LIKE BAPI_MPOP, TAB_FORECASTX LIKE BAPI_MPOPX, TAB_PLANGDATA LIKE BAPI_MPGD, TAB_PLANGDATAX LIKE BAPI_MPGDX, TAB_STLOCDATA LIKE BAPI_MARD, TAB_STLOCDATAX LIKE BAPI_MARDX, TAB_VALDATA LIKE BAPI_MBEW, TAB_VALDATAX LIKE BAPI_MBEWX, TAB_WAREHOUSE LIKE BAPI_MLGN, TAB_WAREHOUSEX LIKE BAPI_MLGNX, TAB_STORTYPED LIKE BAPI_MLGT, TAB_STORTYPEDX LIKE BAPI_MLGTX. DATA GT_MAKT TYPE TABLE OF BAPI_MAKT. DATA: GV_LEN TYPE I, VIEW, COUNTER TYPE SY-INDEX, GV_I TYPE I, GV_MSG(200). FIELD-SYMBOLS: <FS_MARC> TYPE BAPI_MARA_GA,"MARC, <F1> TYPE ANY, <F2> TYPE ANY, <FMS> TYPE BAPI_MATRETURN2, <FSTRUCT> TYPE ANY, <FSTRUCTX> TYPE ANY. CALL FUNCTION 'BAPI_MATERIAL_GET_ALL' EXPORTING MATERIAL = P_MATCFG COMP_CODE = P_BUKRS VAL_AREA = P_BWKEY * VAL_TYPE = PLANT = P_WERKS0 * STGE_LOC = SALESORG = P_VKORG0 DISTR_CHAN = P_DISNSO * WHSENUMBER = * STGE_TYPE = * LIFO_VALUATION_LEVEL = IMPORTING CLIENTDATA = STR_CLIENTDATA PLANTDATA = STR_PLANTDATA FORECASTPARAMETERS = STR_FORECASTPARAMETERS PLANNINGDATA = STR_PLANNINGDATA STORAGELOCATIONDATA = STR_STORAGELOCATIONDATA VALUATIONDATA = STR_VALUATIONDATA WAREHOUSENUMBERDATA = STR_WAREHOUSENUMBERDATA SALESDATA = STR_SALESDATA STORAGETYPEDATA = STR_STORAGETYPEDATA PRTDATA = STR_PRTDATA LIFOVALUATIONDATA = STR_LIFOVALUATIONDATA TABLES MATERIALDESCRIPTION = TAB_MATERIALDESCRIPTION UNITSOFMEASURE = TAB_UNITSOFMEASURE INTERNATIONALARTNOS = TAB_INTERNATIONALARTNOS MATERIALLONGTEXT = TAB_MATERIALLONGTEXT TAXCLASSIFICATIONS = TAB_TAXCLASSIFICATIONS * EXTENSIONOUT = RETURN = TAB_GET_ALL_R. * Material views update --- * SELECT * FROM MARC INTO TABLE GT_MARC * WHERE MATNR = P_MATCFG * AND WERKS = P_WERKS0. * IF SY-SUBRC = 0. * READ TABLE GT_MARC ASSIGNING <FS_MARC> INDEX 1. * IF SY-SUBRC = 0. ASSIGN STR_CLIENTDATA TO <FS_MARC>. "关于视图这块是本人修改的,原来是读的MARC用的PSTAT,可是我发现,还是用读出来的MAINT_STAT准确点 COUNTER = 0. CLEAR VIEW. GV_I = STRLEN( <FS_MARC>-MAINT_STAT ). DO GV_I TIMES. VIEW = <FS_MARC>-MAINT_STAT+COUNTER(1). IF VIEW IS INITIAL. EXIT. ENDIF. COUNTER = COUNTER + 1. CASE VIEW. WHEN 'K'. TAB_HEAD-BASIC_VIEW = VIEW. WHEN 'V'. TAB_HEAD-SALES_VIEW = VIEW. WHEN 'E'. TAB_HEAD-PURCHASE_VIEW = VIEW. WHEN 'D' . TAB_HEAD-MRP_VIEW = VIEW. WHEN 'P'. TAB_HEAD-FORECAST_VIEW = VIEW. WHEN 'A'. TAB_HEAD-WORK_SCHED_VIEW = VIEW. WHEN 'F'. TAB_HEAD-PRT_VIEW = VIEW. WHEN 'L'. TAB_HEAD-STORAGE_VIEW = VIEW. WHEN 'S'. TAB_HEAD-WAREHOUSE_VIEW = VIEW. WHEN 'Q'. TAB_HEAD-QUALITY_VIEW = VIEW. WHEN 'B'. TAB_HEAD-ACCOUNT_VIEW = VIEW. WHEN 'G'. TAB_HEAD-COST_VIEW = VIEW. WHEN OTHERS. ENDCASE. ENDDO. * ENDIF. * ENDIF. TAB_HEAD-MATERIAL = P_MATNR. TAB_HEAD-IND_SECTOR = STR_CLIENTDATA-IND_SECTOR. TAB_HEAD-MATL_TYPE = STR_CLIENTDATA-MATL_TYPE. MOVE-CORRESPONDING STR_CLIENTDATA TO TAB_CLIENT. MOVE-CORRESPONDING STR_PLANTDATA TO TAB_PLANTDATA. MOVE-CORRESPONDING STR_FORECASTPARAMETERS TO TAB_FORECAST. MOVE-CORRESPONDING STR_PLANNINGDATA TO TAB_PLANGDATA. MOVE-CORRESPONDING STR_STORAGELOCATIONDATA TO TAB_STLOCDATA. MOVE-CORRESPONDING STR_VALUATIONDATA TO TAB_VALDATA. MOVE-CORRESPONDING STR_WAREHOUSENUMBERDATA TO TAB_WAREHOUSE. MOVE-CORRESPONDING STR_SALESDATA TO TAB_SALESDATA. TAB_SALESDATA-DELYG_PLNT = P_WERKS0."默认的工厂 MOVE-CORRESPONDING STR_STORAGETYPEDATA TO TAB_STORTYPED. * Fill the update struktur DO . CASE SY-INDEX. WHEN 1. ASSIGN TAB_CLIENT TO <F1>. ASSIGN TAB_CLIENTX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 2. ASSIGN TAB_PLANTDATA TO <F1>. ASSIGN TAB_PLANTDATAX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 3. ASSIGN TAB_FORECAST TO <F1>. ASSIGN TAB_FORECASTX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 4. ASSIGN TAB_PLANGDATA TO <F1>. ASSIGN TAB_PLANGDATAX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 5. ASSIGN TAB_STLOCDATA TO <F1>. ASSIGN TAB_STLOCDATAX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 6. ASSIGN TAB_VALDATA TO <F1>. ASSIGN TAB_VALDATAX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 7. ASSIGN TAB_WAREHOUSE TO <F1>. ASSIGN TAB_WAREHOUSEX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 8. ASSIGN TAB_SALESDATA TO <F1>. ASSIGN TAB_SALESDATAX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN 9. ASSIGN TAB_STORTYPED TO <F1>. ASSIGN TAB_STORTYPEDX TO <F2>. PERFORM FILL_UPDATE_STRUCT USING <F1> <F2>. WHEN OTHERS. EXIT. ENDCASE. ENDDO. LOOP AT TAB_MATERIALDESCRIPTION. MOVE-CORRESPONDING TAB_MATERIALDESCRIPTION TO TAB_MATERIALDESCRIPTION1. APPEND TAB_MATERIALDESCRIPTION1. ENDLOOP. TAB_SALESDATA-SALES_ORG = P_VKORG0. TAB_SALESDATA-DISTR_CHAN = P_DISNSO. CLEAR: TAB_SALESDATAX-SALES_ORG, TAB_SALESDATAX-DISTR_CHAN. TAB_SALESDATAX-SALES_ORG = TAB_SALESDATA-SALES_ORG. TAB_SALESDATAX-DISTR_CHAN = TAB_SALESDATA-DISTR_CHAN. CLEAR TAB_PLANTDATAX-PLANT. TAB_PLANTDATAX-PLANT = TAB_PLANTDATA-PLANT. CLEAR TAB_VALDATAX-VAL_AREA. TAB_VALDATAX-VAL_AREA = TAB_VALDATA-VAL_AREA. CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' EXPORTING HEADDATA = TAB_HEAD CLIENTDATA = TAB_CLIENT CLIENTDATAX = TAB_CLIENTX PLANTDATA = TAB_PLANTDATA PLANTDATAX = TAB_PLANTDATAX FORECASTPARAMETERS = TAB_FORECAST FORECASTPARAMETERSX = TAB_FORECASTX PLANNINGDATA = TAB_PLANGDATA PLANNINGDATAX = TAB_PLANGDATAX STORAGELOCATIONDATA = TAB_STLOCDATA STORAGELOCATIONDATAX = TAB_STLOCDATAX VALUATIONDATA = TAB_VALDATA VALUATIONDATAX = TAB_VALDATAX WAREHOUSENUMBERDATA = TAB_WAREHOUSE WAREHOUSENUMBERDATAX = TAB_WAREHOUSEX SALESDATA = TAB_SALESDATA SALESDATAX = TAB_SALESDATAX STORAGETYPEDATA = TAB_STORTYPED STORAGETYPEDATAX = TAB_STORTYPEDX * FLAG_ONLINE = ' ' * FLAG_CAD_CALL = ' ' * NO_DEQUEUE = ' ' IMPORTING RETURN = TAB_RETURN TABLES MATERIALDESCRIPTION = TAB_MATERIALDESCRIPTION1 * UNITSOFMEASURE = * UNITSOFMEASUREX = * INTERNATIONALARTNOS = * MATERIALLONGTEXT = * TAXCLASSIFICATIONS = RETURNMESSAGES = TAB_RETURN_MSGS. IF TAB_RETURN-TYPE = 'S'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF. LOOP AT TAB_RETURN_MSGS ASSIGNING <FMS>. GV_MSG = <FMS>. WRITE:/ GV_MSG. ENDLOOP. *&---------------------------------------------------------------------* *& Form fill_update_struct *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_<F1> text * -->P_<F2> text *----------------------------------------------------------------------* FORM FILL_UPDATE_STRUCT USING P_F1 TYPE ANY P_F2 TYPE ANY. DO. ASSIGN COMPONENT SY-INDEX OF STRUCTURE P_F1 TO <FSTRUCT>. IF SY-SUBRC <> 0. EXIT. ENDIF. IF <FSTRUCT> IS NOT INITIAL. ASSIGN COMPONENT SY-INDEX OF STRUCTURE P_F2 TO <FSTRUCTX>. IF SY-SUBRC = 0. <FSTRUCTX> = 'X'. ENDIF. ENDIF. ENDDO. ENDFORM. " fill_update_struct
代码应该都能看懂,就不废话了。。。