View previous topic :: View next topic
Author
Message
admin Администратор Joined: 01 Sep 2007 Posts: 1640
Posted: Sat May 10, 2008 8:51 pm Post subject: Consumption Value Upload
Consumption Value Upload
Author: Asis Mohanty
Original: https: //wiki.sdn.sap.com/wiki/display/Snippets/Consumption+Value+UploadConsumption+Value+Upload
Code: *---------------------------------------------------------------------*
*Report : ZDR178
*Description : Consumption Value Upload
*Date : 10-Jan-2008.
*Author : Satyam
*---------------------------------------------------------------------*
REPORT zdr178 MESSAGE-ID zpa
NO STANDARD PAGE HEADING LINE-SIZE 255.
*********************DB Table**************************************
TABLES: t100.
**********************Internal Table Declaration********************
*File to store uploaded data
DATA: BEGIN OF i_tab OCCURS 0,
matnr LIKE mver-matnr, "Material
werks LIKE mver-werks, "Plant
mgv01 LIKE mver-mgv01, "Consumption Value
mgv02 LIKE mver-mgv02,
mgv03 LIKE mver-mgv03,
mgv04 LIKE mver-mgv04,
mgv05 LIKE mver-mgv05,
mgv06 LIKE mver-mgv06,
mgv07 LIKE mver-mgv07,
mgv08 LIKE mver-mgv08,
mgv09 LIKE mver-mgv09,
mgv10 LIKE mver-mgv10,
mgv11 LIKE mver-mgv11,
mgv12 LIKE mver-mgv12,
END OF i_tab.
DATA: i_mver LIKE vstat OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF i_error OCCURS 0,
matnr LIKE mver-matnr,
werks like mver-werks,
errtext(250),
END OF i_error.
***********************Data Declaration*****************************
DATA: v_fisc LIKE bapi0002_4-fiscal_year, " store current fiscal year
v_period LIKE bapi0002_4-fiscal_period, "store current period
v_vstatdatum(8). "8 chara to hold date related data.
DATA: v_mstring(250).
************************Selection Screen***************************
PARAMETERS: pfile LIKE rlgrap-filename DEFAULT space.
**********************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR PFILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = space
def_path = pfile mask = ',.,..'
mode = 'E'
title = 'Choose File Name'
IMPORTING
filename = pfile
EXCEPTIONS
inv_winsys = 04
no_batch = 08
selection_cancel = 12
selection_error = 16.
IF sy-subrc EQ '04'.
MESSAGE e999(zpa) WITH 'FILE NOT FOUND'(e01).
ENDIF.
***********************************************************************
START-OF-SELECTION.
PERFORM f_upload_file.
PERFORM f_update_werks.
PERFORM f_print_errors.
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* Upload File
*----------------------------------------------------------------------*
FORM f_upload_file .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = pfile
filetype = 'DAT'
TABLES
data_tab = i_tab.
ENDFORM. " upload_file
*&---------------------------------------------------------------------*
*& Form f_update_werks
*&---------------------------------------------------------------------*
* Update Plant
*----------------------------------------------------------------------*
FORM f_update_werks .
LOOP AT i_tab.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks.
*Check validity of Material
CALL FUNCTION 'MARC_SINGLE_READ'
EXPORTING
matnr = i_mver-matnr
werks = i_mver-werks
EXCEPTIONS
lock_on_marc = 1
lock_system_error = 2
wrong_call = 3
not_found = 4
OTHERS = 5.
IF sy-subrc NE 0.
PERFORM f_error USING sy-msgid
sy-msgno
sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4
i_mver-matnr
i_mver-werks.
ELSE.
*Get Current Period
PERFORM f_get_start_period.
*Current Period
CONCATENATE v_fisc v_period '01' INTO v_vstatdatum.
i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv01.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 1
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv02.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 2
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv03.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 3
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv04.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 4
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv05.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 5
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv06.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 6
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv07.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 7
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv08.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 8
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv09.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 9
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv10.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 10
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv11.
APPEND i_mver.
CLEAR i_mver.
*Current Period - 11
PERFORM f_back_period CHANGING v_fisc v_period.
CONCATENATE v_fisc v_period '01'
INTO v_vstatdatum.
i_mver-matnr = i_tab-matnr.
i_mver-werks = i_tab-werks. i_mver-datum = v_vstatdatum.
i_mver-gsvbr = i_tab-mgv12.
APPEND i_mver.
CLEAR i_mver.
***
PERFORM f_update_cons_val.
REFRESH i_mver.
ENDIF.
ENDLOOP.
ENDFORM. " f_update_werks
*&---------------------------------------------------------------------*
*& Form f_update_cons_val
*&---------------------------------------------------------------------*
* Update Consumption Values
*----------------------------------------------------------------------*
FORM f_update_cons_val .
CALL FUNCTION 'MB_UPDATE_MATERIAL_CONSUMPTION'
TABLES
xvstat = i_mver
EXCEPTIONS
calendar_not_complete = 1
OTHERS = 2.
IF sy-subrc <> 0.
PERFORM f_error USING sy-msgid
sy-msgno
sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4
i_mver-matnr
i_mver-werks.
ENDIF.
ENDFORM. " f_update_cons_val
*&---------------------------------------------------------------------*
*& Form f_get_start_period
*&---------------------------------------------------------------------*
* Get Current Period
*----------------------------------------------------------------------*
FORM f_get_start_period .
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
companycodeid = 'MBIL'
posting_date = sy-datum
IMPORTING
fiscal_year = v_fisc
fiscal_period = v_period.
* RETURN =
ENDFORM. " f_get_start_period
*&---------------------------------------------------------------------*
*& Form f_back_period
*&---------------------------------------------------------------------*
* Get Previous Period
*----------------------------------------------------------------------*
FORM f_back_period CHANGING p_v_fisc
p_v_period.
IF v_period = 1.
v_period = 12.
v_fisc = v_fisc - 1.
ELSE.
v_period = v_period - 1.
ENDIF.
ENDFORM. " f_back_period
*&---------------------------------------------------------------------*
*& Form f_print_errors
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_print_errors .
format color 1.
uline.
write: 2 'Material', 20 'Plant', 26 'Message'.
uline.
format color off.
LOOP AT i_error.
WRITE:/2 i_error-matnr, 20 i_error-werks, 26 i_error-errtext.
skip.
ENDLOOP.
ENDFORM. " f_print_errors
*&---------------------------------------------------------------------*
*& Form f_error
*&---------------------------------------------------------------------*
* Fetch Errors
*----------------------------------------------------------------------*
* -->P_SY_MSGID text
* -->P_SY_MSGNO text
* -->P_SY_MSGV1 text
* -->P_SY_MSGV2 text
* -->P_SY_MSGV3 text
* -->P_SY_MSGV4 text
* -->P_i_mver_matnr Material
* -->p_i_mver_werks Plant
*----------------------------------------------------------------------*
FORM f_error USING p_sy_msgid
p_sy_msgno
p_sy_msgv1
p_sy_msgv2
p_sy_msgv3
p_sy_msgv4
p_i_mver_matnr
p_i_mver_werks.
.
SELECT SINGLE * FROM t100 WHERE sprsl = sy-langu
AND arbgb = p_sy_msgid
AND msgnr = p_sy_msgno.
IF sy-subrc = 0.
v_mstring = t100-text.
IF v_mstring CS '&1'.
REPLACE '&1' WITH p_sy_msgv1 INTO v_mstring.
REPLACE '&2' WITH p_sy_msgv2 INTO v_mstring.
REPLACE '&3' WITH p_sy_msgv3 INTO v_mstring.
REPLACE '&4' WITH p_sy_msgv4 INTO v_mstring.
ELSE.
REPLACE '&' WITH p_sy_msgv1 INTO v_mstring.
REPLACE '&' WITH p_sy_msgv2 INTO v_mstring.
REPLACE '&' WITH p_sy_msgv3 INTO v_mstring.
REPLACE '&' WITH p_sy_msgv4 INTO v_mstring.
ENDIF.
CONDENSE v_mstring.
i_error-matnr = p_i_mver_matnr.
i_error-werks = p_i_mver_werks.
i_error-errtext = v_mstring.
APPEND i_error.
CLEAR i_error.
ELSE.
CONCATENATE p_sy_msgv1 p_sy_msgv1 p_sy_msgv1 p_sy_msgv1 INTO v_mstring
.
i_error-matnr = p_i_mver_matnr.
i_error-werks = p_i_mver_werks.
i_error-errtext = v_mstring.
APPEND i_error.
CLEAR i_error.
ENDIF.
CLEAR v_mstring.
ENDFORM. " f_error
Keyword: потребление
Back to top
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.