Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Change doc Function Module?

vsubbakrishna
Participant
0 Kudos

Fn mod:ZSUBTESTCHG_WRITE_DOCUMENT

Import parameters Value

OBJECTID ZSUBTESTCHG

TCODE SE37

UTIME 00:00:00

UDATE 09.03.2009

USERNAME 'TESTUSER'

PLANNED_CHANGE_NUMBER

OBJECT_CHANGE_INDICATOR I

PLANNED_OR_REAL_CHANGES R

NO_CHANGE_POINTERS

UPD_ICDTXT_ZSUBTESTCHG I

N_ZSUBTEST 2 TEST

O_ZSUBTEST 2 TEST

UPD_ZSUBTEST I

Tables Value

ICDTXT_ZSUBTESTCHG 0 Entries

I have a ztable 'ZSUBTEST' with 2 fields DEPTID and DEPNAME and ticked "change document" for data element.

I have created the above change doc write fn module. I am trying to insert a new reocrd into table.

How to use ZSUBTESTCHG_WRITE_DOCUMENT so that even if i try to change an existing record in ztable the old and new values for a particulat ztable will be filled in CDPOS Table.

Would appreciate if you can suggest me how to use in1) Update and 2) Insert scenarios.

Thanks,

Subba

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi check this,

      • Types Declaration***

types: BEGIN OF X_audit,

-


Field of ZAUDIT TABLE OR a custom created table------

END OF X_audit.

      • Data Declaration***

Data: w_newvalues type X_audit,

w_oldvalues type X_audit.

DATA: BEGIN OF t_cdtxt OCCURS 0.

INCLUDE STRUCTURE cdtxt.

DATA: END OF t_cdtxt.

DATA: l_tcode type cdhdr-tcode ,

l_time type cdhdr-utime,

l_usnam type cdhdr-username,

l_date type cdhdr-udate.

**Constants****

CONSTANTS : l_objectid TYPE cdhdr-objectid VALUE 'ZAUDIT_CD'.

Initialization.

Clear: l_tcode,l_time, l_usnam, l_date.

Clear: w_newvalues, w_oldvalues.

**Start-Of-Selection**

Start-of-selection.

*Populating w_oldvalues workarea with old values from the table

Select single * from zaudit_t

Into w_oldvalues

Where belnr eq belnr_1

And gjahr eq gjahr_1

And bukrs eq bukrs_1. u201C where, belnr_1, gjahr_1, bukrs_1 are the fields on selection screen.

  • here we are populating w_newvalues workarea with new values

-


W_newvalues-f1 = w_oldvalues-f1

-


f2 = u2018XXXXXXXu2019 -


f3 = u2018YYYYYYYu2019

-


f4 = u2018ZZZZZZZu2019

l_tcode = sy-tcode.

l_time = sy-uzeit.

l_usnam = sy-uname.

l_date = sy-datum.

      • modify the table with new values***

MODIFY zaudit_t FROM w_submit.

IF sy-subrc EQ 0.

MESSAGE 'Document Updated' TYPE 'S'.

call function 'ZAUDIT_CD1_WRITE_DOCUMENT'

exporting

objectid = l_objectid

tcode = l_tcode

utime = l_time

udate = l_date

username = l_usnam

  • PLANNED_CHANGE_NUMBER = ' '

object_change_indicator = 'U' u201CU-update, I-insert, D-delete

  • PLANNED_OR_REAL_CHANGES = ' '

  • NO_CHANGE_POINTERS = ' '

upd_icdtxt_zaudit_cd = 'U'

n_zaudit_t = w_newvalues u201Cpass the work area containing new values

o_zaudit_t = w_oldvalues u201Cpass the work area containing old values

upd_zaudit_t = 'U' u201C this parameter gives the values in the columns(new value, old value and changed field name) of table CDPOS.

tables

icdtxt_zaudit_cd = t_cdtxt

ELSE.

MESSAGE 'Document Not Updated' TYPE 'S'.

ENDIF. u201CIF sy-subrc EQ 0.

10 REPLIES 10

Former Member
0 Kudos

hi check this,

      • Types Declaration***

types: BEGIN OF X_audit,

-


Field of ZAUDIT TABLE OR a custom created table------

END OF X_audit.

      • Data Declaration***

Data: w_newvalues type X_audit,

w_oldvalues type X_audit.

DATA: BEGIN OF t_cdtxt OCCURS 0.

INCLUDE STRUCTURE cdtxt.

DATA: END OF t_cdtxt.

DATA: l_tcode type cdhdr-tcode ,

l_time type cdhdr-utime,

l_usnam type cdhdr-username,

l_date type cdhdr-udate.

**Constants****

CONSTANTS : l_objectid TYPE cdhdr-objectid VALUE 'ZAUDIT_CD'.

Initialization.

Clear: l_tcode,l_time, l_usnam, l_date.

Clear: w_newvalues, w_oldvalues.

**Start-Of-Selection**

Start-of-selection.

*Populating w_oldvalues workarea with old values from the table

Select single * from zaudit_t

Into w_oldvalues

Where belnr eq belnr_1

And gjahr eq gjahr_1

And bukrs eq bukrs_1. u201C where, belnr_1, gjahr_1, bukrs_1 are the fields on selection screen.

  • here we are populating w_newvalues workarea with new values

-


W_newvalues-f1 = w_oldvalues-f1

-


f2 = u2018XXXXXXXu2019 -


f3 = u2018YYYYYYYu2019

-


f4 = u2018ZZZZZZZu2019

l_tcode = sy-tcode.

l_time = sy-uzeit.

l_usnam = sy-uname.

l_date = sy-datum.

      • modify the table with new values***

MODIFY zaudit_t FROM w_submit.

IF sy-subrc EQ 0.

MESSAGE 'Document Updated' TYPE 'S'.

call function 'ZAUDIT_CD1_WRITE_DOCUMENT'

exporting

objectid = l_objectid

tcode = l_tcode

utime = l_time

udate = l_date

username = l_usnam

  • PLANNED_CHANGE_NUMBER = ' '

object_change_indicator = 'U' u201CU-update, I-insert, D-delete

  • PLANNED_OR_REAL_CHANGES = ' '

  • NO_CHANGE_POINTERS = ' '

upd_icdtxt_zaudit_cd = 'U'

n_zaudit_t = w_newvalues u201Cpass the work area containing new values

o_zaudit_t = w_oldvalues u201Cpass the work area containing old values

upd_zaudit_t = 'U' u201C this parameter gives the values in the columns(new value, old value and changed field name) of table CDPOS.

tables

icdtxt_zaudit_cd = t_cdtxt

ELSE.

MESSAGE 'Document Not Updated' TYPE 'S'.

ENDIF. u201CIF sy-subrc EQ 0.

0 Kudos

Hi,

I am able to generate CDHDR and CDPOS entries.I am only changing DEPNAME entries.

But 1) I am not getting FNAME as DEPNAME and old values and new values in CDPOS?

2)Also when I used 'U' for update it was not generating change doc numbers?

.

OBJECTCLAS ZSUBTESTCHG

OBJECTID ZSUBTESTCHG

CHANGENR 15757

TABNAME ZSUBTEST

TABKEY 1

FNAME KEY

CHNGIND I

TEXT CASE 1

UNIT OLD

UNIT NEW

CUKY OLD

CUKY NEW

VALUE NEW

VALUE OLD

REPORT ZSUB_CHGDOC.

types: BEGIN OF X_audit.

INCLUDE STRUCTURE ZSUBTEST.

TYPES END OF X_audit.

PARAMETERS:P_DEPTID LIKE ZSUBTEST-DEPTID.

*Data Declaration**

Data: w_newvalues type X_audit,

w_oldvalues type X_audit.

DATA: BEGIN OF t_cdtxt OCCURS 0.

INCLUDE STRUCTURE cdtxt.

DATA: END OF t_cdtxt.

DATA: l_tcode type cdhdr-tcode ,

l_time type cdhdr-utime,

l_usnam type cdhdr-username,

l_date type cdhdr-udate.

**Constants****

CONSTANTS : l_objectid TYPE cdhdr-objectid VALUE 'ZSUBTESTCHG'.

**Start-Of-Selection**

Start-of-selection.

Clear: l_tcode,l_time, l_usnam, l_date.

Clear: w_newvalues, w_oldvalues.

Select single * from ZSUBTEST

Into w_oldvalues

Where DEPTID eq P_DEPTID.

W_newvalues-DEPTID = '1'.

W_newvalues-DEPNAME = 'SUBBA NEW'.

l_tcode = sy-tcode.

l_time = sy-uzeit.

l_usnam = sy-uname.

l_date = sy-datum.

modify the table with new values**

MODIFY ZSUBTEST FROM W_newvalues.

IF sy-subrc EQ 0.

MESSAGE 'Document Updated' TYPE 'S'.

CALL FUNCTION 'ZSUBTESTCHG_WRITE_DOCUMENT'

EXPORTING

OBJECTID = l_objectid

TCODE = l_tcode

UTIME = l_time

UDATE = l_date

USERNAME = l_usnam

PLANNED_CHANGE_NUMBER = ' '

OBJECT_CHANGE_INDICATOR = 'I'

PLANNED_OR_REAL_CHANGES = ' '

NO_CHANGE_POINTERS = ' '

UPD_ICDTXT_ZSUBTESTCHG = 'I'

N_ZSUBTEST = w_newvalues

O_ZSUBTEST = w_oldvalues

UPD_ZSUBTEST = 'I'

TABLES

ICDTXT_ZSUBTESTCHG = t_cdtxt

.

ELSE.

MESSAGE 'Document Not Updated' TYPE 'S'.

ENDIF.

Thanks,

Subba

0 Kudos

Hi Subba,

i understood that you have not ticked one check box while genetating a function module.

while creating you need to tick doc. for individual at delete check box. then only you'll get the fname.

0 Kudos

link: [http://www.scribd.com/doc/12627676/Logging-Using-Change-Document]

check this document and follow the steps properly how i created.

Edited by: kat k on Mar 9, 2009 8:33 AM

Edited by: kat k on Mar 9, 2009 8:39 AM

0 Kudos

Thanks.Problem solved. Points assigned.

U r Right. There was some inconsistency in FM Generation.

Thanks again.Nice doc though.

Regards,

Subba

0 Kudos

One more question.

There was one more type in this change documents...if you refer EINKBELEG we can see

Dictionary structures

UEKEK UEKES UEKET UEKKN

UEKPA UEKPO UKONVC

what are these structures.Is it possible to use these kind of structures in our example?

Thanks,

Subba

0 Kudos

i don't understand where is it. could you tell me how do i check or post sample code.

0 Kudos

I checked the FM EINKBELEG_WRITE_DOCUMENT...In which it refered to CHANGEDOCUMENT_MULTIPLE_CASE. May be it is used in multiple line items scenario where we could keep track of change at item level.

Thanks,

Subba

0 Kudos

Hi subba,

normaly now we have done the change document settings for only one table. in actual scenario while creating the function module they include multiple table like you c in FM we can find these tables

EKKO

EKPA

EKPO

KONV

so where ever here multiple case is generated and for only one table single case will be generated by SCDO

Former Member
0 Kudos

Hi,

upd_zaudit_t = 'U'. by setting this parameter u'll get the changed values.

their is not update and insert scenarios exist in change document.

if you update a record, set this upd_zaudit_t parameter to 'U'. if your are inserting a record Set the value to 'I'.

so, from this you can understand that what ever the value we passs in this parameter the status will we updated as you by the value you pass to the parameter.