Warning: include_once(http://erpgenie.com/_borders/topabap.htm) [function.include-once]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/vhosts/erpgenie.com/httpdocs/abaptips/templates/rhuk_solarflare_ii/index.php on line 52

Warning: include_once() [function.include]: Failed opening 'http://erpgenie.com/_borders/topabap.htm' for inclusion (include_path='.:') in /var/www/vhosts/erpgenie.com/httpdocs/abaptips/templates/rhuk_solarflare_ii/index.php on line 52
Home arrow Tips and Tricks arrow ABAP OO arrow Managing persistent objects with object services
Managing persistent objects with object services PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Dany Charbonneau   
Sunday, 03 June 2007
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:

 
< Prev   Next >

Google Search

Google Ads


Warning: include(http://erpgenie.com/_borders/bottom.htm) [function.include]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/vhosts/erpgenie.com/httpdocs/abaptips/includes/footer.php on line 22

Warning: include() [function.include]: Failed opening 'http://erpgenie.com/_borders/bottom.htm' for inclusion (include_path='.:') in /var/www/vhosts/erpgenie.com/httpdocs/abaptips/includes/footer.php on line 22