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

Get and Set method /and persistence class

Former Member
0 Likes
4,102

HI All,

1. What is the Purpose of the get and set method ? does set is for update recored in table and get is the select it or get the data to update and set it in the DB.

2. what is recommended to use persistence class or the regular update and read data from performance aspects (in running program that need to update lot of data in run time and read large amount of data ).

Best Regards

Michael

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
2,546

The terms "getter" and "setter" are common OO terms. Getters get data from somewhere, and setters set it. In the case of persistence classes, the getters retrieve data from the database, and setters write to the database.

If you are handling large amounts of data in one go, or have complex selection requirements, don't use persistence classes. Use select statements, but do encapsulate all the db operations into a seperate class, to maintain the seperation of the database layer from the application.

matt

The terms "getter" and "setter" are common OO terms. Getters get data from somewhere, and setters set it. In the case of persistence classes, the getters retrieve data from the database, and setters write to the database.

If you are handling large amounts of data in one go, or have complex selection requirements, don't use persistence classes. Use select statements, but do encapsulate all the db operations into a seperate class, to maintain the seperation of the database layer from the application.

matt

6 REPLIES 6
Read only

Former Member
0 Likes
2,546

This message was moderated.

Read only

matt
Active Contributor
0 Likes
2,547

The terms "getter" and "setter" are common OO terms. Getters get data from somewhere, and setters set it. In the case of persistence classes, the getters retrieve data from the database, and setters write to the database.

If you are handling large amounts of data in one go, or have complex selection requirements, don't use persistence classes. Use select statements, but do encapsulate all the db operations into a seperate class, to maintain the seperation of the database layer from the application.

matt

Read only

Former Member
0 Likes
2,546

HI,

What is recommended to use in abap ,set and get method for every entity or

using constructor and get method?

Best Regards

Michael

Read only

Former Member
0 Likes
2,546

hi,

the constructors are basically being used to initialize the attributes of a class.

so they actually will work at first.

so depending on that if you have requirement say you need to set the values for certain parameters initially then you can go with constructors.

and about setters, these are normal function module... its not something which is predefined in 00 that will do the job automatically.

so you can use them basically whenever you need to set some values for some attributes.

its just like a normal method.

for eg. when you create a entry that can be done using set methods, and when you have to select some entries for display purpose that can be done using get methods.

its just a way of describing about data creation and data retrieval.

hope this will help you!!!

Thanks & Regards,

Punit Raval.

Read only

naimesh_patel
Active Contributor
0 Likes
2,546

You can create a "mapper" type of methods. One method to map the data from the Persistent object to Structure; and another method for the vice versa. Use these methods whenever you need to map your data between persistent object & structure.

In the mapper method from persistent object to structure, you use all the GET methods of the object and set the structure field. Like:


  struct-field1 =   o_pers->get_field1( ).
  struct-field2 =   o_pers->get_field2( ).

  struct-fieldn =   o_pers->get_fieldn( ).

In the other method, you need to use the SET methods to set the data from the structure to persistent object.


  o_pers->set_field1( struct-field1 ).
  o_pers->set_field2( struct-field2 ).

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
2,546

Hi Michael,

I'd like to explain you about Persistent class

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

Eg. A global class is persistent by default, but here we're trying to make 'object' persistent. Persistent service is invoked by 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 basis class 'zcb_<name>'.

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

~ In the calling program, we need to define a reference variable with the type of class actor and fill it with the reference from the static attribute agent.

~ We can create a new instance of a persistent class using its method 'create_persistent'.

~ If the object already exists, it raises a class-based exception 'cx_os_object_existing'

~ We can load the persistent objects back into the program using 'get_persistentmethod'.

~ If the object is not found, it raises the class based exception 'cx_os_object_not_found'.

Hope this helpful to you.

Thanks