Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
roberto_forti
Contributor

ABAP Object Services


In this blog you are going to read some information about ABAP Object Services and how to create persistent class object with single-table using mapping assistant tool, create object instance with class agent, consumer perspective and record converted into database table.

#1. Creating Persistent Object with single-table


SAP Community has introduced excellent Professionals to SAP world as well as providing opportunity for all to writing blog posts which has helped us to improve SAP knowledge.

One of many important SAP techniques which I have been reading about is ABAP Object Services applying object-oriented concept.

This first blog post will show a simple way of creating persistence class working with single-table.

1. ABAP Object Services – Creating Persistent Object with single-table


  • Objective: handling the synchronization of data stored in objects with database table creating a method to synchronize object data with a relational database table considering object relational mapping (ORM) tool.




  • Following simple steps to create persistence class.


1.1. Creating Persistent Class (SE80)

  • Start transaction SE80 to create a Persistence class without “Final” class checked.





  • Confirm “Yes” to activate Class Agent – “At runtime, Class Agent run between persistent objects and the ABAP Object Services”.




  • Agent ABAP Persistent Class implemented.




1.2. Working with single-table using Mapping Assistant tool


  • Going to Persistence Representing to add single-table





  • Insert table/structure for corresponding class.




  • By Business Key – ABAP Dictionary tables which use exiting primary key.





  • Mapping Assistant tool  – Click on Generator Settings button and uncheck the minimum Interface for methods CREATE_PERSISTENT and CREATE_TRANSIENT.




1.3. Persistent objects – Consumer Perspective

  • Persistent objects are managed by object services.





1.4. Creating Persistent Object Instance with class agent

  • ABAP code example: Simple report with corresponding statement Persistent Class and Agent Class working with synchronization of data stored in objects with a relational database table.


*&---------------------------------------------------------------------*
*& Report ZABAP_PERSISTENT_OBJECT
*&---------------------------------------------------------------------*
REPORT zabap_persistent_object.

*&---------------------------------------------------------------------*
*& DATA OBJECT
*&---------------------------------------------------------------------*
DATA: lo_cl_persist TYPE REF TO zcl_single_table_persistent,
lx_os_ex TYPE REF TO cx_os_object_existing,
lv_text TYPE string.

*&---------------------------------------------------------------------*
*& START-OF-SELECTIONf)
*&---------------------------------------------------------------------*
START-OF-SELECTION.

TRY.
lo_cl_persist = zca_single_table_persistent=>agent->create_persistent(
i_char20 = 'TEST01'
i_int4 = 1
i_char50 = 'TEST-01'
i_fltp = '100.50'
i_tims = sy-uzeit ).
COMMIT WORK.

CATCH cx_os_object_existing INTO lx_os_ex.
lv_text = lx_os_ex->get_text( ).
ENDTRY.

* COMMIT WORK: Persistence Service convert in-memory record into the Database table.

1.5. Record converted into Database table


  • Transactions SE11, SE16 and SE16N to check it.




 

Certainly, learning ABAP Object Services technique will improve technical knowledge as well as makes the ABAP code flexible to implement persistence without writing SQL.

Is recommended reading SAP documentation and practicing it to understanding each detail.

Following excellent SAP documentation to support understanding ABAP Object Services technique.

 

SAP suggest that following SAP community is a perfect way to learn, improve and share technical skills and others posts regarding SAP best practices as the following useful blog links:

Useful Blogs



 

Finally, It always is a pleasure sharing a small peace of knowledge after learning from SAP community experts.

Thank you for reading this post and be nice with SAP community colleagues as well as sharing your feedback.
6 Comments
thkolz
Contributor
Thanks for the blog!

 

I used persistent  classes already 14 years ago, but honestly not anymore sincee then.

I don't really see the added value of not having SQL statements.

And I also did not see that SAP is using it somewhere  in their code...
hardyp180
Active Contributor
I agree with Thorsten.

Very good blog. I bought an SAP press book on this subject, again about 14 years ago.

I imagine the technology still works, but it was always an odd idea, and it never really caught on.I imagine in real life no-one has ever used this ever, and if they did, they thereafter wished they had not.

i have always regraded the whole idea as a sort of failed experiment by SAP, which was then abandoned.

Cheersy Cheers

Paul
thkolz
Contributor

Actually I used it in a project I've implemented 14 years ago. I guess at this time it was introduced in an ABAP book written by Rich Heilman.

It works well, but e.g. if a field needs to be added to/removed from a table it always takes more effort than just using plain SQL.

matt
Active Contributor
There are a few places where SAP use it. If you query table SEOCLASSDF with category 10, you'll see them. In a pure Basis installation, there's 172 persistent classes.

But I agree, I find they add no value to creating your own Data Access class where you can optimise your SQL and stopped using them years ago.

 

 
matt
Active Contributor
I also used it in a real life development. As I recall, I used it in a suite of programs to update and query certain database tables that were used as master data throughout the landscape. The advantage was that when a new data type came along, the new developer could just follow the process I had without much thought to get it to work.

What they don't have is interfaces which makes TDD a little trickier.
Jelena
Active Contributor
0 Kudos
Same here. Got book, read it, never used in real life. So wild seeing this resurface in 2022. 🙂
Labels in this area