‎2007 Nov 09 2:54 PM
Hi Experts
What is persistent class. In which cases we use persistent class.Give some examples.
Helpful answers definitely rewards.
Regards
Pratap.M
‎2007 Nov 09 3:01 PM
‎2007 Nov 09 3:01 PM
‎2007 Nov 09 3:56 PM
Persistent Object class is simply an encapsulation of the database access. In reality, if you would use persistent objects, you would not be writing any SQL statements to access the data. All this is encapsulated. You would simply use the methods of the class to manipulate the data, whether reading, updating, or inserting. Persistent objects provide a standard interface to your database layer.
Regards,
Rich Heilman
‎2007 Nov 10 6:13 AM
Hi
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.
steps :
Go to se 24 - choose persistence class
it will be always protected class.
next screen will give u the persistence button when u click on that it will ask u to
add the table or struture.
now u can see two division of the screen where bottom portion of the screen will list uall the fields available and u need to double click and map to the top portion.
Save the persistence class and hit back button..
Whenever u create persistence class zcl_example_persist - it will create two classes - zca_example_persist
and zcb_example_persist automatically
Where zca_example_persist is the agent class and zcb_example_persist is base agent class..
Save and activate.
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.
REPORT ZPERSISTENCECLASS.
data : l_flight type ref to zcl_persist.
data : l_flight_agent type ref to zca_persist.
data : l_seatsfree type i.
data : l_seatsocc type i.
l_flight_agent = zca_persist=>agent.
CATCH CX_OS_OBJECT_NOT_FOUND .
*ENDTRY.
*TRY.
CALL METHOD L_FLIGHT_AGENT->GET_PERSISTENT
EXPORTING
I_CARRID = 'LH'
I_CONNID = '0400'
I_FLDATE = '20060701'
RECEIVING
RESULT = l_flight
.
CATCH CX_OS_OBJECT_NOT_FOUND .
*ENDTRY.
l_seatsfree = L_FLIGHT->GET_SEATSMAX( ) - L_FLIGHT->GET_SEATSOCC( ).
if l_seatsfree > 0.
l_seatsfree = L_FLIGHT->GET_SEATSOCC( ) + 1.
l_flight->set_seatsocc( l_seatsfree ).
endif.
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.
DEMO_QUERY_PERSISTENT
kindly look into below link for screen shot to create persistence class
http://erpgenie.com/abaptips/content/view/417/38/
To tell you more about this persistancy classes are used replace the sql. Actually this are developed to combine the advantages of object oriented design to the relational database model. The main advantage is security is enforced here because of the visibility restrictions private, protected, public of the classes , so you need not take care about the authorisations required for the task. Apat from this all updates are done in update tasks.
As already explained how to do this. Let me explain actually what happens.
Whenever you actiavate a persistancy class it creates class which acts as agent or actor to the persistancy class created. This class actually is responsible for the creation and maintenace of the instances of your persistancy class. If you take a closer look at the code given by satish we actually create an instace of the actor class. This class is actually a sub class of a base class whichhas all the methods.
So whenever you create a persistant class it creates 3 classes
1. CL_<NAME> - Persistant class created by you
2. CA_<NAME> - Class which acts as actor
3. CB_<NAME> - Base class for actor class.
This is the link where you will get step by step creation of persistant class with screen shots. Thomas jung explained it very clearly. The best part is here 3 code snippets are there which clearly tell us how to use persistant class. Particularly see the 3rd code where he is starting a transaction and after updation stoping the transaction.
<b>Reward if usefull</b>