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

Help with design abap class

Former Member
0 Likes
1,872

Hi,

I need your suggestion in order to build class in abap objects,

In Java the concept is that for all entity we need to build class.

Like for employee, for address(include email address ) , phone etc, locale ...

I data will be stored in different table like employee , address

, phone , attributes and additional data.

i need to provide a functionality that allow to some services to read the employee with

all is data like for instance phones (one or more) and update the phone if it changing

read the employee locale and update and so on.

1. the main isuue here is if to provide different classes for employee , phone ,

address (include email address and additional data ) ,

or class 1 that can handle all the thing.

in each class i need get or set.

2. what about presisent class,mainly i need to read the data and Rarely change it.

Best Regards

Nina

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,799

You may create individual persistence classes for all those database tables (e.g. Employee, Address...). Persistent class would create GET methods for each field and SET Methods for each non-primary key fields.

You create one business class which could have all the methods to read the data by using these persistent classes e.g. Get_employee_address, get_all_employees etc. These methods should be Static because the nature of the method is Import something and return something.

Now, you can create a Model class which you will be using for your application. From the model class, call these methods from the business class.

Regards,

Naimesh Patel

14 REPLIES 14
Read only

naimesh_patel
Active Contributor
0 Likes
1,800

You may create individual persistence classes for all those database tables (e.g. Employee, Address...). Persistent class would create GET methods for each field and SET Methods for each non-primary key fields.

You create one business class which could have all the methods to read the data by using these persistent classes e.g. Get_employee_address, get_all_employees etc. These methods should be Static because the nature of the method is Import something and return something.

Now, you can create a Model class which you will be using for your application. From the model class, call these methods from the business class.

Regards,

Naimesh Patel

Read only

0 Likes
1,799

HI Naimesh,

Thanks,

what does it mean:

Now, you can create a Model class which you will be using for your application. From the model class, call these methods from the business class.

can you please elaborate what is model class and why i need it ?

Best Regards

Nina

Read only

0 Likes
1,799

Model class gives you one more layer of abstraction.

For example, you want to create a report. You call all your business class methods directly in your report. Now there is another requirement to generate a webdynpro report for the same requirement. You need to put all your logic again in this new application. If you have wrapped all your logic in the Model class than you don't need to write this logic again in the new Application. You just need to call the methods from the model class in new application.

Regards,

Naimesh Patel

Read only

0 Likes
1,799

HI Naimesh,

Thanks for your suggestion I use them

1. What the benefit of using a persistence class , I read on the Sap Help the Theory,

But i need the practical aspects from your experience .

a. What is the advantage instead of using regular select or read commend or modify and etc...

b. How the class handle with performance of reading and modifying objects .

2. General question:modeled class and business class behave differently ,or it's just type of declarations.

Best Regards

Nina

Read only

matt
Active Contributor
0 Likes
1,799

The idea that Naimesh is wanting to get across, and that many of us use, is to layer our developments. So, at the bottom, we have a class that reads data to and from the database. The advantage of using the persistence class framework for this, is that SAP generate most of the code you need for you. You could, however, develop your own class that does these reads and writes. ( Note, in SAP we generally don't write directly to the standard SAP tables - we use BDC or BAPIs ).

For example, you're application might have documents with header and lines. Header data will be in a header table, line information will be in a line table. You create persistent clases for the header table, and for the line table. This is the persistence layer.

The next layer is to handle the CREATE, READ, UPDATE, DELETE operations. This handles the document as a whole - both header and lines, and communicates with the persistence layer. This is often called the business object layer. For example, delete will remove the records from both the header and the lines tables. Applications interact with the business object layer - they don't have to be concerned with how the data is actually stored in the database.

The application layer uses the business object layer. This could also be considered to be the model layer. This contains the methods which handle how the application works - but not the screen handling. That's handled by the next layer - the UI (User Interface) Layer.

I'm developing an application that can be access by both webdynpro and by classic dynpro. I have one model, one set of business object classes, one set of persistent classes. Both my webdynpro and classic dynpro use the same model class.

The point is that at each layer you encapsulate (abstract) the logic for that layer. Then you don't have to be concerned about what happens at lower layers. You can also test the lower layers, without caring about the effect on the higher layers, because they layers are only loosely coupled - a layer is dependent on the immediately lower layer only.

Rich Heilman's book about advanced techniques explains this with example. It's quite good!

matt

Read only

matt
Active Contributor
0 Likes
1,799

>1. What the benefit of using a persistence class , I read on the Sap Help the Theory,

>But i need the practical aspects from your experience .

>a. What is the advantage instead of using regular select or read commend or modify and etc...

It's faster to develop, and you're just using getter and setter methods.

>b. How the class handle with performance of reading and modifying objects .

Performance is not as fast - but development is faster. Development time is more expensive than runtime.

>2. General question:modeled class and business class behave differently ,or it's just type of declarations.

It's a concept. As far as ABAP is concerned there is no difference between model classes, business object classes. Persistence classes are, however, different in SE24, as they have a mapping tool to map the database fields to getters and setters.

matt

Read only

0 Likes
1,799

HI Matt,

Assume i don't want to use the persistence class for the entity do u suggest to use

the same model that the all object are responsible to save the data on the table

via set and get method's.

P.s.

I need to create employee in DB tables employee with employee number and name,

in the table of the the adress i i need to store all the employee address but the problem that

can raise is with inconsistency if all the entity will have to keep her own data.

Can u provide me please an example how to create it and update it in db via set and get method's,

or u can send me class name that do such of thing and I take the idea from it.

Thanks in advance

Best Regards

Nina

Edited by: Nina C on Jun 22, 2009 6:25 PM

Read only

matt
Active Contributor
0 Likes
1,799

I'm sorry, but I don't understand your question well enough to be able to answer.

matt

Read only

0 Likes
1,799

For you requirement, you don't have to create the Persistent Class. In the Business Class (Layer) you have to use the BDC or the BAPI to create Employee Master Data.

CREATE_EMPLOYEE method will call the BDC on PA30 or respective BAPI to create the Employee. I don't have much knowledge on the Employee BAPI's.

READ_EMPLOYEE method will read the data from the different infotypes. You can use Select statements to read the data.

Regards,

Naimesh Patel

Read only

0 Likes
1,799

HI Matt,

i explain it again.

i have four tables:

1. user tables

2. machine (computer /blackberry... ) that will store user locale for every machine

user can have 4 of 5 machine with different locale in every machine

3. attributes

4. additional data.

All this tables is are related to user and machine,

i.e. i can create user in the table without create machine but i can't create

Racine without creating user ,and so on for attributes that relate for user and machine.

for that i have several of question .

1. can i build entity/class like you mention before without using persistence class i.e.use the same paradigm like 4 class for every table that responsible to get and store (set/get)the data on the tables and one class (business class ) with static attributes that read the data?

2. Assume i want to create user in the table via set and get method can

u provide please short example how to do so or some class that do that

in the backend so i can see the code.

Thanks a lot !

Nina cater

Read only

0 Likes
1,799

HI Naimesh,

This is not relate to PA30 or employee,

Sorry if i don't explain myself well

i have four tables:

1. user tables

2. machine (computer /blackberry... ) that will store user locale for every machine

user can have 4 of 5 machine with different locale in every machine

3. attributes

4. additional data.

All this tables is are related to user and machine,

i.e. i can create user in the table without create machine but i can't create

Racine without creating user ,and so on for attributes that relate for user and machine.

for that i have several of question .

1. can i build entity/class like you mention before without using persistence class i.e.use the same paradigm like 4 class for every table that responsible to get and store (set/get)the data on the tables and one class (business class ) with static attributes that read the data?

2. Assume i want to create user in the table via set and get method can

u provide please short example how to do so or some class that do that

in the back-end so i can see the code.

Thanks a lot !

Nina cater

Edited by: Nina C on Jun 23, 2009 12:28 PM

Read only

matt
Active Contributor
0 Likes
1,799

> 1. can i build entity/class like you mention before without using persistence class i.e.use the same paradigm like 4 class for every table that responsible to get and store (set/get)the data on the tables and one class (business class ) with static attributes that read the data?

I would start witht the ideal of creating one class per table, and then another class to bring them together.

>

> 2. Assume i want to create user in the table via set and get method can

> u provide please short example how to do so or some class that do that

> in the backend so i can see the code.

That would be just standard Open SQL - update, modify, select etc.

Read only

0 Likes
1,799

HI Matt,

I am currently having a new question for that issue,

for that i open new message.

Thanks a lot!

Best Regards

Nina

Read only

Former Member
0 Likes
1,799

Hi,

I'd like to explain you about Persistent class...

Persistent Class : It is used for storing the object of a class persistently i.e. properties of the object is stored permanently in the database.

For eg., a global class is persistent by default, but here we are trying to make 'object' persistent.

Persistent service is invoked by the persistent class to store the state of an object permanently. To use the persistent service for the objects, their types must be created as persistent classes in the class builder.

The term 'persistent class' indicates that the instances of the class and their state are managed by the persistent service. When you create a persistent class, the naming convention is 'zcl_<name>', the class builder automatically generates methods for getting and setting the attributes. In addition to this, other repository objects are also generated including the class actor (class agent) with the naming convention 'ZCA_<name>'. The programs must call the methods of this class to manage the instances of the persistent class. This class(agent) also performs the database access. This class inherits the required methods from the base class 'ZCB_<name>'

The Actor class is a singleton instance and it has a friendship relation with the persistent class.

Hope this is helpful.

Thanks