Hi All,
Im working on a generic 'Snapshot' functionality for Class objects.
Some background info:
The basic idea is that when the class implements the snapshot interface, a 'snapshot' can be taken of that object and its attributes. At a later point the object can be restored to its previous state by recovering all of its attributes values from the snapshot.
All types of attributes work well (data, ref to Class, ref to data, structs, tables, tables with refs, etc etc) except the typed data references ( TYPE REF TO [Type] ).
The issue:
What i try to acomplish is the following:
I want to store a typed data reference (TYPE REF TO Mandt) into an untyped data reference (TYPE REF TO Data) and back.
The goals is to, in the end, have the data refrence point to the same address as in the beginning, not necesseraly the same value.
The problem is in the last step where i move back the reference from the untyped to the typed reference.
here i keep getting Dumps caused by type incompatability. The weird thing is that in debug i see that both TECHNICAL TYPES are equal (MANDT) but the Absolute types differ. This still understandable because in fact both data types are unequal (REF TO Mandt vs. REF TO Data).
I've tried dozens of things but i can not get it to work properly. Ive looked into type casting, using helper refs, trying to dynamically create the store data object with type specified, etc , etc.
Please see the sample code below for better understanding.
Hope you guys can help me out here. Any other solution to accomplish my goal is welcome as well ofcourse!
Thanks in advance!
Joris Bots
REPORT ztestjbo3. ********************************************************** * Store a typed data reference into generic 'Store'. * and restore from that store. * Phase 1: Store/Save data reference in store * Phase 2: Change location our datref points to * Phase 3: Restore our dataref from the store ********************************************************** * The generic data store (untyped) DATA g_datastore TYPE REF TO data. * Simple data DATA lv_mandt1 TYPE mandt VALUE '100'. DATA lv_mandt2 TYPE mandt VALUE '200'. * Our data reference (typed) DATA lr_mandt TYPE REF TO mandt. ************************* Phase 1 Store/Save data reference in store GET REFERENCE OF lv_mandt1 INTO lr_mandt. * our data ref lr_mandt now points to lv_mandt, containing '0100' *create data g_datastore like lr_mandt. g_datastore = lr_mandt. * store/save this ref to '0100'. ************************* Phase 2 Change location our datref points to * Get other ref into LR_MANDT GET REFERENCE OF lv_mandt2 INTO lr_mandt. ************************* PART 3 Restore our dataref from the store FIELD-SYMBOLS <fs> TYPE any. ASSIGN g_datastore TO <fs>. * This is where it all goes bad. lr_mandt = <fs>. * Shortdumps caused by type incompatability * In debug it shows that technical Types are equal (MANDT) * but The Absulote types (%_T00004S00000038O0000022592, etc) differ. * Below code is NOT the solution since lv_Mandt1 then overwrites lv_Mandt2 *ASSIGN g_datastore->* TO <fs>. *lr_mandt->* = <fs>.
Edited by: Joris Bots on Jan 13, 2011 5:06 PM