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

How to write an adjustable ABAP program?

Former Member
2,571

Hi,

I have experience in developing programs in ABAP and through it would like to know how can I code keeping future changes in mind.

For example recently I developed a program for a customized process on client side and initially requirements were simple and program was done.

But few weeks later came changes that were critical and although I accommodated them it came at expense of code readability and performance.

Few more months later came few changes ,and at this moment I was thoroughly confused as to what I had done in there making myself confused by my own programming.

So I would really like to know as to what methodology you gurus adopt for these kind of scenarios assuming changes to be inevitable .

8 REPLIES 8
Read only

maheshpalavalli
Active Contributor
2,274

Hi NIDA,

As per me, I usually write the code which is reusable and modular to the peaks 😉 I create as many methods as possible to make my code more modular..

I code everything in global classes and methods, if possible in some cases I use inheritance concepts..

So for any kind of applications be it abap webdynpro odata UI5 or others if we make sure our code is very modular then it will be easy to accomodate any new changes and overall impact will be less.. atleast for me 🙂

If we try to use object oriented concepts as much as possible, the code will be a lot better. Documentation will als0 help a lot when we go back to change something. I try to put a lot of comments in my code if that involves some logic..

And remember if the issue is with the customer requirements, even writing the best code will also not help 🙂

Adding more below:

Try not to hard code and Try to use custom configuration tables as much as possible so we can write the code in such a way that changes in future can be avoided by just maintaining the entries in that configuration table..

this I try to use a lot in my code and it will always help in avoiding more changes in future.

Also, while writing code we need to get more than enough information from the customer so that we can write the code thinking future changes in mind and this where configuration tables will give you more benefits..

BR,

Mahesh

Read only

2,274

Mahesh is absolutely correct that custom configuration tables and lookup tables are a life-saver when having to add new functionality to an existing program.

"Also, while writing code we need to get more than enough information from the customer so that we can write the    code thinking future changes in mind ..."

A very important point!

One method I have found useful over the years is to get invited to some of the functional design meetings. One can get a real feeling for what the user community wants to see in the future, where they are headed or what it is they "really" are passionate about. We can also get a feeling for what leadership is pointing towards and what are their longer-term goals from these discussions.

Even the discussion points that were ultimately not approved for the current development cycle may well contain elements that can be considered when designing the code to accomplish the current tasking; often with few (or even no) additional resources. That type of detail usually gets lost in the translation from conference room table discussion among the user community to the final technical specification we developers work from. And that detail can make all the difference in writing flexible, robust programs.

Read only

0 Likes
2,274

Hi Mahesh,

Thanks for your useful reply..

Also apart from configuration table for hardcode values how do I plan ahead considering that these changes come as they are observed by customers in production and not in advance.

Let me say it like this

if varable1 >= variable2.

//my processing here

endif.

Now in future if more conditions or checks come for these two variables and apart from adding more if's, how to proceed, cause currently all I do is revamp it with more if statements. Now certain scenarios contain more variables and conditions to compare,

So what could be a suitable alternative to if or case statements.

Thanks and Regards,

Nida Khan

Read only

2,274

Precisely in these kind of scenario's we use customizing tables.. I didn't mean them only for the hardcoded values..

Lets take a very simple example:

Customer says i want the upload to work only for PDF documents.

So instead of writing an if condition for only 'PDF' document, create a customizing table for 'Allowed Doc Types Upload', here you can maintain a list of document types that are allowed to be uploaded.

Now in your code you can write a select query and check if that particular Document type is maintained or not, If it is maintained, then go a head and upload the document.

But if the business logic itself is entirely changed in the if condition, then obviously we have to accommodate the program with new code changes.

BR,

Mahesh

Read only

0 Likes
2,274

Hi Mahesh,

Got your point.

One more thing , how do I design my program flow (normally I program in core ABAP and not OOABAP), so as to leave "Window" for changes.
Is there a standard pattern in ABAP that i could follow where I could just add my functionality like in a BADI but for modification purpose and not enhancement.

In short any prerequisite designing required in abap for optimal programming and readability.

One more thing as added by Kerem Koseoglu . Design patterns for OOABAP seemed right approach but for CORE ABAP is there any alternative?

Regards,

Nida Khan

Read only

2,274

Hi Nida,

Yes, actually speaking you can create your own BADIs and use them for extension as well. I've worked in couple of projects where we used them like that especially the Filter BADIs.

I would say that from now onwards, strictly change your coding style to OOABAP and start using classes instead of includes and push all the business logic, UI logic & DB logic to classes(Multiple class for UI, BL & DB if possible), use the report/module pool programs only for the screen designing and displaying. This has its advantage, as you can use the same classes for your future ODATA & BOPF with minimal code changes which you cannot do with the normal core ABAP style programming.

You can also see standard modules like REFX, BP, CRM, C4C etc., completely uses OOABAP concepts to run the applications and they use different design patterns in all of those modules but most common design pattern you will find is Singleton & Factory design pattern. So may be you can check those patterns in different blogs available in SCN.

In parallel, as per the suggestion of Kerem Koseoglu, you can check those patterns and understand them and try to implement the same in ABAP. But i would suggest you to get good knowledge and understand of OOABAP in order to move forward with the patterns.

BR,

Mahesh

Read only

keremkoseoglu
Contributor
2,274

Using design patterns would improve the flexibility of your programs dramatically. In case you need a book on the subject, check: https://www.amazon.com/ABAP-Design-Patterns-Objects-PRESS/dp/1493214640

Read only

EnnoWulff
Active Contributor
2,274

Hi Nida,

there is no golden rule. You cannot predict the changes of the future. If you try, the changes will turn out to be totally different to your prediction... 😉

The tip of maheshkumar.palavalli is good: try to modulize.

Practice Clean code.

Strictly use constants for hard coded values.

In my opinion the only way is to steadily learn and develop your skills. After having finished a program try to get some colleagues to discuss some issues. Sit back and ask yourself: If I were a user, what functionality would I like to have additionally in this programm? Then try to implement it.

And: There is a difference between "being unable to extend a functionality" and "not understanding the former coded program"! If your are confused about what the hell you coded two months before then try to figure out why you are confused? What is not clear? Lack of documentation? Unprecise naming?

Cheers
~ Enno