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 detect modifications in an ABAP Object?

jsancho
Participant
0 Kudos

Hi all,

I was wondering if there's a simple way of detecting modifications in an ABAP Object.

Imagine an ABAP entity object which holds several attributes and you need to know if this object has been modified. Instead of having to check attribute by attribute to compare it's previous value with the new one I came with the idea of calculating a HASH code for the object before the execution of the application which can change the object attributes and comparing it with the HASH calculated for the same object after the execution.

That way, checking only two hashes simplifies a lot the code. So.... is there any way of calculating a HASH for any object instance? if not... any other approach?

Thanks in advance.

1 ACCEPTED SOLUTION

huseyindereli
Active Contributor
0 Kudos

Hi Jorge ,

Maybe tracking changes using version management could help you. VRSD table has the version management data.

SE24 -> UTILITIES -> VERSIONS -> VERSION MANAGEMENT

Important -> There are different types for Public , private and protected sections.

In VRSD table ;

Enter your object name to the OBJNAME field and check if it helps you.

Regards.

5 REPLIES 5

huseyindereli
Active Contributor
0 Kudos

Hi Jorge ,

Maybe tracking changes using version management could help you. VRSD table has the version management data.

SE24 -> UTILITIES -> VERSIONS -> VERSION MANAGEMENT

Important -> There are different types for Public , private and protected sections.

In VRSD table ;

Enter your object name to the OBJNAME field and check if it helps you.

Regards.

0 Kudos

Sorry Hüseyin Dereli, but I'm not talking about source version control, but how to detect attribute modifications of an ABAP Object Instance.

for example, suppose you have a program which reads data from DataBase and stores temporally that data into an ABAP Object like this:


ABAP Object AAAA{
   private attr1
   private attr2
}

and passes this ABAP Object into a screen for user interaction, or even a FunctionModule or Method or anything else...


data: myObject type ref to AAAA.
myObject-attr1 = 1
myObject-attr2 = 2.

CallFunction AnyFunction Changing data = myObject

After the execution of AnyFunction I would like to know if myObject has been changed but I'm trying not to check attribute by attribute because if myObject has a lot of attributes (not in this example but in the real source code)

It would be great if we could do something like this:


data: myObject type ref to AAAA,
          oldHash type hash,
           newHash type hash.

myObject-attr1 = 1
myObject-attr2 = 2.

oldHash = myObject->get_hash()

CallFunction AnyFunction Changing data = myObject

newHash = myObject->get_hash()
if oldHash NE newHash.
* MyObject has been modified
endif.

0 Kudos

Hello Jorge,

you have two options:

1) Write your own ABAP OO encapsulation for DataObjects ( aka DAO-Objects )

2) Use ABAP OO Persistence Services.

With the OO Perstistence Services, you will get an event raised, when a field is changed during a transaction context.

Kind regards,

Hendrik

0 Kudos

Okay Jorge ,

I've just misunderstood your question.

I don't know if there is any simple way as you described.

( IMP_GET_HASHVALUE Function module or cl_hash_utilities_imp Utility Class )

There are functions for retrieving Hash value However you should implement your own method. There are FMs to get an Object's attributes at runtime. You can write a generic method to use for all.

Regards.

jsancho
Participant
0 Kudos

Finally I've build my own code to calculate dinamically the corresponding hash for each instance, because using Persistent Classes would need a lot of modifications in my code, but I'll take into account for the next time.

Thanks guys for your advice!