В пользовательском отчете я использую функциональный модуль ME_UPDATE_INFORECORD
для изменения поля "номер материала поставщика" в информационных записях закупок некоторых указанных поставщиков.
Работает отлично, но документы изменений не пишутся.
Не могли бы вы проверить мой простой код и дать подсказку, как правильно вызвать функциональный модуль ME_CREATE_CHANGEDOC_INFOREC
, озаглавленный «Создание документов изменений для информационной записи».
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.