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 the entries are made in CDHDR and CDPOS tables?

Former Member
0 Kudos

Hi,

I have a dbtable ZTEST_DB which has one field (TESTFIELD). Its data element consists of change document enabled and I created a change document namely ZMYCHDOC in SCDO transaction and included this table and generated the function module ZMYCHDOC_WRITE_DOCUMENT .

I have written one report for adding record to dbtable.

REPORT ztest_report.

*TABLES: ztest_db.

DATA: itab TYPE TABLE OF ztest_db,

wa TYPE ztest_db.

PARAMETERS: test TYPE ztest_db-testfield.

wa-testfield = test.

INSERT into ztest_db values wa.

IF sy-subrc EQ 0.

WRITE: 'success'.

ELSE.

WRITE: 'failed'.

ENDIF.

PERFORM CD_CALL_ZMYCHDOC.

INCLUDE: fzmychdoccdt.

INCLUDE: fzmychdoccdc.

After adding the record I could not find any new entries in CDHDR and CDPOS tables. I dint understand the concept. How the entries are made in those tables when database changes occur?

I have searched many threads. But could not find how the entries are made in those tables. Should I need to use that function module in my code to write the entries?

Regards,

SAP Lover.

7 REPLIES 7

former_member181995
Active Contributor
0 Kudos

Dear Lover,

se11>technical settings>log data changes?should be enable.

Than The existing logs can be displayed with Transaction Table history (SCU3).

Amit.

0 Kudos

I have already enabled log changes in dbtable technical settings.

Regards,

SAP Lover

0 Kudos

> I have already enabled log changes in dbtable technical settings.

You can switch this off again, as it would create entries in table DBTABLOG. Since you have created your own change document, you don't need table logging.

Make sure you call ZMYCHDOC_WRITE_DOCUMENT with the old and new data (before and after changes).

Thomas

0 Kudos

Thomas,

First of all thanks to you.

It is working for insertion of new record but it is not working when i update the old record. It is creating 2 entries in CDPOS table with same change number (one for deleting the old record and another one for inserting new record).

see the code.

REPORT ztest_kalai.

INCLUDE: fzmychdoccdt.

*TABLES: ztest_db.

DATA: itab TYPE TABLE OF ztest_db,

wa TYPE ztest_db.

DATA: it_cdtxt TYPE TABLE OF cdtxt,

    • yztest_db TYPE TABLE OF yztest_db, "old*

    • xztest_db TYPE TABLE OF yztest_db, "new*

wa_yz TYPE yztest_db.

PARAMETERS: test TYPE ztest_db-testfield.

CLEAR wa_yz.

wa_yz-testfield = test.

wa_yz-kz = 'U'.

APPEND wa_yz TO xztest_db. "new table

wa_yz-testfield = 'XZB'.

wa_yz-kz = 'U'.

APPEND wa_yz TO yztest_db. "old table

upd_ztest_db = 'U'. " chnge indicator = U

objectid = 'ZMYCHDOC'.

UPDATE ztest_db SET testfield = test WHERE testfield = 'XZB'.

IF sy-subrc EQ 0.

WRITE: 'success'.

ELSE.

WRITE: 'failed'.

ENDIF.

PERFORM cd_call_zmychdoc. "call to func module

INCLUDE: fzmychdoccdc.

****************************************************

FORM CD_CALL_ZMYCHDOC.

IF UPD_ZTEST_DB NE SPACE .

CALL FUNCTION 'ZMYCHDOC_WRITE_DOCUMENT' " IN UPDATE TASK

EXPORTING

OBJECTID = OBJECTID

TCODE = 'ZTR'

UTIME = sy-uzeit

UDATE = sy-datum

USERNAME = sy-uname

    • PLANNED_CHANGE_NUMBER = PLANNED_CHANGE_NUMBER*

    • OBJECT_CHANGE_INDICATOR = UPD_ZTEST_DB*

    • PLANNED_OR_REAL_CHANGES = CDOC_PLANNED_OR_REAL*

    • NO_CHANGE_POINTERS = CDOC_NO_CHANGE_POINTERS*

    • updateflag of ZTEST_DB*

UPD_ZTEST_DB = UPD_ZTEST_DB

    • UPD_ICDTXT_ZMYCHDOC = UPD_ICDTXT_ZMYCHDOC*

TABLES

ICDTXT_ZMYCHDOC

= ICDTXT_ZMYCHDOC

XZTEST_DB

= XZTEST_DB

YZTEST_DB

= YZTEST_DB

.

ENDIF.

CLEAR PLANNED_CHANGE_NUMBER.

ENDFORM.

How the old value and new values come in CDPOS table if I update a record?

Regards,

SAP Lover

0 Kudos

Hi Lover, I couldn't even get to write the value into CDHDR or CDPOS. Could you identify what's wrong between your initial code (where you fail to create the entries) and your latest code (successfully created the entries). Many thanks.

0 Kudos

Hi Nivla,

You have to insert records in internal tables, which is passed as an parameters for the Change Document function module.

Regards,

SAP Lover

Former Member
0 Kudos

You need to call function module ZMYCHDOC_WRITE_DOCUMENT before INSERT command. Only then it enters data in CDHDR and CDPOS.