0

I want to capture changes for all possible SAP tables.

I figured out that CDHDR and CDPOS tables capture change documents but it's not clear for which all tables it does that.

I have multiple questions to ask:

  1. Get list of all tables for which CDHDR and CDPOS tables capture change documents.
  2. As CDPOS table only contains changed field and I need to map it with Primary Key of the table. How can I map changed record with primary key of a table?
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Vishal Garg
  • 59
  • 1
  • 3

2 Answers2

3

To purely answer your question, I certainly can tell you to look into the t-code SCDO to get the clue on what you need, but I would choose to challenge your reasoning approach. So, you have a requirement to capture changes for all possible SAP tables. For what purpose? There are thousands of SAP tables being tracked by CDHDR and CDPOS, and most tables there do not bring immediate business values to you. Whenever a table column has a data element like BELNR_D and GJAHR, it could appear in CDHDR, because such element is marked as "Change Document" flag (t-code SE11): enter image description here

And SAP's explanation to the flag is:

The flag for change documents specifies whether changes to fields in database tables defined with reference to this data element are logged when change document objects are involved.

Therefore, with thousands of tables being tracked, it would not be a good idea to solve the problem purely from technical aspect, and we have not even started looking into the performance problem with CDHDR and CDPOS yet.

If your requirement is part of a data warehousing project, then without the hassle of dealing with CDPOS and CDHDR, you can analyze the incremental insertion, deletion and update through the transparent tables or standard extractors. If you can use DB trigger, then SLT could also be an option to get the changed records on the tables you are interested in at almost real-time (5-second delay by default setting).

To summarize, to get to what you need, you can navigate to SAP Menu - Tools - ABAP Workbench - Other Tools - Change Document, or simply the t-code SCDO. However, my comment above on the business requirement is what I really intend to express.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
AecorSoft
  • 414
  • 4
  • 10
  • Thanks for your response. It’s my use case to capture changes for analytical purpose, i need to automate this process so i am using JDBC. I have got few more doubts from your answer: 1. As you said there are flags like BELNR_D and GJAHR in tables that appear in CDHDR, how can i get list of all such flags? I don’t see these flags as part of columns for a table. 2. Do i need to manually enable Change Document flag for tables or it’s is enabled by default? 3. Do you have any suggestions for mapping of records with primary key, that’s my 2nd query in original question? – Vishal Garg Aug 29 '19 at 10:25
  • When you use SE11 or SE12 to open table schema (e.g. BKPF), please look under the "Data element" column, and you will find that the elements like BELNR_D. You should not enable it or disable it manually. It's a system setting which tells you that the table could have changed records in CDHDR and CDPOS. If we still use Accounting Doc as example, from experience you would know its change document is BELE* like BELEG (which can be confirmed in SCDO). Then, in CDHDR, you use "BELEG" in OBJECTCLAS, to get the list of OBJECTID, with which you can filter with CDPOS to get the details of changes. – AecorSoft Aug 29 '19 at 13:28
  • I still think you should look into the source table level incremental load. For example, if you deal with accounting document, the delta is already well tracked by extractor 0FI_GL_4 which is easier to use than BKPF/BSEG extract. For sales order, table is easier to access than logistics extractors. I wrote some topics on subject in the blog area on our company website. – AecorSoft Aug 29 '19 at 13:31
1

Why not running SELECT DISTINCT tabname FROM cdpos to get the actual list of all tables? I guess it should be sufficient because your SAP system has been live for a while. If you can't do it yourself, ask someone, once for all.

In the table CDPOS, you get the ID of the object changed from the column TABKEY. If the primary key is made of several columns, TABKEY is the concatenation of the character values, with the alignment based on each column size. I'm not sure, but I guess that the primary key columns (of tables referred by TABNAME of CDPOS) always have character types.

The columns of the primary key of one table can be extracted from the ABAP Dictionary with this SQL query: SELECT fieldname, leng FROM dd03l WHERE tabname = 'one_table' AND fieldname LIKE '.%' AND keyflag = 'X' ORDER BY position (column names starting with a dot are for internal stuff).

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • Sandra, your edit to my reply was appreciated! Just a small comment on the primary key data type: I did a search in DD03L table and found the primary key types can include non-character types like hexadecimal (x), string (g), floating point (F), as well as those common types like N, D, T which are actually characters in the underlying database. – AecorSoft Aug 29 '19 at 20:26
  • @AecorSoft I meant [columns of tables referred by TABNAME of CDPOS] "always have character types". Answer updated. – Sandra Rossi Aug 30 '19 at 06:04