Skip to Content
author's profile photo
Former Member

What is Persistancy Class ?

What is Persistancy Class ?..with Example .

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 03:39 AM

    Hi Girish,

    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 <b>persistence framework</b> that closes the object-relational gap.

    You no longer need to write <b>SQL code</b> as objects are transparently loaded from the database when needed. You must create a <b>persistent class</b>. 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 <b>DEMO_CREATE_PERSISTENT</b>.

    <b>DEMO_QUERY_PERSISTENT</b>

    kindly look into below link for screen shot to create persistence class

    http://erpgenie.com/abaptips/content/view/417/38/

    Regards

    Sathish

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 05:18 AM

    Hi Girish,

    As stish said 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 satish 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.

    Reward points if useful else getback,

    Aleem.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Sep 28, 2007 at 05:33 AM

    Hi Girish,

    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.

    <a href="/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

    Reward points if useful,

    aleem.

    Add comment
    10|10000 characters needed characters exceeded