‎2007 Jul 17 11:19 AM
<i>Can someone please demonstrate the how to work with the function module changedocument_read with a example.</i>
Thank you.
‎2007 Jul 17 11:23 AM
Hi,
The function module reads change document headers and change document items and processes the old and new values according to their category. In some cases, the units and currencies are added on to the value fields.
The object class is expected as minimum entry.
The program RSSCD200 uses this function module and can be regarded as a possible application.
Using the parameter LOCAL_TIME you can specify whether a local date and time should be transferred (re: time zone) or the system date and time (default).
Example call:
DATA: NUMMER LIKE CDPOS-CHANGNR,
TABNAME LIKE CDPOS-TABNAME,
TABKEY LIKE CDPOS-TABKEY.
DATA: BEGIN OF EDIT_FORM OCCURS 50.
INCLUDE STRUCTURE CDRED.
DATA: END OF EDIT_FORM.
...
CALL FUNCTION 'CHANGEDOCUMENT_READ'
EXPORTING OBJECTCLASS = 'BANF'
TABLES EDITPOS = EDIT_FORM
EXCEPTIONS ...
Hope it was useful.
Thanks,
Sandeep.
‎2007 Jul 17 2:32 PM
‎2007 Jul 17 2:38 PM
CALL FUNCTION 'CHANGEDOCUMENT_READ'
EXPORTING
ARCHIVE_HANDLE = 0
CHANGENUMBER = ' '
DATE_OF_CHANGE = '00000000'
OBJECTCLASS = 'MATERIAL'
OBJECTID = MATNR1
TABLEKEY = ' '
TABLENAME = ' '
TIME_OF_CHANGE = '000000'
USERNAME = ' '
LOCAL_TIME = ' '
TABLES
EDITPOS = CHGDOC
EXCEPTIONS
NO_POSITION_FOUND = 1
WRONG_ACCESS_TO_ARCHIVE = 2
TIME_ZONE_CONVERSION_ERROR = 3
OTHERS = 4.
In the above example you can get al the changes that are made to the material MATNR1 since it was first created.
Regards,
Ravi
‎2007 Jul 17 3:13 PM
CALL FUNCTION 'CHANGEDOCUMENT_READ'
EXPORTING
* ARCHIVE_HANDLE = 0
* CHANGENUMBER = ' '
* DATE_OF_CHANGE = '00000000'
OBJECTCLASS = 'MATERIAL'
OBJECTID = MATNR1
* TABLEKEY = ' '
* TABLENAME = ' '
* TIME_OF_CHANGE = '000000'
* USERNAME = ' '
* LOCAL_TIME = ' '
TABLES
EDITPOS = CHGDOC
EXCEPTIONS
NO_POSITION_FOUND = 1
WRONG_ACCESS_TO_ARCHIVE = 2
TIME_ZONE_CONVERSION_ERROR = 3
OTHERS = 4
‎2007 Jul 17 3:15 PM
In a loop I would like to use this FM to pass one of the fields of the Internal Table...How can copy the updated field value to one of my internal table...Thank you.
‎2007 Jul 17 2:44 PM
See the below program and i am getting material changes list using change document.
REPORT ZQA_MATERIAL_CHANGE_LIST no standard page heading line-size 132.
tables: bdcp, mara, makt.
data: i_cdhdr like cdhdr occurs 0 with header line,
i_cdshw like cdshw occurs 0 with header line.
SELECTION SCREEN ELEMENTS ------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK one
WITH FRAME TITLE text-001.
Select-options: s_datum for sy-datum obligatory.
select-options : s_time for sy-uzeit.
Start of change Seshu 02/19/2007
Reason - Added Material Number as Range Option
*select-options : p_matnr for mara-matnr.
select-options s_matnr for mara-matnr.
select-options: S_usernm for sy-uname.
SELECTION-SCREEN END OF BLOCK one.
SELECTION-SCREEN BEGIN OF BLOCK two
WITH FRAME TITLE text-002.
parameters: r_all radiobutton group one default 'X',
r_erps radiobutton group one,
r_select radiobutton group one.
SELECTION-SCREEN: BEGIN OF LINE, POSITION 5.
parameter p_fname like bdcp-fldname.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK two.
ranges r_objectid for cdhdr-objectid.
List of fields transmitted to ERPsy-Daisy
select-options so_fname for i_cdshw-fname no-display.
START OF SELECTION --------------------------------------------------*
START-OF-SELECTION.
if r_select is initial.
clear p_fname.
endif.
perform set_erpsy_daisy_fields.
perform get_data.
perform write_report.
SUBROUTINES ---------------------------------------------------------*
&----
*& Form get_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM get_data.
data: v_objectid like cdhdr-objectid.
*
move p_matnr to v_objectid.
*
loop at s_matnr.
move : s_matnr-low to r_objectid-low,
s_matnr-high to r_objectid-high,
s_matnr-option to r_objectid-option,
s_matnr-sign to r_objectid-sign.
append r_objectid.
endloop.
**if v_objectid is initial.
*select * from cdhdr into table i_cdhdr
where USERNAME in s_usernm
and OBJECTCLAS = 'MATERIAL'
and UDATE in s_datum
and utime in s_time.
*
*
*else.
select * from cdhdr into table i_cdhdr
where OBJECTID in r_objectid
and USERNAME in s_usernm
and OBJECTCLAS = 'MATERIAL'
and UDATE in s_datum
and utime in s_time.
*endif.
if sy-subrc ne 0.
message e000(zwave) with 'No Data Found for given Selection'.
endif.
ENDFORM. " get_data
&----
*& Form write_report
&----
text
----
--> p1 text
<-- p2 text
----
FORM write_report.
data: v_fname(60) type c,
v_changenr like i_cdhdr-changenr,
v_count type i value 0.
sort i_cdhdr by tcode changenr.
list materials created ---------------------------------------
if not s_datum-high is initial.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials created since',
25 s_datum-low ,39 'to',43 s_datum-high,
132 sy-vline.
format color off.
uline.
else.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials created since',
s_datum-low ,
132 sy-vline.
format color off.
ULINE.
endif.
loop at i_cdhdr where tcode = 'MM01' or
tcode = 'MM11'.
perform write_header_line using i_cdhdr.
endloop.
uline.
list materials deleted ---------------------------------------
if not s_datum-high is initial.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials flagged for deletion since',
43 s_datum-low ,55 'to',59 s_datum-high,
132 sy-vline.
format color off.
uline.
else.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials flagged for deletion since',
s_datum-low,
132 sy-vline.
format color off.
uline.
endif.
loop at i_cdhdr where tcode = 'MM06' or
tcode = 'MM16'.
perform write_header_line using i_cdhdr.
endloop.
uline.
display detail for material changes ---------------------------
skip.
if not s_datum-high is initial.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials changed since',
28 s_datum-low ,39 'to',43 s_datum-high,
132 sy-vline.
format color off.
else.
uline.
format color col_heading intensified on.
write: / sy-vline,
'Materials changed since',
s_datum-low ,
132 sy-vline.
format color off.
endif.
display material change transactions (immediate and change)
loop at i_cdhdr where tcode = 'MM02' or
tcode = 'MM12'.
retrieve change document line items
perform get_change_positions using i_cdhdr-changenr.
display each item matching field on parameter screen, only
ERPsy-Daisy materials, or all fields if both paramters blank
v_count = 0.
loop at i_cdshw.
if ( p_fname is initial or
i_cdshw-fname = p_fname ) and
i_cdshw-fname in so_fname.
write header line if this is the first line item from change
order to meet above criteria
add 1 to v_count.
if v_count = 1.
if i_cdhdr-changenr <> v_changenr.
if sy-index <> 1.
uline.
endif.
perform write_header_line using i_cdhdr.
endif.
endif.
v_changenr = i_cdhdr-changenr.
write change line
concatenate '(' i_cdshw-fname ')'
into v_fname.
concatenate i_cdshw-ftext v_fname
into v_fname separated by space.
write: / sy-vline.
if i_cdshw-chngind = 'U'. "update
write 12 'Change >'.
elseif i_cdshw-chngind = 'D' or
i_cdshw-chngind = 'I'.
write 12 'Deleted >'.
elseif i_cdshw-chngind = 'I'.
write 12 'Inserted >'.
endif.
write: v_fname,
132 sy-vline.
write: / sy-vline,
16 'Old Value:',
(40) i_cdshw-f_old,
132 sy-vline,
/ sy-vline,
16 'New Value:',
(40) i_cdshw-f_new,
132 sy-vline.
endif.
endloop.
endloop.
uline.
ENDFORM. " write_report
&----
*& Form write_header_line
&----
text
----
--> p1 text
<-- p2 text
----
FORM write_header_line using x_cdhdr like cdhdr.
data: v_date(10) type c,
v_time(8) type c.
get material description
select single maktx
from makt
into makt-maktx
where matnr = x_cdhdr-objectid.
format color col_heading intensified off.
write: / sy-vline,
x_cdhdr-objectid+8(10) no-zero,
(40) makt-maktx,
x_cdhdr-tcode,
x_cdhdr-username,
x_cdhdr-udate,
x_cdhdr-utime,
132 sy-vline.
format color off.
ENDFORM. " write_header_line
&----
*& Form get_change_positions
&----
text
----
--> p1 text
<-- p2 text
----
FORM get_change_positions using x_chgnbr.
CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
EXPORTING
ARCHIVE_HANDLE = 0
CHANGENUMBER = x_chgnbr
TABLEKEY = ' '
TABLENAME = ' '
IMPORTING
HEADER =
TABLES
EDITPOS = i_cdshw
EDITPOS_WITH_HEADER =
EXCEPTIONS
NO_POSITION_FOUND = 1
WRONG_ACCESS_TO_ARCHIVE = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " get_change_positions
&----
*& Form set_erpsy_daisy_fields
&----
text
----
--> p1 text
<-- p2 text
----
FORM set_erpsy_daisy_fields.
if r_erps = 'X'.
move: 'I' to so_fname-sign,
'EQ' to so_fname-option,
'BISMT' to so_fname-low.
append so_fname.
move 'MATNR' to so_fname-low.
append so_fname.
move 'MAKTX' to so_fname-low.
append so_fname.
MVKE fields
move 'VKORG' to so_fname-low.
append so_fname.
move 'VTWEG' to so_fname-low.
append so_fname.
move 'VMSTA' to so_fname-low.
append so_fname.
move 'VMSTA' to so_fname-low.
append so_fname.
move 'VRKME' to so_fname-low.
append so_fname.
move 'MSTAV' to so_fname-low.
append so_fname.
MARA fields
move 'MTART' to so_fname-low.
append so_fname.
move 'MATKL' to so_fname-low.
append so_fname.
move 'MEINS' to so_fname-low.
append so_fname.
move 'EAN11' to so_fname-low.
append so_fname.
MARC fields
move 'MTVFP' to so_fname-low.
append so_fname.
move 'MSTDV' to so_fname-low.
append so_fname.
move 'PLIFZ' to so_fname-low.
append so_fname.
move 'WERKS' to so_fname-low.
append so_fname.
move 'ZZDEPT' to so_fname-low.
append so_fname.
move 'ZZATP1' to so_fname-low.
append so_fname.
move 'ZZATP2' to so_fname-low.
append so_fname.
move 'ZZATP3' to so_fname-low.
append so_fname.
move 'ZZATP4' to so_fname-low.
append so_fname.
move 'ZZATP5' to so_fname-low.
append so_fname.
move 'ZZATP6' to so_fname-low.
append so_fname.
move 'ZZATP7' to so_fname-low.
append so_fname.
MARM fields
move 'UMREN' to so_fname-low.
append so_fname.
move 'UMRES' to so_fname-low.
append so_fname.
endif.
ENDFORM. " set_erpsy_daisy_fields
text elements :
P_FNAME Field name
R_ALL All Fields
R_ERPS Only ERPsy-Daisy Fields
R_SELECT Field:
S_DATUM Changes from Date
S_MATNR Material
S_TIME Changes from Time
S_USERNM User
________ ______________________________
Thanks
Seshu
‎2007 Jul 17 3:34 PM
loop at gt_cc.
call function 'CHANGEDOCUMENT_READ'
exporting
* ARCHIVE_HANDLE = 0
* CHANGENUMBER = ' '
* DATE_OF_CHANGE = '00000000'
objectclass = 'MATERIAL'
OBJECTID = gt_cc-matnr
TABLEKEY =
tables
editpos = CHGDOC
* EXCEPTIONS
* NO_POSITION_FOUND = 1
* WRONG_ACCESS_TO_ARCHIVE = 2
* TIME_ZONE_CONVERSION_ERROR = 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.
endif.
endloop.Getting a error "Field "TABLES" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement"
How to fix this error.
‎2020 Sep 29 2:36 PM
Your exporting parameter TABLEKEY is empty, therefore the system thinks, that you try to assign "tables" to TABLEKEY
TABLEKEY = tables
editpos = CHGDOCinstead of
TABLEKEY = <internal table>
tables
editpos = CHGDOC
OR* TABLEKEY =
tables
editpos = CHGDOC