SAP MM 库存初始化和批量扩充物料仓位
庫存初始化和批量擴充物料倉位 這兩個功能合在一個程序里。
SAP剛上線時這兩功能很管用。
?
*&---------------------------------------------------------------------*
*&?Report??ZR_KTK_MM_0017
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT??ZR_KTK_MM_0017.
TABLES:?MKPF,RM07M,MSEG,T100,RM03M.
DATA:???BDCDATA?LIKE?BDCDATA????OCCURS?0?WITH?HEADER?LINE.
*???????messages?of?call?transaction
DATA:???MESSTAB?LIKE?BDCMSGCOLL?OCCURS?0?WITH?HEADER?LINE.
DATA:???E_GROUP_OPENED,
????????E_KEEP(1)?TYPE?C,
????????SMALLLOG(1)?TYPE?C.
DATA:?BEGIN?OF?RECORD?OCCURS?0,
????????BLDAT?LIKE?MKPF-BLDAT,????????????"創建日期
????????BUDAT?LIKE?MKPF-BUDAT,????????????"過賬日期
????????SOBKZ?LIKE?RM07M-SOBKZ,???????????"特殊庫存
????????WERKS?LIKE?RM07M-WERKS,???????????"工廠
????????LGORT?LIKE?MSEG-LGORT,????????????"倉碼
????????MATNR?LIKE?MSEG-MATNR,????????????"料號
*????????ERFMG?LIKE?MSEG-ERFMG,????????????"數量
????????ERFMG(13)?type?c,??????????????????"數量
????????ERFME?LIKE?MSEG-ERFME,????????????"單位
??????END?OF?RECORD.
DATA:?BEGIN?OF?RECORD1?OCCURS?0,
????????MATNR?LIKE?RM03M-MATNR,??????????"料號
????????WERKS?LIKE?RM03M-WERKS,??????????"工廠
????????LGORT?LIKE?RM03M-LGORT,??????????"倉碼
??????END?OF?RECORD1.
SELECTION-SCREEN?BEGIN?OF?BLOCK?BLOCK1?WITH?FRAME.
******?N?>?A
??PARAMETERS?CTUMODE?LIKE?CTU_PARAMS-DISMODE?DEFAULT?'N'?NO-DISPLAY.
*??PARAMETERS?CTUMODE?LIKE?CTU_PARAMS-DISMODE?DEFAULT?'P'.
??PARAMETERS?CUPDATE?LIKE?CTU_PARAMS-UPDMODE?DEFAULT?'L'?NO-DISPLAY.
??PARAMETERS?E_GROUP(12)?NO-DISPLAY.?????????????"group?name?of?error-session
??PARAMETERS:?E_USER(12)?DEFAULT?SY-UNAME?NO-DISPLAY.????"user?for?error-session
*??PARAMETERS:?E_KEEP?AS?CHECKBOX.?????"'?'?=?delete?session?if?finished
??????????????????????????????????????"'X'?=?keep???session?if?finished
??PARAMETERS:?E_HDATE?LIKE?SY-DATUM?NO-DISPLAY.
*SELECTION-SCREEN?SKIP.
??PARAMETERS:?NODATA?DEFAULT?'?'?LOWER?CASE?NO-DISPLAY.??????????"nodata
*??PARAMETERS:?SMALLLOG?AS?CHECKBOX.??"'?'?=?log?all?transactions
?????????????????????????????????????"'X'?=?no?transaction?logging
PARAMETERS:?p_qty?RADIOBUTTON?GROUP?g1.
PARAMETERS:?p_mat?RADIOBUTTON?GROUP?g1.
PARAMETERS:?FILENAME(132)?LOWER?CASE?DEFAULT
??????????????????????????????'C:\data.xls'.
SELECTION-SCREEN?END?OF?BLOCK?BLOCK1.
*&------------------------------------------------------------------*
*&?AT?SELECTION-SCREEN?ON?VALUE-REQUEST?FOR
*&------------------------------------------------------------------*
AT?SELECTION-SCREEN?ON?VALUE-REQUEST?FOR?FILENAME?.
??CALL?FUNCTION?'WS_FILENAME_GET'
??????EXPORTING
*??????????DEF_FILENAME?????=?'c:\test.xls'???????"default?selected?file
???????????DEF_PATH?????????=?'c:'????????????????"Default?path
*???????????MASK?????????????=?',*.txt,*.txt.'
???????????MASK?????????????=?',*.xls,*.xls.'
???????????MODE?????????????=?'0'
???????????TITLE????????????=?'Select?a?file?to?open'
?????IMPORTING
???????????FILENAME?????????=?FILENAME
*?????????RC???????????????=
???????EXCEPTIONS
????????????INV_WINSYS???????=?1
????????????NO_BATCH?????????=?2
????????????SELECTION_CANCEL?=?3
????????????SELECTION_ERROR??=?4
????????????OTHERS???????????=?5.
*&------------------------------------------------------------------*
START-OF-SELECTION.
??IF?P_QTY?=?'X'.
????PERFORM?INITIALIZE_QTY.
??ELSE.
????PERFORM?INITIALIZE_MAT.
??ENDIF.
??PERFORM?CLOSE_GROUP.
END-OF-SELECTION.
FORM?INITIALIZE_QTY.
??DATA:?FILENAME1?LIKE?RLGRAP-FILENAME.
??FILENAME1?=?FILENAME.
??TYPE-POOLS:truxs.
??DATA:l_raw_data?TYPE?truxs_t_text_data.
??CALL?FUNCTION?'TEXT_CONVERT_XLS_TO_SAP'
????EXPORTING
*???I_FIELD_SEPERATOR??????????=
*???I_LINE_HEADER??????????????=
??????i_tab_raw_data?????????????=?l_raw_data
??????i_filename?????????????????=?filename1
????TABLES
??????i_tab_converted_data???????=?record
*?EXCEPTIONS
*???CONVERSION_FAILED??????????=?1
*???OTHERS?????????????????????=?2
????????????.
??IF?sy-subrc?<>?0.
??????MESSAGE?E398(00)?WITH?'數據在導入內表時出錯!'.
??ENDIF.
??LOOP?AT?RECORD.
??perform?bdc_dynpro??????using?'SAPMM07M'?'0400'.
??perform?bdc_field???????using?'BDC_CURSOR'
????????????????????????????????'RM07M-WERKS'.
??perform?bdc_field???????using?'BDC_OKCODE'
????????????????????????????????'/00'.
??perform?bdc_field???????using?'MKPF-BLDAT'
????????????????????????????????RECORD-BLDAT.
??perform?bdc_field???????using?'MKPF-BUDAT'
????????????????????????????????RECORD-BUDAT.
??perform?bdc_field???????using?'RM07M-BWARTWA'
????????????????????????????????'561'.
??perform?bdc_field???????using?'RM07M-WERKS'
????????????????????????????????RECORD-WERKS.
??perform?bdc_field???????using?'XFULL'
????????????????????????????????'X'.
??perform?bdc_field???????using?'RM07M-WVERS2'
????????????????????????????????'X'.
??perform?bdc_dynpro??????using?'SAPMM07M'?'0421'.
??perform?bdc_field???????using?'BDC_CURSOR'
????????????????????????????????'MSEG-LGORT(01)'.
??perform?bdc_field???????using?'BDC_OKCODE'
????????????????????????????????'=BU'.
??perform?bdc_field???????using?'MSEG-MATNR(01)'
????????????????????????????????RECORD-MATNR.
??perform?bdc_field???????using?'MSEG-ERFMG(01)'
????????????????????????????????RECORD-ERFMG.
??perform?bdc_field???????using?'MSEG-ERFME(01)'
????????????????????????????????RECORD-ERFME.
??perform?bdc_field???????using?'MSEG-LGORT(01)'
????????????????????????????????RECORD-LGORT.
??perform?bdc_field???????using?'MSEG-WERKS(01)'
????????????????????????????????RECORD-WERKS.
??perform?bdc_field???????using?'DKACB-FMORE'
????????????????????????????????'X'.
??perform?bdc_dynpro??????using?'SAPLKACB'?'0002'.
??perform?bdc_field???????using?'BDC_OKCODE'
????????????????????????????????'=ENTE'.
??perform?bdc_dynpro??????using?'SAPLKACB'?'0002'.
??perform?bdc_field???????using?'BDC_OKCODE'
????????????????????????????????'=ENTE'.
??perform?bdc_transaction?using?'MB1C'.
??ENDLOOP.
ENDFORM.
FORM?INITIALIZE_MAT.
??DATA:?FILENAME1?LIKE?RLGRAP-FILENAME.
??FILENAME1?=?FILENAME.
??TYPE-POOLS:truxs.
??DATA:l_raw_data?TYPE?truxs_t_text_data.
??CALL?FUNCTION?'TEXT_CONVERT_XLS_TO_SAP'
????EXPORTING
*???I_FIELD_SEPERATOR??????????=
*???I_LINE_HEADER??????????????=
??????i_tab_raw_data?????????????=?l_raw_data
??????i_filename?????????????????=?filename1
????TABLES
??????i_tab_converted_data???????=?record1
*?EXCEPTIONS
*???CONVERSION_FAILED??????????=?1
*???OTHERS?????????????????????=?2
????????????.
??IF?sy-subrc?<>?0.
??????MESSAGE?E398(00)?WITH?'數據在導入內表時出錯!'.
??ENDIF.
??LOOP?AT?RECORD1.
??perform?bdc_dynpro??????using?'SAPMM03M'?'0105'.
??perform?bdc_field???????using?'BDC_CURSOR'
????????????????????????????????'RM03M-WERKS'.
??perform?bdc_field???????using?'BDC_OKCODE'
????????????????????????????????'/00'.
??perform?bdc_field???????using?'RM03M-MATNR'
????????????????????????????????RECORD1-MATNR.
??perform?bdc_field???????using?'RM03M-WERKS'
????????????????????????????????RECORD1-WERKS.
??perform?bdc_field???????using?'RM03M-LFLAG'
????????????????????????????????'X'.
??perform?bdc_dynpro??????using?'SAPMM03M'?'0195'.
??perform?bdc_field???????using?'BDC_CURSOR'
????????????????????????????????'RM03M-LGORT(09)'.
??perform?bdc_field???????using?'BDC_OKCODE'
????????????????????????????????'=BU'.
??perform?bdc_field???????using?'RM03M-LGORT(09)'
????????????????????????????????RECORD1-LGORT.
??perform?bdc_transaction?using?'MMSC'.
??ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*&??????Form??BDC_TRANSACTION
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
*????????Start?new?transaction?according?to?parameters?????????????????*
*----------------------------------------------------------------------*
FORM?BDC_TRANSACTION?USING?TCODE.
?DATA:?L_MSTRING(480).
??DATA:?L_SUBRC?LIKE?SY-SUBRC.
*?call?transaction?using
????REFRESH?MESSTAB.
????CALL?TRANSACTION?TCODE?USING?BDCDATA
?????????????????????MODE???CTUMODE
?????????????????????UPDATE?CUPDATE
?????????????????????MESSAGES?INTO?MESSTAB.
????L_SUBRC?=?SY-SUBRC.
????IF?SMALLLOG?<>?'X'.
??????WRITE:?/?'CALL_TRANSACTION',
???????????????TCODE,
???????????????'returncode:'(I05),
???????????????L_SUBRC,
???????????????'RECORD:',
???????????????SY-INDEX.
??????LOOP?AT?MESSTAB.
????????SELECT?SINGLE?*?FROM?T100?WHERE?SPRSL?=?MESSTAB-MSGSPRA
??????????????????????????????????AND???ARBGB?=?MESSTAB-MSGID
??????????????????????????????????AND???MSGNR?=?MESSTAB-MSGNR.
????????IF?SY-SUBRC?=?0.
??????????L_MSTRING?=?T100-TEXT.
??????????IF?L_MSTRING?CS?'&1'.
????????????REPLACE?'&1'?WITH?MESSTAB-MSGV1?INTO?L_MSTRING.
????????????REPLACE?'&2'?WITH?MESSTAB-MSGV2?INTO?L_MSTRING.
????????????REPLACE?'&3'?WITH?MESSTAB-MSGV3?INTO?L_MSTRING.
????????????REPLACE?'&4'?WITH?MESSTAB-MSGV4?INTO?L_MSTRING.
??????????ELSE.
????????????REPLACE?'&'?WITH?MESSTAB-MSGV1?INTO?L_MSTRING.
????????????REPLACE?'&'?WITH?MESSTAB-MSGV2?INTO?L_MSTRING.
????????????REPLACE?'&'?WITH?MESSTAB-MSGV3?INTO?L_MSTRING.
????????????REPLACE?'&'?WITH?MESSTAB-MSGV4?INTO?L_MSTRING.
??????????ENDIF.
??????????CONDENSE?L_MSTRING.
??????????WRITE:?/?MESSTAB-MSGTYP,?L_MSTRING(250).
????????ELSE.
??????????WRITE:?/?MESSTAB.
????????ENDIF.
??????ENDLOOP.
??????SKIP.
????ENDIF.
**?Erzeugen?fehlermappe?************************************************
????IF?L_SUBRC?<>?0?AND?E_GROUP?<>?SPACE.
??????IF?E_GROUP_OPENED?=?'?'.
????????CALL?FUNCTION?'BDC_OPEN_GROUP'
?????????????EXPORTING??CLIENT???=?SY-MANDT
????????????????????????GROUP????=?E_GROUP
????????????????????????USER?????=?E_USER
????????????????????????KEEP?????=?E_KEEP
????????????????????????HOLDDATE?=?E_HDATE.
?????????E_GROUP_OPENED?=?'X'.
??????ENDIF.
??????CALL?FUNCTION?'BDC_INSERT'
???????????EXPORTING?TCODE?????=?TCODE
???????????TABLES????DYNPROTAB?=?BDCDATA.
????ENDIF.
??REFRESH?BDCDATA.
endform.????????????????????"?BDC_TRANSACTION
*----------------------------------------------------------------------*
*????????Start?new?screen??????????????????????????????????????????????*
*----------------------------------------------------------------------*
FORM?BDC_DYNPRO?USING?PROGRAM?DYNPRO.
??CLEAR?BDCDATA.
??BDCDATA-PROGRAM??=?PROGRAM.
??BDCDATA-DYNPRO???=?DYNPRO.
??BDCDATA-DYNBEGIN?=?'X'.
??APPEND?BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
*????????Insert?field??????????????????????????????????????????????????*
*----------------------------------------------------------------------*
FORM?BDC_FIELD?USING?FNAM?FVAL.
??IF?FVAL?<>?NODATA.
????CLEAR?BDCDATA.
????BDCDATA-FNAM?=?FNAM.
????BDCDATA-FVAL?=?FVAL.
????APPEND?BDCDATA.
??ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&??????Form??CLOSE_GROUP
*&---------------------------------------------------------------------*
form?CLOSE_GROUP.
IF?E_GROUP_OPENED?=?'X'.
??????CALL?FUNCTION?'BDC_CLOSE_GROUP'.
??????WRITE:?/.
??????WRITE:?/(30)?'Fehlermappe?wurde?erzeugt'(I06).
????ENDIF.
endform.????????????????????"?CLOSE_GROUP
?
總結
以上是生活随笔為你收集整理的SAP MM 库存初始化和批量扩充物料仓位的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 寨卡病毒
- 下一篇: 修改ALSM_EXCEL_TO_INTE