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
Labels in this area