Code: Alles auswählen.
ABLES: mseg, mver, mkpf.
DATA: it_mseg LIKE STANDARD TABLE OF mseg,
wa_mseg LIKE LINE OF it_mseg.
DATA: it_mver LIKE STANDARD TABLE OF mver,
wa_mver LIKE LINE OF it_mver.
TYPES: BEGIN OF zeile_typ,
mblnr LIKE mkpf-mblnr,
bldat LIKE mkpf-bldat,
matnr LIKE mseg-matnr,
END OF zeile_typ.
TYPES it_mkpf_typ TYPE STANDARD TABLE OF zeile_typ.
DATA: it_mkpf TYPE it_mkpf_typ.
DATA: wa_mkpf TYPE zeile_typ.
SELECT-OPTIONS:
belart FOR mkpf-blart,
mblnr FOR mkpf-mblnr,
werk FOR mver-werks,
p_matnr FOR mver-matnr.
*
*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: r1 RADIOBUTTON GROUP rad1 USER-COMMAND radio,
r2 RADIOBUTTON GROUP rad1 DEFAULT 'X' .
SELECTION-SCREEN END OF BLOCK b1.
*
*start-of-selection.
SELECT mkpf~mblnr mkpf~bldat mseg~matnr FROM mkpf
INNER JOIN mseg ON mkpf~mblnr = mseg~mblnr INTO CORRESPONDING FIELDS OF TABLE it_mkpf
WHERE mkpf~mjahr > '2009' AND mseg~matnr IN p_matnr AND mseg~werks IN werk AND mseg~bwart = '601'
AND mkpf~mblnr IN mblnr AND mkpf~blart IN belart.
"and blart in belart and mblnr in mblnr . "Alle Belegnummern mit Belegdatum die dem Mandant entsprechen
*DESCRIBE TABLE it_mkpf.
SELECT mver~matnr mver~muv01 mver~muv02 mver~muv03 mver~muv04 mver~muv05 mver~muv06 mver~muv07 mver~muv08 mver~muv09 mver~muv10 mver~muv11 mver~muv12
FROM mver INTO CORRESPONDING FIELDS OF TABLE it_mver WHERE matnr IN p_matnr AND werks IN werk.
LOOP AT it_mkpf INTO wa_mkpf. " Aktuelle MBLNR
DATA: zunplnd LIKE mseg-menge.
DATA: zbelnr LIKE mseg-mblnr.
DATA: zbldat LIKE mkpf-bldat.
DATA: monat TYPE n LENGTH 2.
DATA lv_menge TYPE mseg-menge.
CLEAR: zunplnd, zbelnr, zbldat, monat, lv_menge.
ADD wa_mkpf-mblnr TO zbelnr. " Übergabe MBLNR
ADD wa_mkpf-bldat TO zbldat. " Übergabe Datum
SELECT SUM( menge ) FROM mseg INTO lv_menge
WHERE matnr = wa_mkpf-matnr AND werks = '2211' and bwart = '601' AND MBLNR = wa_mkpf-mblnr.
DATA zeilen TYPE i.
DATA l_field TYPE char5. "l_field = Feldname
FIELD-SYMBOLS <l_field> TYPE ANY. " Zeiger
monat = zbldat+4(2). " Feld Monat erhält den Monat des Belegdatums
DATA lt_amveu TYPE TABLE OF mveu_ueb.
DATA ls_amveu TYPE mveu_ueb.
LOOP AT it_mver INTO wa_mver WHERE matnr = wa_mkpf-matnr .
CONCATENATE 'MUV' monat INTO l_field.
ASSIGN COMPONENT l_field OF STRUCTURE wa_mver TO <l_field>.
ADD lv_menge TO <l_field>.
*
ls_amveu-matnr = wa_mver-matnr.
ls_amveu-werks = wa_mver-werks.
CONCATENATE zbldat(6) '01' INTO ls_amveu-ertag.
ls_amveu-kovbw = lv_menge.
ls_amveu-kzexi = 'X'.
COLLECT ls_amveu INTO lt_amveu.
clear: ls_amveu-kovbw, lv_menge.
ENDLOOP.
ENDLOOP.
IF r1 = 'X'.
DATA lt_amveug type table of mveg_ueb.
* data ls_amveug type mveg_ueb.
select * from mver into corresponding fields of table lt_amveug.
* ls_amveug-matnr = wa_mver-matnr.
* ls_amveug-werks = wa_mver-werks.
*
* CONCATENATE zbldat(6) '01' INTO ls_amveug-ertag.
*
* ls_amveu-kovbw = ls_amveu-vbwrt.
* ls_amveug-kzexi = 'X'.
*
* COLLECT ls_amveug INTO lt_amveug.
CALL FUNCTION 'MVER_MAINTAIN_DARK'
* EXPORTING
* SPERRMODUS = ' '
* MAX_ERRORS = 0
TABLES
AMVEG_UEB = lt_amveug
amveu_ueb = lt_amveu
* AMERRDAT_F =
* EXCEPTIONS
* UPDATE_ERROR = 1
* INTERNAL_ERROR = 2
* TOO_MANY_ERRORS = 3
* OTHERS = 4
.
IF sy-subrc = 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
loop at lt_amveu into ls_amveu.
write:/ 'Field MUV',monat, ' updated by value', ls_amveu-kovbw.endloop.
elseif sy-subrc <> 0. write:/ 'Update unsuccesfull'.
ENDIF.
"update_mver
endif.
if r2 = 'X'.
loop at lt_amveu into ls_amveu.
WRITE:/ ls_amveu-matnr, 'MVER-Field ', ' MUV',monat, 'value', ls_amveu-kovbw. endloop.endif.
Code: Alles auswählen.
CALL FUNCTION 'MVER_MAINTAIN_DARK'
* EXPORTING
* SPERRMODUS = ' '
* MAX_ERRORS = 0
TABLES
amveg_ueb = lt_amveug
amveu_ueb = lt_amveu
* AMERRDAT_F =
* EXCEPTIONS
* UPDATE_ERROR = 1
* INTERNAL_ERROR = 2
* TOO_MANY_ERRORS = 3
* OTHERS = 4
.
IF sy-subrc = 0.
commit work.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
LOOP AT lt_amveu INTO ls_amveu.
WRITE:/ ls_amveu-matnr, l_field, ' updated by value', ls_amveu-kovbw.
ENDLOOP.
ELSEIF sy-subrc <> 0.
WRITE:/ 'Update unsuccesfull'.
ENDIF.