MR21批量修改物料价格-BDC
生活随笔
收集整理的這篇文章主要介紹了
MR21批量修改物料价格-BDC
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
REPORT??z_update_price.
TABLES:sscrfields,t100.
*&-------------------------------------------------------------------
*??data?declaration
*&------------------------------------------------------------------*
***定義裝載EXCEL表數據的內表
DATA:excelitab?LIKE?alsmex_tabline?OCCURS?0?WITH?HEADER?LINE.
DATA:?result?TYPE?i,
??????j?TYPE?i,
??????l_mstring(480),????????????????????????????????"消息字符串
??????msgtab?LIKE?bdcmsgcoll?OCCURS?0?WITH?HEADER?LINE."定義消息內表
DATA:?BEGIN?OF?bdcdata?OCCURS?0.
????????INCLUDE?STRUCTURE?bdcdata.
DATA:?END?OF?bdcdata.
DATA:BEGIN?OF?wa,
?????werks(4),
?????matnr(18),
?????price(15),
END?OF?wa.
DATA?itab?LIKE?wa?OCCURS?0?WITH?HEADER?LINE.
*&------------------------------------------------------------------*
*&?SELECT-OPTIONS
*&------------------------------------------------------------------*
SELECTION-SCREEN:BEGIN?OF?BLOCK?b1?WITH?FRAME?TITLE?tt1?NO?INTERVALS,
BEGIN?OF?LINE,
COMMENT?(10)?text1.
PARAMETERS?p_file?LIKE?rlgrap-filename?VISIBLE?LENGTH?30.
SELECTION-SCREEN:
PUSHBUTTON?44(10)?btn1?USER-COMMAND?cli1,
END?OF?LINE,
END?OF?BLOCK?b1.
*&------------------------------------------------------------------*
*&??at?selection-screen?????????“F4?for?PC?Input?file
*&------------------------------------------------------------------*
AT?SELECTION-SCREEN?.
??CASE?sscrfields.
????WHEN?'CLI1'.
??????CALL?FUNCTION?'WS_FILENAME_GET'
????????EXPORTING
??????????def_filename?????=?''
??????????def_path?????????=?'D:\'
??????????mask?????????????=?',*.XLS,*.XLS.'
*??????????MODE?????????????=?'0'
??????????title????????????=?'選擇需要導入的文件'
????????IMPORTING
??????????filename?????????=?p_file
????????EXCEPTIONS
??????????inv_winsys???????=?1
??????????no_batch?????????=?2
??????????selection_cancel?=?3
??????????selection_error??=?4
??????????OTHERS???????????=?5.
??ENDCASE.
*&------------------------------------------------------------------*
*&?Initialization
*&------------------------------------------------------------------*
INITIALIZATION.
??tt1?=?'請選擇要上傳的文件'.
??text1?=?'上傳文件:'.
??btn1?=?'瀏覽…'.
*&---------------------------------------------------------------------*
*?START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
??PERFORM?check_file.
??PERFORM?read_file.
??PERFORM?input_data.
END-OF-SELECTION.
??PERFORM?write_msg.
**&---------------------------------------------------------------------*
*?START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
??PERFORM?check_file.
??PERFORM?read_file.
??PERFORM?input_data.
END-OF-SELECTION.
??PERFORM?write_msg.
*&---------------------------------------------------------------------*
*&??????Form??CHECK_FILE
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?check_file?.
??CALL?FUNCTION?'WS_QUERY'
????EXPORTING
??????filename???????=?p_file
??????query??????????=?'FE'
????IMPORTING
??????return?????????=?result
????EXCEPTIONS
??????inv_query??????=?1
??????no_batch???????=?2
??????frontend_error?=?3
??????OTHERS?????????=?4.
??IF?result?=?0.
????MESSAGE?i888(sabapdocu)?WITH??p_file?'上傳文件不存在!'.
????STOP.
??ENDIF.
ENDFORM.????????????????????"?CHECK_FILE
*&---------------------------------------------------------------------*
*&??????Form??READ_FILE
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?read_file?.
??CALL?FUNCTION?'ALSM_EXCEL_TO_INTERNAL_TABLE'
????EXPORTING
??????filename????????????????=?p_file
??????i_begin_col?????????????=?1???????"開始列
??????i_begin_row?????????????=?2???????"開始行
??????i_end_col???????????????=?20??????"結束列
??????i_end_row???????????????=?9999????"結束行
????TABLES
??????intern??????????????????=?excelitab
????EXCEPTIONS
??????inconsistent_parameters?=?1
??????upload_ole??????????????=?2
??????OTHERS??????????????????=?3.
??IF?sy-subrc?<>?0.
????MESSAGE?i888(sabapdocu)?WITH?'UPLOAD?ERROR!'.
??ENDIF.
??SORT?excelitab?BY?row?col.
??REFRESH?itab.
??CLEAR?itab.
??LOOP?AT?excelitab.
????CASE?excelitab-col.
??????WHEN?'0001'.
????????wa-werks?=?excelitab-value.????"工廠
??????WHEN?'0002'.
????????wa-matnr?=?excelitab-value.????"
??????WHEN?'0003'.
????????wa-price?=?excelitab-value.????"
????ENDCASE.
????AT?END?OF?row.
??????APPEND?wa?TO?itab..
??????CLEAR?wa.
????ENDAT.
??ENDLOOP.
ENDFORM.????????????????????"?READ_FILE
*&---------------------------------------------------------------------*
*&??????Form??INPUT_DATA
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?input_data?.
??LOOP?AT?itab?INTO?wa.
***第一個屏幕
????PERFORM?bdc_dynpro?USING?'SAPRCKM_MR21'?'0201'.
????PERFORM?bdc_field?USING?'BDC_OKCODE'?'=ENTR'.
????PERFORM?bdc_field?USING?'MR21HEAD-BUDAT'?'2012.02.29'.
????PERFORM?bdc_field?USING?'MR21HEAD-BUKRS'?'4000'.
????PERFORM?bdc_field?USING?'MR21HEAD-WERKS'?wa-werks.
*********
????PERFORM?bdc_dynpro?USING?'SAPRCKM_MR21'?'0201'.
????PERFORM?bdc_field?USING?'BDC_OKCODE'?'=ENTR'.
????PERFORM?bdc_field?USING?'CKI_MR21_0250-MATNR(01)'?wa-matnr.
????PERFORM?bdc_field?USING?'CKI_MR21_0250-NEWVALPR(01)'?wa-price.
*******
????PERFORM?bdc_dynpro?USING?'SAPRCKM_MR21'?'0201'.
????PERFORM?bdc_field?USING?'BDC_OKCODE'?'=SAVE'.
********
????CALL?TRANSACTION?'MR21'?USING?bdcdata?MODE?'E'?MESSAGES?INTO?msgtab.
????CLEAR?bdcdata[].
??ENDLOOP.
ENDFORM.????????????????????"?INPUT_DATA
*&---------------------------------------------------------------------*
*&??????Form??BDC_DYNPRO
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??????-->P_0416???text
*??????-->P_0417???text
*----------------------------------------------------------------------*
FORM?bdc_dynpro??USING??program?dynpro.
??CLEAR?bdcdata.
??bdcdata-program?=?program.
??bdcdata-dynpro?=?dynpro.
??bdcdata-dynbegin?=?'X'.
??APPEND?bdcdata.
ENDFORM.????????????????????"?BDC_DYNPRO
*&---------------------------------------------------------------------*
*&??????Form??BDC_FIELD
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??????-->P_0421???text
*??????-->P_0422???text
*----------------------------------------------------------------------*
FORM?bdc_field??USING?fnam?fval.
??CLEAR?bdcdata.
??bdcdata-fnam?=?fnam.
??bdcdata-fval?=?fval.
??APPEND?bdcdata.
ENDFORM.????????????????????"?BDC_FIELD
*&---------------------------------------------------------------------*
*&??????Form??WRITE_MSG
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?write_msg?.
??WRITE?:?/?'消息類型',?20?'消息內容'.
??LOOP?AT?msgtab.
????SELECT?SINGLE?*?FROM?t100?WHERE?sprsl?=?msgtab-msgspra
???????????????????????????AND?arbgb?=?msgtab-msgid
???????????????????????????AND?msgnr?=?msgtab-msgnr.
????IF?sy-subrc?=?0.
??????l_mstring?=?t100-text.
??????IF?l_mstring?CS?'&1'.
????????REPLACE?'&1'?WITH?msgtab-msgv1?INTO?l_mstring.
????????REPLACE?'&2'?WITH?msgtab-msgv2?INTO?l_mstring.
????????REPLACE?'&3'?WITH?msgtab-msgv3?INTO?l_mstring.
????????REPLACE?'&4'?WITH?msgtab-msgv4?INTO?l_mstring.
??????ELSE.
????????REPLACE?'&'?WITH?msgtab-msgv1?INTO?l_mstring.
????????REPLACE?'&'?WITH?msgtab-msgv2?INTO?l_mstring.
????????REPLACE?'&'?WITH?msgtab-msgv3?INTO?l_mstring.
????????REPLACE?'&'?WITH?msgtab-msgv4?INTO?l_mstring.
??????ENDIF.
??????CONDENSE?l_mstring.
??????WRITE:?/?msgtab-msgtyp,?20?l_mstring.
????ELSE.
??????WRITE:?/?msgtab.
????ENDIF.
??ENDLOOP.
ENDFORM.????????????????????"?WRITE_MSG
TABLES:sscrfields,t100.
*&-------------------------------------------------------------------
*??data?declaration
*&------------------------------------------------------------------*
***定義裝載EXCEL表數據的內表
DATA:excelitab?LIKE?alsmex_tabline?OCCURS?0?WITH?HEADER?LINE.
DATA:?result?TYPE?i,
??????j?TYPE?i,
??????l_mstring(480),????????????????????????????????"消息字符串
??????msgtab?LIKE?bdcmsgcoll?OCCURS?0?WITH?HEADER?LINE."定義消息內表
DATA:?BEGIN?OF?bdcdata?OCCURS?0.
????????INCLUDE?STRUCTURE?bdcdata.
DATA:?END?OF?bdcdata.
DATA:BEGIN?OF?wa,
?????werks(4),
?????matnr(18),
?????price(15),
END?OF?wa.
DATA?itab?LIKE?wa?OCCURS?0?WITH?HEADER?LINE.
*&------------------------------------------------------------------*
*&?SELECT-OPTIONS
*&------------------------------------------------------------------*
SELECTION-SCREEN:BEGIN?OF?BLOCK?b1?WITH?FRAME?TITLE?tt1?NO?INTERVALS,
BEGIN?OF?LINE,
COMMENT?(10)?text1.
PARAMETERS?p_file?LIKE?rlgrap-filename?VISIBLE?LENGTH?30.
SELECTION-SCREEN:
PUSHBUTTON?44(10)?btn1?USER-COMMAND?cli1,
END?OF?LINE,
END?OF?BLOCK?b1.
*&------------------------------------------------------------------*
*&??at?selection-screen?????????“F4?for?PC?Input?file
*&------------------------------------------------------------------*
AT?SELECTION-SCREEN?.
??CASE?sscrfields.
????WHEN?'CLI1'.
??????CALL?FUNCTION?'WS_FILENAME_GET'
????????EXPORTING
??????????def_filename?????=?''
??????????def_path?????????=?'D:\'
??????????mask?????????????=?',*.XLS,*.XLS.'
*??????????MODE?????????????=?'0'
??????????title????????????=?'選擇需要導入的文件'
????????IMPORTING
??????????filename?????????=?p_file
????????EXCEPTIONS
??????????inv_winsys???????=?1
??????????no_batch?????????=?2
??????????selection_cancel?=?3
??????????selection_error??=?4
??????????OTHERS???????????=?5.
??ENDCASE.
*&------------------------------------------------------------------*
*&?Initialization
*&------------------------------------------------------------------*
INITIALIZATION.
??tt1?=?'請選擇要上傳的文件'.
??text1?=?'上傳文件:'.
??btn1?=?'瀏覽…'.
*&---------------------------------------------------------------------*
*?START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
??PERFORM?check_file.
??PERFORM?read_file.
??PERFORM?input_data.
END-OF-SELECTION.
??PERFORM?write_msg.
**&---------------------------------------------------------------------*
*?START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
??PERFORM?check_file.
??PERFORM?read_file.
??PERFORM?input_data.
END-OF-SELECTION.
??PERFORM?write_msg.
*&---------------------------------------------------------------------*
*&??????Form??CHECK_FILE
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?check_file?.
??CALL?FUNCTION?'WS_QUERY'
????EXPORTING
??????filename???????=?p_file
??????query??????????=?'FE'
????IMPORTING
??????return?????????=?result
????EXCEPTIONS
??????inv_query??????=?1
??????no_batch???????=?2
??????frontend_error?=?3
??????OTHERS?????????=?4.
??IF?result?=?0.
????MESSAGE?i888(sabapdocu)?WITH??p_file?'上傳文件不存在!'.
????STOP.
??ENDIF.
ENDFORM.????????????????????"?CHECK_FILE
*&---------------------------------------------------------------------*
*&??????Form??READ_FILE
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?read_file?.
??CALL?FUNCTION?'ALSM_EXCEL_TO_INTERNAL_TABLE'
????EXPORTING
??????filename????????????????=?p_file
??????i_begin_col?????????????=?1???????"開始列
??????i_begin_row?????????????=?2???????"開始行
??????i_end_col???????????????=?20??????"結束列
??????i_end_row???????????????=?9999????"結束行
????TABLES
??????intern??????????????????=?excelitab
????EXCEPTIONS
??????inconsistent_parameters?=?1
??????upload_ole??????????????=?2
??????OTHERS??????????????????=?3.
??IF?sy-subrc?<>?0.
????MESSAGE?i888(sabapdocu)?WITH?'UPLOAD?ERROR!'.
??ENDIF.
??SORT?excelitab?BY?row?col.
??REFRESH?itab.
??CLEAR?itab.
??LOOP?AT?excelitab.
????CASE?excelitab-col.
??????WHEN?'0001'.
????????wa-werks?=?excelitab-value.????"工廠
??????WHEN?'0002'.
????????wa-matnr?=?excelitab-value.????"
??????WHEN?'0003'.
????????wa-price?=?excelitab-value.????"
????ENDCASE.
????AT?END?OF?row.
??????APPEND?wa?TO?itab..
??????CLEAR?wa.
????ENDAT.
??ENDLOOP.
ENDFORM.????????????????????"?READ_FILE
*&---------------------------------------------------------------------*
*&??????Form??INPUT_DATA
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?input_data?.
??LOOP?AT?itab?INTO?wa.
***第一個屏幕
????PERFORM?bdc_dynpro?USING?'SAPRCKM_MR21'?'0201'.
????PERFORM?bdc_field?USING?'BDC_OKCODE'?'=ENTR'.
????PERFORM?bdc_field?USING?'MR21HEAD-BUDAT'?'2012.02.29'.
????PERFORM?bdc_field?USING?'MR21HEAD-BUKRS'?'4000'.
????PERFORM?bdc_field?USING?'MR21HEAD-WERKS'?wa-werks.
*********
????PERFORM?bdc_dynpro?USING?'SAPRCKM_MR21'?'0201'.
????PERFORM?bdc_field?USING?'BDC_OKCODE'?'=ENTR'.
????PERFORM?bdc_field?USING?'CKI_MR21_0250-MATNR(01)'?wa-matnr.
????PERFORM?bdc_field?USING?'CKI_MR21_0250-NEWVALPR(01)'?wa-price.
*******
????PERFORM?bdc_dynpro?USING?'SAPRCKM_MR21'?'0201'.
????PERFORM?bdc_field?USING?'BDC_OKCODE'?'=SAVE'.
********
????CALL?TRANSACTION?'MR21'?USING?bdcdata?MODE?'E'?MESSAGES?INTO?msgtab.
????CLEAR?bdcdata[].
??ENDLOOP.
ENDFORM.????????????????????"?INPUT_DATA
*&---------------------------------------------------------------------*
*&??????Form??BDC_DYNPRO
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??????-->P_0416???text
*??????-->P_0417???text
*----------------------------------------------------------------------*
FORM?bdc_dynpro??USING??program?dynpro.
??CLEAR?bdcdata.
??bdcdata-program?=?program.
??bdcdata-dynpro?=?dynpro.
??bdcdata-dynbegin?=?'X'.
??APPEND?bdcdata.
ENDFORM.????????????????????"?BDC_DYNPRO
*&---------------------------------------------------------------------*
*&??????Form??BDC_FIELD
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??????-->P_0421???text
*??????-->P_0422???text
*----------------------------------------------------------------------*
FORM?bdc_field??USING?fnam?fval.
??CLEAR?bdcdata.
??bdcdata-fnam?=?fnam.
??bdcdata-fval?=?fval.
??APPEND?bdcdata.
ENDFORM.????????????????????"?BDC_FIELD
*&---------------------------------------------------------------------*
*&??????Form??WRITE_MSG
*&---------------------------------------------------------------------*
*???????text
*----------------------------------------------------------------------*
*??-->??p1????????text
*??<--??p2????????text
*----------------------------------------------------------------------*
FORM?write_msg?.
??WRITE?:?/?'消息類型',?20?'消息內容'.
??LOOP?AT?msgtab.
????SELECT?SINGLE?*?FROM?t100?WHERE?sprsl?=?msgtab-msgspra
???????????????????????????AND?arbgb?=?msgtab-msgid
???????????????????????????AND?msgnr?=?msgtab-msgnr.
????IF?sy-subrc?=?0.
??????l_mstring?=?t100-text.
??????IF?l_mstring?CS?'&1'.
????????REPLACE?'&1'?WITH?msgtab-msgv1?INTO?l_mstring.
????????REPLACE?'&2'?WITH?msgtab-msgv2?INTO?l_mstring.
????????REPLACE?'&3'?WITH?msgtab-msgv3?INTO?l_mstring.
????????REPLACE?'&4'?WITH?msgtab-msgv4?INTO?l_mstring.
??????ELSE.
????????REPLACE?'&'?WITH?msgtab-msgv1?INTO?l_mstring.
????????REPLACE?'&'?WITH?msgtab-msgv2?INTO?l_mstring.
????????REPLACE?'&'?WITH?msgtab-msgv3?INTO?l_mstring.
????????REPLACE?'&'?WITH?msgtab-msgv4?INTO?l_mstring.
??????ENDIF.
??????CONDENSE?l_mstring.
??????WRITE:?/?msgtab-msgtyp,?20?l_mstring.
????ELSE.
??????WRITE:?/?msgtab.
????ENDIF.
??ENDLOOP.
ENDFORM.????????????????????"?WRITE_MSG
總結
以上是生活随笔為你收集整理的MR21批量修改物料价格-BDC的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 导出SAP表结构到EXCEl
- 下一篇: 物料价格分析取未分摊和未分配价格差异