2010 Apr 22 1:30 PM
Hello,
this is my first time with object services. I read a lot but can't find the information which I really need to implement my requirements.
I have build a persistent class, clicked to "persistence", mapped my persistent attributes. I want to use a table-like attribute in my class, which contains references to another class. I added this attribute manually to the attribute list in the class builder. Consequently, GET and SET methods were generated automatically. Then I changed the generator settings by activating "manual implementation of database access layer".
So, my first notice is - If I choose manual implementation a call of create_persistent-method will not work. Nothing will be inserted into the mapped data base table.
Can anybody give me a example which shows how I can implement the database access layer manually? What do I have to do to write object attributes into data base table?
Which methods do I have to enhance?
Thanks a lot for any help in advance!
Anne
2010 Apr 22 3:19 PM
Thanks for your answer, but I would not be sure if you really got my problem.
I really really read much stuff (including SAP help, sappress "object services in ABAP" by Assig, Fobbe, Niemitz, sappress "abap objects" by keller), I googled a lot. But I couldn't find detailed information about this manual implementation of database access which you can activate in persistence settings.
This is the only extract out of SAP Help regarding this topic:
"If you prefer to carry out a manual implementation of the database access layer, select to change the generator settings and select the field of the same name. In this case you can implement your own database read routines, through which you can redefine the generated SET and GET methods for access to the database. This is particularly recommended if you want to improve performance by providing these routines with their own buffer mechanism. "
And some information about so calles Structure mapping which means the same idea in my opinion
"Structure Mapping
In this case, you map ABAP Dictionary structures, rather than database tables or database views to persistent objects. The application developer must therefore program the type of persistent data storage in the appropriate methods of the class actor.
You will need to map a structure (or structures) if you want a persistent object to contain table-like attributes. Database tables can only have flat structures, which prevents your mapping the object to a table in this case. You must still use structure mapping, even if you want to store the data in a different form u2013 such as in a file on the application server."
I used the debugger to get the idea of the SAVE method. But I couldn't find the difference between manual and automatic implementation in the code.
I tried to use implicit enhancement, but was not successful. Right now I am trying to redefine the SAVE method of the interface IF_OS_CA_SERVICE. But I can't believe that I have to implement the whole attribute-table-mapping on my own now. That can't be the idea of object service and their manual implementation. In my opinion it must be possible to use predefined algorithm to map business key etc. to corresponding table fields and to implement own ideas just for those table-like attributes..
Or am I totally wrong with this thoughts?
Thanks in advance!!
Anne
Hello,
this is my first time with object services. I read a lot but can't find the information which I really need to implement my requirements.
I have build a persistent class, clicked to "persistence", mapped my persistent attributes. I want to use a table-like attribute in my class, which contains references to another class. I added this attribute manually to the attribute list in the class builder. Consequently, GET and SET methods were generated automatically. Then I changed the generator settings by activating "manual implementation of database access layer".
So, my first notice is - If I choose manual implementation a call of create_persistent-method will not work. Nothing will be inserted into the mapped data base table.
Can anybody give me a example which shows how I can implement the database access layer manually? What do I have to do to write object attributes into data base table?
Which methods do I have to enhance?
Thanks a lot for any help in advance!
Anne
2010 Apr 22 2:57 PM
Hi Anne,
as this is your first attempt at using persistent object I suggest you try and walk before you try and run.
Use the many blogs and tutorials on Persistent Objects to see how they work against standard database tables and how the code is implemented.
Then, when you want to implement getters and setters manually you will have a much better idea how to do it.
Cheers
Graham Robbo
2010 Apr 22 3:19 PM
Thanks for your answer, but I would not be sure if you really got my problem.
I really really read much stuff (including SAP help, sappress "object services in ABAP" by Assig, Fobbe, Niemitz, sappress "abap objects" by keller), I googled a lot. But I couldn't find detailed information about this manual implementation of database access which you can activate in persistence settings.
This is the only extract out of SAP Help regarding this topic:
"If you prefer to carry out a manual implementation of the database access layer, select to change the generator settings and select the field of the same name. In this case you can implement your own database read routines, through which you can redefine the generated SET and GET methods for access to the database. This is particularly recommended if you want to improve performance by providing these routines with their own buffer mechanism. "
And some information about so calles Structure mapping which means the same idea in my opinion
"Structure Mapping
In this case, you map ABAP Dictionary structures, rather than database tables or database views to persistent objects. The application developer must therefore program the type of persistent data storage in the appropriate methods of the class actor.
You will need to map a structure (or structures) if you want a persistent object to contain table-like attributes. Database tables can only have flat structures, which prevents your mapping the object to a table in this case. You must still use structure mapping, even if you want to store the data in a different form u2013 such as in a file on the application server."
I used the debugger to get the idea of the SAVE method. But I couldn't find the difference between manual and automatic implementation in the code.
I tried to use implicit enhancement, but was not successful. Right now I am trying to redefine the SAVE method of the interface IF_OS_CA_SERVICE. But I can't believe that I have to implement the whole attribute-table-mapping on my own now. That can't be the idea of object service and their manual implementation. In my opinion it must be possible to use predefined algorithm to map business key etc. to corresponding table fields and to implement own ideas just for those table-like attributes..
Or am I totally wrong with this thoughts?
Thanks in advance!!
Anne
2010 Apr 23 3:47 AM
Hi Anne,
I did a few experiments and found that there are differences in classes generated with the generator set to "Manual". It seems to me that all the code is still generated but the data persistence bits are commented out.
Check the methods MAP_INITIALIZE_METADATA, MAP_LOAD_FROM_DATABASE, MAP_LOAD_FROM_DATABASE_KEY, etc.
You can redefine these methods in the actor class to work the way you want them to. You may, for example, uncomment all the code except that to do with the particular fields you want to handle in a special way.
Of course you can also do this with an actor class generated with the "Manual" flag set off as well.
Cheers
Graham Robbo
2010 Apr 24 10:50 PM
Hi Graham,
thanks for your research! I didn't recognize the parts which were commented out while I was debugging. But it makes sense.
I have had the idea of switching off the "manual status", too. And I think I stick to it. Because I can be sure that the "normal" mapped attributes are saved and loaded correctly to / from data base tables then. I tried to redefine the SAVE method, but it didn't really work, because I couldn't use the necessary references etc then. Furthermore, all of these methods are implemented in the Base Agent class, which can only be enhanced implicitely at the beginning or end of the method. So, it's not possible to change code in between. (In addition, I recognized that I obviously don't have enough rights to create enhancements... )
But a work-around just came into my mind - I can copy the coding and paste it into my redefined part.. what do you think about it? Is this a proper way?
I will try to implement your approach (with the mentioned methods MAP_LOAD_FROM_DATABASE..etc ) on Monday when I am in my company again and give feedback here.
Thanks again!
Have a nice weekend!
Best regards,
Anne
2010 Apr 25 5:47 AM
The way to put your own code into a persistent object class is to redefine the methods of the actor class.
So your peristent object class definitiion (ZCL_MYPERSIST) generates a class called ZCB_MYPERSIST and a subclass call YCA_MYPERSIST.
You can redefine the methods in YCA_MYPERSIST.
Cheers
Graham Robbo
2010 Apr 26 12:50 PM
Hi Graham,
first of all, I could reproduce your described behaviour regarding code generation for "manual implemented classes" and, lets say "normal ones" with my created persistented classes.
The reason why I didn't get that before was the update_mode of the persistence manager. Whenever I debugged my sample coding, especially the command "COMMIT WORK" (which calls method SAVE of interface IF_OS_CA_SERVICE as I have already described in my post above) I don't reach the call for the method MAP_SAVE_TO_DATABASE (see extract of coding below - it's taken from line 132 of the method of Base Agent)
" * Direct DB operations
CALL METHOD map_save_to_database
EXPORTING
i_inserts = insert_data_tab
i_updates = update_data_tab
i_deletes = delete_tab."
Because this condition " if ( UPDATE_MODE = DMODE_DIRECT )" is false - update_mode is "0" and not "1" (dmode_direct) - I reach else-sector where function module "OS_UPDATE_CLASS" is called in update task. As I read in comment this function calls the method if_os_ca_service~save_in_update_task of this class agent. But I don't reach this method while debugging. I assume the reason is, that OS_UPDATE_CLASS is an update function module...
I made some experiments with "manual" mode switched on. I redefined your methods mentioned above (in detail: MAP_SAVE_TO_DATABASE, MAP_INITIALIZE_METADATA, MAP_LOAD_FROM_DATABASE, MPA_LOAD_FROM_DATABASE_KEY). I did it in the way I mentioned in my last post. I copied the original coding and pasted it into my redefined part. I uncommented all commented parts. I know, that I have to redefine agent methods, but the point is, that I lose whole automatically generated coding then. That's why I came up with this copy+paste-strategy of "old" coding so that I can add my additional coding and keep old one then. Do you know what I mean?
So, If I set update_mode to dmode_direct manually just before if-else-part begins, everything will work and object attributes will be written to data base table.
Do you know anything about this update_mode of persistency_manager? Where is the difference between direct call of map_save_to_database and the call of the function module OS_UPDATE_CLASS?
Thanks for your answer and your patience in advance,
Anne
2010 Apr 27 10:22 AM
Hello again,
I have to correct myself.
The above described behaviour resulted from a mistake made by myself.. I forgot to set some variables in actor's method IF_OS_CA_SERVICE~SAVE_IN_UPDATE_TASK. That's why it couldn't work well.. there were no data sets to insert into the mapped data base table.
So, problem solved!
Thx and kind regards,
Anne
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |