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

differences in class types.

Former Member
0 Likes
1,612

Hi ,

can anyone explain me the diffence between class types(standard,exception,persistent) and when to use them . i have gone thru material bt can't get exactly their usage,mainly exception and persistence classes.

thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,129

Hi,

Persistent classes are created and managed in the Class Builder.

Prerequisites

Use of the prefix CL_ (or a corresponding naming convention in the customer namespace) is required for persistent classes since generation of the corresponding auxiliary classes assumes exactly this naming convention.

Procedure

To create a persistent class from the initial screen of the Object Navigator (SE80):

Select the category Class/Interface in from the object list.

Enter the name of the new class according to the naming conventions.

Confirm your entries with ENTER.

Confirm that you want to create the class.

The system displays the Create Class ... dialog box.

Enter the rest of the basic data for the class:

Select Persistent class as the class type.

Choose Save.

The Create Object Catalog Entry dialog box is displayed.

Enter the Package.

Choose Save again.

Or check these links....

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c3d638d11d4966d00a0c94260a5/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c46638d11d4966d00a0c94260a5/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c52638d11d4966d00a0c94260a5/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c58638d11d4966d00a0c94260a5/content.htm

Regards,

Satish

4 REPLIES 4
Read only

Former Member
0 Likes
1,130

Hi,

Persistent classes are created and managed in the Class Builder.

Prerequisites

Use of the prefix CL_ (or a corresponding naming convention in the customer namespace) is required for persistent classes since generation of the corresponding auxiliary classes assumes exactly this naming convention.

Procedure

To create a persistent class from the initial screen of the Object Navigator (SE80):

Select the category Class/Interface in from the object list.

Enter the name of the new class according to the naming conventions.

Confirm your entries with ENTER.

Confirm that you want to create the class.

The system displays the Create Class ... dialog box.

Enter the rest of the basic data for the class:

Select Persistent class as the class type.

Choose Save.

The Create Object Catalog Entry dialog box is displayed.

Enter the Package.

Choose Save again.

Or check these links....

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c3d638d11d4966d00a0c94260a5/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c46638d11d4966d00a0c94260a5/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c52638d11d4966d00a0c94260a5/content.htm

http://help.sap.com/saphelp_nw70/helpdata/en/06/f23c58638d11d4966d00a0c94260a5/content.htm

Regards,

Satish

Read only

Former Member
0 Likes
1,129

Hi

Persistent class

A special class, the attributes of which are linked to database tables via object-relational mapping. Since Release 6.10 they can be created using the Mapping

http://help.sap.com/saphelp_nw04/helpdata/en/f5/a36828bc6911d4b2e80050dadfb92b/frameset.htm

http://help.sap.com/saphelp_47x200/helpdata/en/ab/9d0a3ad259cd58e10000000a11402f/frameset.htm

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

Check this:

... EXCEPTIONS except1 = rc1 ...exceptn = rcn

Effect

EXCEPTIONS lists the exceptions to be handled by the calling program itself. At the end of the exception list, you can use OTHERS to refer to all the remaining exceptions.

If one of the listed exceptions occurs, SY-SUBRC is set to the appropriate value rc (a numeric literal!) and control passes back to the calling program. By specifying a return code, you can divided the exceptions into classes. With the second form, without "=rc", SY-SUBRC is set to a value other than 0 if an exception occurs.

If the function module triggers an exception (with the statements RAISE and MESSAGE ... RAISING) and the exception is not to be handled by the calling program itself,

RAISE terminates the program with a runtime error;

MESSAGE ... RAISING outputs the message.

Note

The following EXCEPTIONS are predefined by the system and have a special meaning:

OTHERS: Covers all user-defined exceptions in the called function module.

ERROR_MESSAGE: This exception instructs the system to ignore S messages, I messages and W messages until return from the function module (although they still appear in the log during background processing). When an E message or an A message occurs, the called function module terminates, as if the exception ERROR_MESSAGE has been triggered.

Example

DATA: WA_SFLIGHT TYPE SFLIGHT,

P_LOSS LIKE SFLIGHT-PAYMENTSUM,

P_REVENUE LIKE SFLIGHT-PRICE,

P_CARRID LIKE SFLIGHT-CARRID.

...

SELECT * FROM SFLIGHT INTO WA_SFLIGHT WHERE CARRID = P_CARRID ... .

CALL FUNCTION 'CALCULATE_REVENUE_LOSS'

EXPORTING

PAYMENTSUM = WA_SFLIGHT-PAYMENTSUM

SEATSOCC = WA_SFLIGHT-SEATSOCC

PRICE = WA_SFLIGHT-PRICE

IMPORTING

LOSS = P_LOSS

REVENUE = P_REVENUE

EXCEPTIONS

OTHERS = 1.

...

ENDSELECT.

...

Example

TABLES SFLIGHT.

DATA: ITAB TYPE STANDARD TABLE OF BCAXX WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 10.

P_YEAR ... .

CALL FUNCTION 'FILL_SEATTAB'

EXPORTING

YEAR = P_YEAR

TABLES

SEATTAB = ITAB

EXCEPTIONS

NO_ENTRY = 1

OTHERS = 2.

CASE SY-SUBRC.

WHEN 1. ...

WHEN 2. ...

ENDCASE.

And also check this doc.

http://help.sap.com/saphelp_nw04/helpdata/en/fb/35c62bc12711d4b2e80050dadfb92b/content.htm

Regards

Kiran Sure

Read only

Former Member
0 Likes
1,129

Hi

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.

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.

Check the below link :

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...

********************************

Exception class

http://help.sap.com/saphelp_nw04/helpdata/en/fb/35c62bc12711d4b2e80050dadfb92b/content.htm

Read only

Former Member
0 Likes
1,129

Thank you