‎2014 May 09 2:48 PM
Hi,
I recently when thru some blogs in SDN related to persistent class from Former Member. I understand how persistent class works but I am trying to understand why do we need a concept called persistent class when the same can be achieved thru normal selects. I am trying to find answers to the below questions.
What I know is when we call the method get persistent or get_XXX or set_XXX, internally SAP uses a select or insert.
1. So why cant we just use the the same ourselves. What is the advantage of creating a persistent object and then using get/set methods? IMO, this only makes things complex.
2. Lets say I want to retrieve multiple records into an internal table: Below is an example from Former Member:
Since we already do a SELECT on SFLIGHT, why not just select the rest of the fields and perform the calculations inside our program the normal way. Every time we perform get_persistent inside the second loop, we make a SELECT on the DB, how would this be performance effective even if its select single based on a key?
Also by doing this using persistent class, we first select data into a internal table and then we have to loop thru this table and then move the data into another internal table. This can be completely avoided if we do this the normal way.
isfligt1 -> normal table with the fields from sflight.
select carrid connid fldate from sflight
into table isflight1
where carrid = p_carrid
and connid = p_connid.
loop at isflight1.
clear isflight_line.
move-corresponding isflight1 to isflight_line.
append isflight_line to isflight.
endloop.
loop at isflight into isflight_line.
isflight_line-my_flight = zca_bc620_00_persist=>agent->get_persistent( i_carrid = isflight_line-carrid
i_connid = isflight_line-connid
i_fldate = isflight_line-fldate ).
modify isflight from isflight_line.
endloop.
3. In the same blog, there was also a question from about using where clause to fetch multiple records. Thomas had said that this can be achieved using...
Again my question here is why make it complex to build the where clause and then use query manager when you can simply use where clause on the select?
I am pretty sure there is a proper reason why we have persistent class and its advantages over using SQL. I am just trying to find the right place and reasons why someone would prefer using persistence over SQL
I know the same question was asked by and but I am looking for something in laymen terms to understand why and when use persistent class?
Thanks,
Vikram.M
‎2014 May 09 7:25 PM
Hello Vikram,
I think you wanted to refer to me - .
Persistence classes are not designed for mass processing since each record of the DB table is an object of the Persistence class. So if you want to process 1000x records of a DB table => you'll be creating 1000x objects which will be a performance overhead.
But consider building a custom application involving a few tables & a few records to maintain. You can use the Persistent classes for these tables & coupled with Transaction service you delegate the whole process of maintaining the DB recs to ABAP Object services. You don't have to worry how to handle the error if you try to insert a duplicate rec/ modify a rec which doesn't exist.
Recently i developed a custom tab in the Business Partner(BP) screen using BDT framework. In this i had to a custom table to maintain from the BP screen. I decided to use an MVC-architecture for this solution -
I had delegated all the DB operation to the Persistent class and it worked like a charm.
I am planning to blog about it once i have some time.
BR,
Suhas
‎2014 May 09 3:55 PM
Dear Vikram
In OO-ABAP persistent class is used to store the object permanently with some GUID. In general the object is just run time object, so to make that object state permanently in database we can use persistence class.
Regards,
Abbas.
‎2014 May 09 6:35 PM
Syed,
As far as I know its not necessary to have a GUID in order to use the concept of persistence.
Secondly I understand what persistence is. My question was "why" since I can use INSERT to save data in DB.
Thanks,
Vikram.M
‎2014 May 09 7:25 PM
Hello Vikram,
I think you wanted to refer to me - .
Persistence classes are not designed for mass processing since each record of the DB table is an object of the Persistence class. So if you want to process 1000x records of a DB table => you'll be creating 1000x objects which will be a performance overhead.
But consider building a custom application involving a few tables & a few records to maintain. You can use the Persistent classes for these tables & coupled with Transaction service you delegate the whole process of maintaining the DB recs to ABAP Object services. You don't have to worry how to handle the error if you try to insert a duplicate rec/ modify a rec which doesn't exist.
Recently i developed a custom tab in the Business Partner(BP) screen using BDT framework. In this i had to a custom table to maintain from the BP screen. I decided to use an MVC-architecture for this solution -
I had delegated all the DB operation to the Persistent class and it worked like a charm.
I am planning to blog about it once i have some time.
BR,
Suhas
‎2014 May 09 7:58 PM
I was definitely referring to you and was actually hoping either you or Namiesh would see this post since you guys have already talked about this
Thanks for a nice explanation.
You don't have to worry how to handle the error if you try to insert a duplicate rec/ modify a rec which doesn't exist.
The above statement is clearly a advantage, but even if the table has just 10 records (or even lesser) and we want to select a few of those based on certain condition, based on points 1 & 2 in my question, we still need extra processing in order to move the data from one table to another to be able to do the rest of the process and also build the where clause.
Either there is a different way to use the persistent concept when it comes to accessing multiple records (which I am hoping you will explain) or else I do not see any the advantage.
Cheers on your next blog and I hope you find time for the same soon.
Thanks,
Vikram.M