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 get association of a Z table to a Stad. SAP's Change Document Object - SCDO

former_member202077
Participant
0 Kudos

Hello

I have a Z table, say, my_table with 4 Z fields in it, well.

My functional guy / business analyst said that the business want to track the changes of this table, hence he has asked me to get this make associate to XXXX (whichi is a Standard SAP Change doc. object, tx. code is SCDO) SCDO, pls. let me know how can i achieve this requirement.

XXXX, say an example of VDARL_CBP, i went to tx oc SCDO and choosen this VDARL_CBP and then clicked the General Info. button on menu, there am seeing some DDIC structures. Like the same way

I guess, its nothing to do with Checking the check box of 'Change Document' under 'Further Characterstics' tab 'in Data element level' of all 4 Z fields

Thank you

1 ACCEPTED SOLUTION

rosenberg_eitan
Active Contributor
0 Kudos

Hi,  Have you consider FUNCTION "CHANGEDOCUMENT_SINGLE_CASE" ?

I am using it to track changes in Z tables .

Can you add code where you update your Z file ?

Make sure your data elements "Indicator for writing change documents" is set.

Regards.

 

Code:

*----------------------------------------------------------------------*
FORM do_add_change_document
  USING
    objectclas TYPE cdhdr-objectclas
    tabname    TYPE cdpos-tabname
    change_ind TYPE cdhdr-change_ind
    objectid   TYPE cdhdr-objectid
    image_new
    image_old .

  DATA: st_cdhdr TYPE cdhdr .
  DATA: st_cdpos TYPE cdpos .

  st_cdhdr-objectclas = objectclas .
  st_cdpos-tabname    = tabname    .
  st_cdhdr-change_ind = change_ind .
  st_cdhdr-objectid   = objectid   .

  CALL FUNCTION 'CHANGEDOCUMENT_OPEN'
    EXPORTING
      objectclass             = st_cdhdr-objectclas
      objectid                = st_cdhdr-objectid
      planned_change_number   = ' '
      planned_or_real_changes = ' '
    EXCEPTIONS
      sequence_invalid        = 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.

  CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'
    EXPORTING
      change_indicator       = st_cdhdr-change_ind
      docu_delete            = 'X'
      tablename              = st_cdpos-tabname
      workarea_new           = image_new
      workarea_old           = image_old
    EXCEPTIONS
      nametab_error          = 1
      open_missing           = 2
      position_insert_failed = 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.

  st_cdhdr-username = sy-uname .
  st_cdhdr-udate    = sy-datum .
  st_cdhdr-utime    = sy-uzeit .
  st_cdhdr-tcode    = sy-tcode .

  CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'
    EXPORTING
      objectclass             = st_cdhdr-objectclas
      objectid                = st_cdhdr-objectid
      tcode                   = st_cdhdr-tcode
      username                = st_cdhdr-username
      date_of_change          = st_cdhdr-udate
      time_of_change          = st_cdhdr-utime
      object_change_indicator = st_cdhdr-change_ind
    IMPORTING
      changenumber            = st_cdhdr-changenr
    EXCEPTIONS
      header_insert_failed    = 1
      no_position_inserted    = 2
      object_invalid          = 3
      open_missing            = 4
      position_insert_failed  = 5
      OTHERS                  = 6.

  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 .                    "do_add_change_document
*----------------------------------------------------------------------*
FORM do_changedocu_key
  USING
    record  TYPE data
    tabname TYPE tabname
  CHANGING
    objectid TYPE cdobjectv .

* For the object ID.

  DATA: ev_tabkey TYPE cdpos_uid-tabkey .

  CALL FUNCTION 'CHANGEDOCU_KEY_ANY2CHAR'
    EXPORTING
      iv_struct_in     = record
      iv_tabname       = tabname
    IMPORTING
      ev_tabkey        = ev_tabkey
    EXCEPTIONS
      tabname_is_empty = 1
      nametab_error    = 2
      OTHERS           = 3.

  IF sy-subrc NE 0.
  ENDIF.

  objectid = ev_tabkey .

ENDFORM .                    "do_changedocu_key
*----------------------------------------------------------------------*
FORM do_dsp_change_document
  USING
    objectclas TYPE cdhdr-objectclas
    tabname    TYPE cdpos-tabname
    objectid   TYPE cdhdr-objectid .

* Display .

  DATA: editpos TYPE TABLE OF cdred .

  CALL FUNCTION 'CHANGEDOCUMENT_READ'
    EXPORTING
      objectclass                = objectclas
      tablename                  = tabname
      objectid                   = objectid
    TABLES
      editpos                    = editpos
    EXCEPTIONS
      no_position_found          = 1
      wrong_access_to_archive    = 2
      time_zone_conversion_error = 3
      OTHERS                     = 4.

  CHECK sy-subrc EQ 0.

  CALL FUNCTION 'CHANGEDOCUMENT_DISPLAY'
    EXPORTING
      i_applicationid       = sy-repid
      flg_autocondense      = abap_false
      i_screen_start_line   = 10
      i_screen_start_column = 10
      i_screen_end_line     = 20
      i_screen_end_column   = 150
    TABLES
      i_cdred               = editpos.

ENDFORM .                    "do_dsp_change_document

15 REPLIES 15

palash_mazumder
Participant
0 Kudos

I dont understand question fully but u can try to find any user exit after save the tcode scdo and take the return value through user exit and save this value in ztable.

former_member223322
Active Participant
0 Kudos

Yes, the same way as what you see in VDARL_CBP in the tcode SCDO. Refer the below blog on how to set a change log for the Z Table and how to use the same.

http://wiki.sdn.sap.com/wiki/display/ABAP/Maintaining+Change+Log+for+Database+Tables

~Srini

0 Kudos

Thank you, but this wiki is talking completely Z table & Z Change Doc Object/SCDO, hence its not relevent for me.

Pls. let me know Can i add a Z table/structure to the Standard SAP's Change Doc Object (you can see it SCDO) with a REPAIR transport, i mean, is it safe? any alternate? any suggestions?

0 Kudos

Any help pls.

Thank you

0 Kudos

An alternative would be to create a Z change document object, and include standard as well as Z table in it.

0 Kudos

You may have to create a Z change object and include the standard objects on it.

~Srini

rosenberg_eitan
Active Contributor
0 Kudos

Hi,  Have you consider FUNCTION "CHANGEDOCUMENT_SINGLE_CASE" ?

I am using it to track changes in Z tables .

Can you add code where you update your Z file ?

Make sure your data elements "Indicator for writing change documents" is set.

Regards.

 

Code:

*----------------------------------------------------------------------*
FORM do_add_change_document
  USING
    objectclas TYPE cdhdr-objectclas
    tabname    TYPE cdpos-tabname
    change_ind TYPE cdhdr-change_ind
    objectid   TYPE cdhdr-objectid
    image_new
    image_old .

  DATA: st_cdhdr TYPE cdhdr .
  DATA: st_cdpos TYPE cdpos .

  st_cdhdr-objectclas = objectclas .
  st_cdpos-tabname    = tabname    .
  st_cdhdr-change_ind = change_ind .
  st_cdhdr-objectid   = objectid   .

  CALL FUNCTION 'CHANGEDOCUMENT_OPEN'
    EXPORTING
      objectclass             = st_cdhdr-objectclas
      objectid                = st_cdhdr-objectid
      planned_change_number   = ' '
      planned_or_real_changes = ' '
    EXCEPTIONS
      sequence_invalid        = 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.

  CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'
    EXPORTING
      change_indicator       = st_cdhdr-change_ind
      docu_delete            = 'X'
      tablename              = st_cdpos-tabname
      workarea_new           = image_new
      workarea_old           = image_old
    EXCEPTIONS
      nametab_error          = 1
      open_missing           = 2
      position_insert_failed = 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.

  st_cdhdr-username = sy-uname .
  st_cdhdr-udate    = sy-datum .
  st_cdhdr-utime    = sy-uzeit .
  st_cdhdr-tcode    = sy-tcode .

  CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'
    EXPORTING
      objectclass             = st_cdhdr-objectclas
      objectid                = st_cdhdr-objectid
      tcode                   = st_cdhdr-tcode
      username                = st_cdhdr-username
      date_of_change          = st_cdhdr-udate
      time_of_change          = st_cdhdr-utime
      object_change_indicator = st_cdhdr-change_ind
    IMPORTING
      changenumber            = st_cdhdr-changenr
    EXCEPTIONS
      header_insert_failed    = 1
      no_position_inserted    = 2
      object_invalid          = 3
      open_missing            = 4
      position_insert_failed  = 5
      OTHERS                  = 6.

  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 .                    "do_add_change_document
*----------------------------------------------------------------------*
FORM do_changedocu_key
  USING
    record  TYPE data
    tabname TYPE tabname
  CHANGING
    objectid TYPE cdobjectv .

* For the object ID.

  DATA: ev_tabkey TYPE cdpos_uid-tabkey .

  CALL FUNCTION 'CHANGEDOCU_KEY_ANY2CHAR'
    EXPORTING
      iv_struct_in     = record
      iv_tabname       = tabname
    IMPORTING
      ev_tabkey        = ev_tabkey
    EXCEPTIONS
      tabname_is_empty = 1
      nametab_error    = 2
      OTHERS           = 3.

  IF sy-subrc NE 0.
  ENDIF.

  objectid = ev_tabkey .

ENDFORM .                    "do_changedocu_key
*----------------------------------------------------------------------*
FORM do_dsp_change_document
  USING
    objectclas TYPE cdhdr-objectclas
    tabname    TYPE cdpos-tabname
    objectid   TYPE cdhdr-objectid .

* Display .

  DATA: editpos TYPE TABLE OF cdred .

  CALL FUNCTION 'CHANGEDOCUMENT_READ'
    EXPORTING
      objectclass                = objectclas
      tablename                  = tabname
      objectid                   = objectid
    TABLES
      editpos                    = editpos
    EXCEPTIONS
      no_position_found          = 1
      wrong_access_to_archive    = 2
      time_zone_conversion_error = 3
      OTHERS                     = 4.

  CHECK sy-subrc EQ 0.

  CALL FUNCTION 'CHANGEDOCUMENT_DISPLAY'
    EXPORTING
      i_applicationid       = sy-repid
      flg_autocondense      = abap_false
      i_screen_start_line   = 10
      i_screen_start_column = 10
      i_screen_end_line     = 20
      i_screen_end_column   = 150
    TABLES
      i_cdred               = editpos.

ENDFORM .                    "do_dsp_change_document

0 Kudos

Thank you, very good suggestion.

By chance do you hv any idea about my original question, as below

"Can i add my Z table to a Standard SAP Change Document Object in SCDO transaction?"

Regards

0 Kudos

Any help pls.?

Thank you

0 Kudos

Hi ,   I have no experience with SCDO   Regards.

0 Kudos

Any help pls.?

"Can i add my Z table to a Standard SAP Change Document Object in SCDO transaction?"

Regards

0 Kudos

Its not a good idea to change the standard object as it involves regenerating the FM and you need to change the code wherever the FM is called. So the better option would be to create your own custom object and make the changes.

~Srini

0 Kudos

Ah, so just adding Z struture is not enough (job done)? do i need to,

1) Regenerate the FMs (by clicking the Generate Update Pgm.)? and

2) change the code, whereever they (FMs) are calling? if so, they are calling in again standard SAP classes, so, do i need to change the standard SAP class as well? Hmmm

Thank you

0 Kudos

Any help pls.?

Thank you    

0 Kudos

Any help pls.?

Thank you