在自定义报告中我使用功能模块ME_UPDATE_INFORECORD
在购买某些指定供应商的信息记录中更改字段"供应商材料号"。
它可以很好地工作,但没有编写更改文档。
您可以检查我的简单代码,并给我一个提示如何正确调用功能模块ME_CREATE_CHANGEDOC_INFOREC
标题为" Info Record的更改文档"。
REPORT zic_pir_update.
TABLES : eine,eina.
PARAMETERS : pa_esokz TYPE eine-esokz OBLIGATORY VALUE CHECK DEFAULT '0'.
SELECT-OPTIONS: so_matnr FOR eina-matnr DEFAULT '10016.70.001.03'.
TYPES: BEGIN OF ts_t001w,
werks TYPE t001w-werks,
zz_ic_lifnr TYPE t001w-zz_ic_lifnr,
END OF ts_t001w.
DATA gt_t001w TYPE STANDARD TABLE OF ts_t001w.
CLASS lcl_checkauthority DEFINITION.
PUBLIC SECTION.
TYPES: ls_001w TYPE STANDARD TABLE OF ts_t001w.
CLASS-METHODS :get_t001w
EXPORTING
lt_t001w TYPE ls_001w.
ENDCLASS.
CLASS lcl_checkauthority IMPLEMENTATION.
METHOD get_t001w.
SELECT werks ,zz_ic_lifnr FROM t001w
INTO TABLE @lt_t001w
WHERE zz_ic_lifnr <> ' '. "For intercompany process, plant is assigned
to intercompany supplier.
SORT lt_t001w BY werks.
LOOP AT lt_t001w ASSIGNING FIELD-SYMBOL(<lfs_t001w>).
AUTHORITY-CHECK OBJECT 'M_MATE_WRK' ID 'WERKS' FIELD <lfs_t001w>-werks
ID 'ACTVT' FIELD '03'.
IF sy-subrc NE 0.
MESSAGE e120(m7) WITH <lfs_t001w>-werks.
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
CLASS lcl_pir DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ts_mbew,
bklas TYPE mbew-bklas,
zz_ic_lifnr TYPE t001w-zz_ic_lifnr,
END OF ts_mbew.
TYPES : ts_eina_o TYPE eina,
ts_eine_o TYPE eine,
ts_eina_i TYPE eina,
ts_eine_i TYPE eine.
TYPES : ls_cd_eina_ua TYPE STANDARD TABLE OF veinaua,
ls_cd_eina_ua_old TYPE STANDARD TABLE OF veinaua.
CLASS-METHODS :get_eina_eine
EXPORTING
ls_eina_o TYPE ts_eina_o
ls_eine_o TYPE ts_eine_o
ls_mbew TYPE ts_mbew
ls_eina_i TYPE ts_eina_i
ls_eine_i TYPE ts_eine_i
lt_cd_eina_ua TYPE ls_cd_eina_ua
lt_cd_eina_ua_old TYPE ls_cd_eina_ua_old
lst_cd_eina_ua TYPE veinaua
lst_cd_eina_ua_old TYPE veinaua.
ENDCLASS.
CLASS lcl_pir IMPLEMENTATION.
METHOD get_eina_eine.
SELECT * FROM eina INTO ls_eina_o
FOR ALL ENTRIES IN gt_t001w
WHERE lifnr = gt_t001w-zz_ic_lifnr AND
loekz EQ ' ' AND
matnr IN so_matnr.
IF ls_eina_o-idnlf EQ ls_eina_o-matnr.
WRITE: / 'PIR'(001),ls_eina_o-infnr, 'Vendor'(002), ls_eina_o-lifnr,
'Material'(003) , ls_eina_o-matnr, 'not neccessary update'(004).
ELSE.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = ls_eina_o-matnr
IMPORTING
output = ls_eina_o-matnr
EXCEPTIONS
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF ls_eina_o-idnlf EQ ls_eina_o-matnr.
WRITE: / 'PIR'(001),ls_eina_o-infnr, 'Vendor'(002), ls_eina_o-lifnr,
'Material'(003) , ls_eina_o-matnr, 'not neccessary update'(004).
ELSE.
IF ( sy-subrc <> 0 AND sy-batch = 'X' ).
WRITE :/ 'no PIR found'(005).
RETURN.
ENDIF.
SELECT * FROM eine INTO ls_eine_o
FOR ALL ENTRIES IN gt_t001w
WHERE infnr = ls_eina_o-infnr AND
werks = gt_t001w-werks AND
esokz = pa_esokz AND
loekz EQ ' '.
ls_eina_i = ls_eina_o.
ls_eine_i = ls_eine_o.
ls_eina_o-idnlf = ls_eina_o-matnr.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = ls_eina_o-matnr
IMPORTING
output = ls_eina_o-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*check if it is IC Material. "#EC CI_BUFFJOIN
SELECT mbew~bklas, t001w~zz_ic_lifnr
UP TO 1 ROWS BYPASSING BUFFER
FROM mbew AS mbew INNER JOIN t001w AS t001w ON "#EC CI_BUFFJOIN
mbew~bwkey = t001w~bwkey
INTO @ls_mbew
WHERE mbew~matnr = @ls_eina_o-matnr AND
zz_ic_lifnr = @ls_eina_o-lifnr.
ENDSELECT.
*check if supplier is IC.
IF ( ls_eina_o-lifnr EQ ls_mbew-zz_ic_lifnr ).
CALL FUNCTION 'ME_UPDATE_INFORECORD'
EXPORTING
xeina = ls_eina_o "new
xeine = ls_eine_o "new
yeina = ls_eina_i "old
yeine = ls_eine_i "old
reg_eina = ls_eina_o. "new
lst_cd_eina_ua-idnlf = ls_eina_o-idnlf .
lst_cd_eina_ua_old-idnlf = ls_eina_i-idnlf .
lst_cd_eina_ua-infnr = ls_eina_o-infnr .
lst_cd_eina_ua_old-infnr = ls_eina_i-infnr .
APPEND :
lst_cd_eina_ua TO lt_cd_eina_ua,
lst_cd_eina_ua_old TO lt_cd_eina_ua_old.
WRITE : / 'PIR updated'(006),ls_eina_o-infnr, 'Vendor'(002),
ls_eina_o-lifnr, 'Material'(003) , ls_eina_o-matnr.
ELSE.
WRITE: / 'Material' , ls_eina_o-matnr, 'Vendor'(002), ls_eina_o-
lifnr, 'is not equeal to'(007), 'Vendor'(002),ls_mbew-zz_ic_lifnr.
ENDIF.
ENDSELECT.
ENDIF .
ENDIF.
ENDSELECT.
CALL FUNCTION 'ME_CREATE_CHANGEDOC_INFOREC'
TABLES
cd_eina_ua = lt_cd_eina_ua
cd_eina_ua_old = lt_cd_eina_ua_old
. " ME_CREATE_CHANGEDOC_INFOREC
COMMIT WORK.
IF sy-subrc EQ 0.
"All OK
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
*method call for authority check.
CALL METHOD lcl_checkauthority=>get_t001w
IMPORTING
lt_t001w = gt_t001w.
*method call for find for intercompany purchase info records
CALL METHOD lcl_pir=>get_eina_eine.
END-OF-SELECTION.
解决方案我将fm从'me_update_inforecord'更改为'me_direct_input_inforecord'和下一个FM,从'me_update_inforecord'更改为'me_pdate_inforecord'到'me_post_inforecord'''''请关闭此请求。在最终代码下方。
REPORT zic_pir_update LINE-SIZE 150.
TABLES : eina.
PARAMETERS : pa_esokz TYPE eine-esokz OBLIGATORY VALUE CHECK DEFAULT '0'.
SELECT-OPTIONS: so_matnr FOR eina-matnr.
TYPES: BEGIN OF ts_t001w,
werks TYPE t001w-werks,
zz_ic_lifnr TYPE t001w-zz_ic_lifnr,
END OF ts_t001w.
DATA gt_t001w TYPE STANDARD TABLE OF ts_t001w.
*example with local class/exporting**************************
CLASS lcl_checkauthority DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ts_t001w,
werks TYPE t001w-werks,
zz_ic_lifnr TYPE t001w-zz_ic_lifnr,
END OF ts_t001w.
TYPES: ls_t001w TYPE STANDARD TABLE OF ts_t001w.
CLASS-METHODS :get_t001w
EXPORTING
lt_t001w TYPE ls_t001w.
ENDCLASS.
CLASS lcl_checkauthority IMPLEMENTATION.
METHOD get_t001w.
SELECT werks ,zz_ic_lifnr FROM t001w
INTO TABLE @lt_t001w
WHERE zz_ic_lifnr <> ' '. "For intercompany process, plant is assigned to
intercompany supplier.
SORT lt_t001w BY werks.
LOOP AT lt_t001w ASSIGNING FIELD-SYMBOL(<lfs_t001w>).
AUTHORITY-CHECK OBJECT 'M_MATE_WRK' ID 'WERKS' FIELD <lfs_t001w>-werks
ID 'ACTVT' FIELD '03'.
IF sy-subrc NE 0.
MESSAGE e120(m7) WITH <lfs_t001w>-werks.
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
CLASS lcl_pir DEFINITION.
PUBLIC SECTION.
TYPES : ts_eina_o TYPE eina,
ts_eine_o TYPE eine,
ts_eina_i TYPE eina,
ts_eine_i TYPE eine,
ts_eina TYPE STANDARD TABLE OF eina.
*reconstruct the table type without the corresponding input fields using the type
addition RANGE OF.
TYPES sv_matnr TYPE RANGE OF eina-matnr.
CLASS-METHODS :get_eina_eine
IMPORTING
pv_esokz TYPE eine-esokz
sv_matnr TYPE sv_matnr
EXPORTING
ls_eina_o TYPE ts_eina_o
ls_eine_o TYPE ts_eine_o
ls_eina_i TYPE ts_eina_i
ls_eine_i TYPE ts_eine_i
lt_eina_o TYPE ts_eina
lt_eina_n TYPE ts_eina
ls_eina_n TYPE ts_eina_o.
ENDCLASS.
CLASS lcl_pir IMPLEMENTATION.
METHOD get_eina_eine.
SELECT * FROM eina INTO TABLE lt_eina_o FOR ALL ENTRIES IN gt_t001w
WHERE lifnr = gt_t001w-zz_ic_lifnr AND
loekz EQ ' ' AND
matnr IN sv_matnr.
* batch job found no entry.
IF ( sy-subrc <> 0 AND sy-batch = 'X' ).
WRITE :/ 'no PIR found'(005).
RETURN.
ENDIF.
LOOP AT lt_eina_o INTO ls_eina_o.
*If in PIR 'vendor material number' eina-idnlf does not equal with the material in
the form 0000000XXXXXXXXXXXX.
IF ls_eina_o-idnlf EQ ls_eina_o-matnr.
WRITE: / 'PIR'(001),ls_eina_o-infnr, 'Vendor'(002), ls_eina_o-lifnr,
'Material'(003) , ls_eina_o-matnr, 'not neccessary update in field Vendor Mat.
No.'(004).
ELSE.
* CONVERSION from 0000000XXXXXXXXXXXX to XXXXX.XX.XXX.XX
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = ls_eina_o-matnr
IMPORTING
output = ls_eina_o-matnr
EXCEPTIONS
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*If in PIR 'vendor material number' eina-idnlf does not equal with the material in
the form of XXXXX.XX.XXX.XX
IF ls_eina_o-idnlf EQ ls_eina_o-matnr.
WRITE: / 'PIR'(001),ls_eina_o-infnr, 'Vendor'(002), ls_eina_o-lifnr,
'Material'(003) , ls_eina_o-matnr, 'not neccessary update in field Vendor Mat.
no.'(004).
ELSE.
SELECT * FROM eine INTO ls_eine_o
UP TO 1 ROWS
FOR ALL ENTRIES IN gt_t001w
WHERE infnr = ls_eina_o-infnr AND
werks = gt_t001w-werks AND
esokz = pv_esokz AND
loekz EQ ' '.
ENDSELECT.
IF sy-subrc = 0.
*CONVERSION from XXXXX.XX.XXX.XX to 0000000XXXXXXXXXXXX.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = ls_eina_o-matnr
IMPORTING
output = ls_eina_o-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ls_eina_i = ls_eina_o.
ls_eine_i = ls_eine_o.
ls_eina_o-idnlf = ls_eina_o-matnr.
*FM to change condition records into inforecord
CALL FUNCTION 'ME_INITIALIZE_INFORECORD'.
CALL FUNCTION 'ME_DIRECT_INPUT_INFORECORD'
EXPORTING
activity = 'V' " Aktivitätstyp: 'A' Anzeigen, 'V'
Pflegen
i_eina = ls_eina_o " Infosatz allgemeine Daten neuer
Stand
o_eina = ls_eina_i " Infosatz allgemeine Daten alter
Stand
i_no_suppose = 'X' " Keine Vorschlagsdaten setzen
i_vorga = 'A' " Wer ruft den Funktionsbaustein auf?
* i_skip_nr_check = " Skip number range check
IMPORTING
e_eina = ls_eina_n " Infosatz allgemeine Daten neuer
stand
EXCEPTIONS
textname_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
APPEND:ls_eina_n TO lt_eina_n.
CALL FUNCTION 'ME_POST_INFORECORD'
TABLES
t_eina_i = lt_eina_n " Einkaufsinfosatz - allgemeine Daten: Neue Sätze
EXCEPTIONS
OTHERS = 2.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
WRITE : / 'Vendor Mat. No. in PIR updated'(006) COLOR COL_KEY,ls_eina_o-
infnr COLOR COL_KEY, 'Vendor'(002) COLOR COL_KEY,
ls_eina_o-lifnr COLOR COL_KEY, 'Material'(003) COLOR COL_KEY ,
ls_eina_o-matnr COLOR COL_KEY.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
*method call for authority check.
CALL METHOD lcl_checkauthority=>get_t001w
IMPORTING
lt_t001w = gt_t001w.
*method call for find for intercompany purchase info records
CALL METHOD lcl_pir=>get_eina_eine
EXPORTING
pv_esokz = pa_esokz
sv_matnr = so_matnr[].
END-OF-SELECTION.