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 in design methods

Former Member
0 Likes
476

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

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
440

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

3 REPLIES 3
Read only

MarcinPciak
Active Contributor
0 Likes
441

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

Read only

0 Likes
440

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

Read only

Former Member
0 Likes
440

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