Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Persistent class

Former Member
0 Likes
1,221

Hi all,

i have the book abap - next generation and now i want to create an example of a persistent class.

I have created a persistent class.

But now my agent class has no interface method called get_persistent.

The code described in the book.

l_agent = zca_sflight_pers=>agent.

l_pers_obj = l_agent->get_persistent(

i_carrid_id = i_carrid_id ).

But there is no get_persistent method...

Whats wrong???

regards

3 REPLIES 3
Read only

Former Member
0 Likes
629

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>Check the below link</b> :

http://help.sap.com/saphelp_nw04/helpdata/en/f5/a3682ebc6911d4b2e80050dadfb92b/content.htm

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/840ad679-0601-0010-cd8e-9989fd65...

<b>Reward if usefull</b>

Read only

Former Member
0 Likes
629

Hi,

thanks.

I tried the sflight example.

My classes:

zcl_sflight_pers

zca_sflight_pers

zbc_sflight_pers

But i get some syntax errors

l_flight_agent = zca_sflight_pers=>agent.

-> field agent unknown

l_flight = l_flight_agent->get_persistent(

i_carrid = 'LH'

i_connid = '0400'

i_fldate = '20031030' ).

-> get_persistent is unknown

Why are these fields and methods not available?

I followed these instructions:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/840ad679-0601-0010-cd8e-9989fd65...

Any ideas?? Do i have to create the static attribute agent by myself??

regards

Read only

0 Likes
629

Hi,

i have found the solution by myself.

1. create persistent class

2. activate!!!

If i do the activation after the mapping in the base class the actor attribute is

missing!!

3. define mapping

I have to map all fields from the table otherwise i got the error...

One or more fields....

-> then i can activate the persistent class

-> the methods in the base class will be created (e.g. get_persistent)

regards