|
Managing Persistent Objects With Object Services |
|
|
|
|
Written by Dany Charbonneau
|
|
Sunday, 27 May 2007 |
Managing persistent objects with object services. Note: This only works for WAS 6.10 and over. There is a way to avoid building a fully object-oriented program while still working with non-object-oriented relational database. The object services layer now provides a persistence framework that closes the object-relational gap. You no longer need to write SQL code as objects are transparently loaded from the database when needed. You must create a persistent class.
Choose transaction SE24 and create a persistent class; this class must be protected.  In the class builder, a new button is added in the main toolbar, press it :  in the next screen, you just have to map which fields you need in your persistent class  After having saved the previous screen, you will notice that the system creates a set/get method for each field that you selected.  Activate the whole class. Now that we have a persistent object to access the database table SFLIGHT, we must access it in a program. Here is a small example to read/write data into SFLIGHT using persistent objects. Code: REPORT zdany_sflight_persistent. DATA : l_flight TYPE REF TO zcl_dany_sflight, l_flight_agent TYPE REF TO zca_dany_sflight, l_seatsfree TYPE i, l_seatsocc TYPE i. * Reference to the class agent, ALWAYS required for any operation l_flight_agent = zca_dany_sflight=>agent. TRY. *We read a record from SFLIGHT using a unique key l_flight = l_flight_agent->get_persistent( i_carrid = 'LH' i_connid = '0400' i_fldate = '20031030' ). *We read a specific field l_seatsfree = l_flight->get_seatsmax( ) - l_flight->get_seatsocc( ). IF l_seatsfree > 0. l_seatsocc = l_flight->get_seatsocc( ) + 1. * We write back a specific field into the DB l_flight->set_seatsocc( l_seatsocc ). ENDIF. ENDTRY. COMMIT WORK. There are lots of other methods and techniques that you can use in persistent classes. A demonstration of this can be found in program DEMO_CREATE_PERSISTENT.
Related Items:
|