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: 

Ztable Last modiefied by and Last modified on not updating

Former Member
0 Kudos

Hello Members,

I have a problem updating two fields "modified by" and "modififed on" of z table. I am using a event 18 through the view v_tvimf and SM30 to move sy-datum and sy-uname to the above said fields. It is updating the fields at one instance of the run but finally it is been over written by the buffer ( I suppose ) with old values of "created by" and "created at".

I would really appreciate if some one can help me out in this issue and thanks in advance.

Regards,

Sri

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Thanks Rob and Saquib

The code helped me but I have one little issue with it.

loop at total.

if <action> = 'U'.

move total to total_s.

the <action> value is empty at runtime and it is exiting the loop.

Can you please suggest me how to update this <action> flag coming from this total structure from the program so that it will satisfy the if condition and then updates the desired fields to the database.

Thanks in advance.

Sri.

11 REPLIES 11

Former Member
0 Kudos

Try adding something like the following code at event 01 (FILL_SY_FIELDS):

*----------------------------------------------------------------------*
*   INCLUDE LZZHB6_SAL_INC_RLFXX                                       *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FILL_SY_FIELDS
*&---------------------------------------------------------------------*
*       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 zzhb6_sal_inc_rl.
  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

Former Member
0 Kudos

Hi Rob,

Thanks for the fast reply.

I had couple of questions Where do I code this (Did you mean SAP EVENT 01 which is Before saving Entries to the database).

My other question was for the structure zzhb6_sal_inc_rl. Is it a standard SAP structure or your program's table structure

Please reply.

Thanks once again

Sri.

0 Kudos

You have to code

INCLUDE LZZHB6_SAL_INC_RLFXX

and yes its his program table structure , We also did almost same kind of stuff in order to track users and there hits on per transactions .

Hope this`ll help you .

Thanks

Saquib

0 Kudos

Yes - my structure. This is basically boiler plate code that you should be able to use by only modifying the structure. We hjave this plugged into event 01 in a number of table maintenance dialogues and it seems to work pretty well.

Sorry - I copied the form name rather than the event name. I'm not sure if it would work in a different event.

Rob

Message was edited by: Rob Burbank

Former Member
0 Kudos

Thanks Rob and Saquib

The code helped me but I have one little issue with it.

loop at total.

if <action> = 'U'.

move total to total_s.

the <action> value is empty at runtime and it is exiting the loop.

Can you please suggest me how to update this <action> flag coming from this total structure from the program so that it will satisfy the if condition and then updates the desired fields to the database.

Thanks in advance.

Sri.

0 Kudos

Does this happen when you press the 'save' button?

Rob

Former Member
0 Kudos

Thanks Rob and Saquib

Thanks for all your time. I used the code that you sent me in Event 18 and it worked fine.

Thanks again for the quick responses.

0 Kudos

Glad to help.

Rob

Former Member
0 Kudos

Hi Rob,

I have a another issue with the code.

Data: f_index like sy-tabix.

data begin of total_s.

include structure zzhb6_sal_inc_rl.

data action.

data mark.

data end of total_s.

I have to dynamically determine the table name for the include structure above ( in place of zzhb6_sal_inc_rl) so that the code can be used for lot of ztables instead of one Ztable which we are now hardcoding the table name in the include structure. At run time I am getting the table name in x_header-viewname field before it hits my event. Is there a way we can capture this and move it as a structure to the Include structure in the above total_s.

Thanks for your help.

Sri.

0 Kudos

Not that I know of. A table maintenance dialogue is for a particular table. But I've used the same event code (except for table name) for a number of tables.

Rob

Former Member
0 Kudos

Hi Rob

I was able to figure out the Dynamic table declaration. and here is my final code maybe i thought I will share it with you and among other members also.

FORM SAVE.

field-symbols: <f1> type any,

<f2> type any.

data: flag.

data: l_len type i.

loop at total.

assign total to <f1> casting type (x_header-viewname).

describe field <f1> output-length l_len.

if total+l_len(1) = 'U'.

flag = total+l_len(1).

assign component 'LAEDA' of structure <f1> to <f2>.

<f2> = sy-datum.

assign component 'AENAM' of structure <f1> to <f2>.

<f2> = sy-uname.

total = <f1>.

total+l_len(1) = flag.

modify total.

elseif total+l_len(1) = 'N'.

flag = total+l_len(1).

assign component 'LAEDA' of structure <f1> to <f2>.

<f2> = sy-datum.

assign component 'AENAM' of structure <f1> to <f2>.

<f2> = sy-uname.

assign component 'ERSDA' of structure <f1> to <f2>.

<f2> = sy-datum.

assign component 'ERNAM' of structure <f1> to <f2>.

<f2> = sy-uname.

total = <f1>.

total+l_len(1) = flag.

modify total.

endif.

endloop.

loop at extract.

assign extract to <f1> casting type (x_header-viewname).

describe field <f1> output-length l_len.

if extract+l_len(1) = 'U'.

flag = extract+l_len(1).

assign component 'LAEDA' of structure <f1> to <f2>.

<f2> = sy-datum.

assign component 'AENAM' of structure <f1> to <f2>.

<f2> = sy-uname.

extract = <f1>.

extract+l_len(1) = flag.

modify extract.

elseif extract+l_len(1) = 'N'.

flag = extract+l_len(1).

assign component 'LAEDA' of structure <f1> to <f2>.

<f2> = sy-datum.

assign component 'AENAM' of structure <f1> to <f2>.

<f2> = sy-uname.

assign component 'ERSDA' of structure <f1> to <f2>.

<f2> = sy-datum.

assign component 'ERNAM' of structure <f1> to <f2>.

<f2> = sy-uname.

extract = <f1>.

extract+l_len(1) = flag.

modify extract.

endif.

endloop.

endform.

Thanks again Rob.

Sri.