‎2009 Aug 04 4:15 PM
HI ,
i want to know if there is performance aspects and good design i do the operation in good way ,
this is regards insert , update , modify
I do read opration from the DB tables and i need to create or update the value
1. if sy-subrc = 0 i check if the data that i get form the
DB is equel to the data that i have, if yes dont do anything .
2. if sy-subrc = 0 and some records are different - > do update
3. if sy-subrc <> 0 - > insert the records to the DB via insert commend
i know that modify do both update and insert but my question if for my case
its good to separate the operation for two method despite i can do that in same method
1. methods handle insert
2. method Handle update
Regards
Joy
‎2009 Aug 04 5:14 PM
Hi Joy,
Basic rules about creating the methods would be:
- keep it smart
- keep it small
- let the method be responsible for certain task only
- minimize but don't atomize - which means do not create method just to execute one statement only. Class itself may then become very hard to maintain if too many methods are used.
Generally in your case it is really of no matter how you handle it, either in both or in one method. All in all they will be both responsible for doing very similar task. So you can use one method and pass parameter i.e. mode where I would be for insert, U for update, but it's always up to you which approach you take.
Regards
Marcin
‎2009 Aug 04 5:14 PM
Hi Joy,
Basic rules about creating the methods would be:
- keep it smart
- keep it small
- let the method be responsible for certain task only
- minimize but don't atomize - which means do not create method just to execute one statement only. Class itself may then become very hard to maintain if too many methods are used.
Generally in your case it is really of no matter how you handle it, either in both or in one method. All in all they will be both responsible for doing very similar task. So you can use one method and pass parameter i.e. mode where I would be for insert, U for update, but it's always up to you which approach you take.
Regards
Marcin
‎2009 Aug 04 8:59 PM
Hi Marcin,
Thanks ,
1. in persistence class there is one method that are responsible for update and modify ?
i ask it because the new concept or SAP is to use persistence class model class and business class so the persistence class have just 3 methods for create( with delete and read ) ?
2. one thing that i forget to Remind is that in the update method i do some enqueue and dequeue which i dont use in the insert method .
Regards
Joy
‎2009 Aug 04 6:13 PM
Joy,
The argument about splitting inserts and updates (as opposed to the more generic "modify") is an old one, but I understand that's not the topic here.
Regarding your design question: I'm leaning with Marcin, meaning that you should use only one method. Instead of passing it a "mode" parameter, you could also use two (optional) input parameters: one to pass data for inserting, and one to pass data for updating (and maybe one for deleting, if your application requires that). In the method, depending on which one is filled, you do either one or the other (or both).
Best regards
Rainer