Application Development and Automation 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: 
Read only

events for changed entry in data dictionary

Former Member
0 Likes
3,791

Hi ,

I have a requirement as mentioned below:

my table has four fields : 1. vkorg 2. validity_period 3. modification_date and 4. modification_time.

I have to capture the modification date and modification time if a user changes an entry (or entries) in the table and update the date and time fields in the table. I have done it by creating an event "creating a new entry"which is triggered when a new entry is added to the table. But if an existing entry is modifies then the entry is not triggered. when I use " before saving the data " event then only the last record of the table moves to the "Routine" of the event. So I am not able to capture the date and time when an entry (or entries ) is modified. Can anyone suggest me what I should do?

Regards

Amit kumar

Edited by: amitku1201 on Jan 15, 2010 3:05 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,509

This question has been asked many times before. Please see:

*&---------------------------------------------------------------------*
*&      Form  FILL_SY_FIELDS                                    FISKROB
*&---------------------------------------------------------------------*
*       Add the creation date and userid if the line is being created.
*       Add the change date and userid if the line is being changed.
*----------------------------------------------------------------------*
form fill_sy_fields.

  data: f_index like sy-tabix. "Index to note the lines found

  data begin of total_s.
          include structure zzv_my_tab.
  data action.
  data mark.
  data end of total_s.

  data extract_s like total_s.

  loop at total.
    if <action> = 'U'.
      move total to total_s.
      read table extract with key total.
      if sy-subrc eq 0.
        f_index = sy-tabix.
        extract_s = extract.
      else.
        clear f_index.
      endif.
*       (make desired changes to the line TOTAL)
      total_s-zzfchdate = sy-datum.
      total_s-zzfchusr  = sy-uname.
      move total_s to total.
      modify total.
      check f_index gt 0.
      extract = total.
      modify extract index f_index.
    elseif <action> = 'N'.
      move total to total_s.
      read table extract with key total.
      if sy-subrc eq 0.
        f_index = sy-tabix.
        extract_s = extract.
      else.
        clear f_index.
      endif.
*       (make desired changes to the line TOTAL)
      total_s-zzfcredate = sy-datum.
      total_s-zzfcreusr  = sy-uname.
      move total_s to total.
      modify total.
      check f_index gt 0.
      extract = total.
      modify extract index f_index.
    elseif total is initial.
      move total to total_s.
      read table extract with key total.
      if sy-subrc eq 0.
        f_index = sy-tabix.
        extract_s = extract.
      else.
        clear f_index.
      endif.
*       (make desired changes to the line TOTAL)
      delete total.
      check f_index gt 0.
      delete extract index f_index.
    endif.
  endloop.
  sy-subrc = 0.

endform.                    " FILL_SY_FIELDS

Rob

The link I posted earlier may not work now. The above code does.

Edited by: Rob Burbank on Jan 15, 2010 12:20 PM

Hi ,

I have a requirement as mentioned below:

my table has four fields : 1. vkorg 2. validity_period 3. modification_date and 4. modification_time.

I have to capture the modification date and modification time if a user changes an entry (or entries) in the table and update the date and time fields in the table. I have done it by creating an event "creating a new entry"which is triggered when a new entry is added to the table. But if an existing entry is modifies then the entry is not triggered. when I use " before saving the data " event then only the last record of the table moves to the "Routine" of the event. So I am not able to capture the date and time when an entry (or entries ) is modified. Can anyone suggest me what I should do?

Regards

Amit kumar

Edited by: amitku1201 on Jan 15, 2010 3:05 PM

13 REPLIES 13
Read only

naimesh_patel
Active Contributor
0 Likes
2,509

In the event 01 - "Before Saving data to database", you can access the TOTAL table, which contains all the current line items. You can select the data from the Z table into another table and compare it.

You may like to check this blog post - http://help-abap.blogspot.com/2008/09/capture-changed-content-after-fm.html

Regards,

Naimesh Patel

Read only

0 Likes
2,509

Hi Naimesh,

I have to maintain the data using SM30. can you please explain in some more detail how it can be done? thanks in advance.

Regards

Amit kumar

Read only

0 Likes
2,509

I have done it by creating an event "creating a new entry"

I have to maintain the data using SM30. can you please explain in some more detail how it can be done

Do it the same way you did for "creating a new entry", in the suggested blog only the event changes and the data is compared by whole.

Read only

0 Likes
2,509

Hi Keshav,

If I use " creating new entry" event then it will be triggered only when I create a new entry in the table and not for changing the entry. in that case I would not be able to modify the date and time field.

Read only

0 Likes
2,509

Please read the blog, the changed data is compared in event 01.

The existing entries from the db are picked and then compared with the current entries in event 01.

Here the values of the control including changed data will be held in TOTAL.

You can then update your values to the records that are changed ( Records changed are identified while comparing with the existing data )

Read only

Former Member
0 Likes
2,509

Hello Amit,

You will have to create two table events in table maintenance generation as shown below...

  • 05 FETCH_VALUE_NEW

  • 21 FETCH_VALUE_CHANGE

The first event-05 triggers when you create new entry where you can update created by/created date etc.,

and in the second event-21 you can update Changed by/Changed date etc.,

Let me know if you need more clarification.

Thanks

Alis

Read only

Former Member
0 Likes
2,509

Hi Keshav,

I am getting all the data in TOTAL table. But I didnt understand how to update the data base with data. I dont think we should use update or insert statement for updating the database.

Read only

Former Member
0 Likes
2,510

This question has been asked many times before. Please see:

*&---------------------------------------------------------------------*
*&      Form  FILL_SY_FIELDS                                    FISKROB
*&---------------------------------------------------------------------*
*       Add the creation date and userid if the line is being created.
*       Add the change date and userid if the line is being changed.
*----------------------------------------------------------------------*
form fill_sy_fields.

  data: f_index like sy-tabix. "Index to note the lines found

  data begin of total_s.
          include structure zzv_my_tab.
  data action.
  data mark.
  data end of total_s.

  data extract_s like total_s.

  loop at total.
    if <action> = 'U'.
      move total to total_s.
      read table extract with key total.
      if sy-subrc eq 0.
        f_index = sy-tabix.
        extract_s = extract.
      else.
        clear f_index.
      endif.
*       (make desired changes to the line TOTAL)
      total_s-zzfchdate = sy-datum.
      total_s-zzfchusr  = sy-uname.
      move total_s to total.
      modify total.
      check f_index gt 0.
      extract = total.
      modify extract index f_index.
    elseif <action> = 'N'.
      move total to total_s.
      read table extract with key total.
      if sy-subrc eq 0.
        f_index = sy-tabix.
        extract_s = extract.
      else.
        clear f_index.
      endif.
*       (make desired changes to the line TOTAL)
      total_s-zzfcredate = sy-datum.
      total_s-zzfcreusr  = sy-uname.
      move total_s to total.
      modify total.
      check f_index gt 0.
      extract = total.
      modify extract index f_index.
    elseif total is initial.
      move total to total_s.
      read table extract with key total.
      if sy-subrc eq 0.
        f_index = sy-tabix.
        extract_s = extract.
      else.
        clear f_index.
      endif.
*       (make desired changes to the line TOTAL)
      delete total.
      check f_index gt 0.
      delete extract index f_index.
    endif.
  endloop.
  sy-subrc = 0.

endform.                    " FILL_SY_FIELDS

Rob

The link I posted earlier may not work now. The above code does.

Edited by: Rob Burbank on Jan 15, 2010 12:20 PM

Read only

0 Likes
2,509

thanks rob ..its working

Read only

0 Likes
2,509

For completeness sake, you have to add FILL_SY_FIELDS as a FORM routine for event 01 in the table maintenance generator.

Rob

Read only

0 Likes
2,509

Hi Rob,

I have a doubt here, TOTAL line is a single component and not having any table components in it.

How can you MOVE TOTAL to TOTAL_S. In unicode programming it will give us dump right.

Please clarify.

Regards,

Kusuma K.

Read only

0 Likes
2,509

Hi ,

I have coded it as mentioned. I didnt get any dump. the UNICODE check was also active. I dont think there should be any issue.

Read only

0 Likes
2,509

HI kusuma,

You are absolutely correct. The statement MOVE TOTAL to TOTAL_S results in a dump.

For the solution refer to the answer in the below thread by Vijay Babu Dudla . It works as expected.