Todo Based Coding in ABAP
Today, I would like to demonstrate a very simple but effective programming habit that I use in ABAP development: “TODO based coding”.
The idea is to plant TODO comments into the code (typically among multiple programs / classes) before actually starting to write / modify code. That enables us a few things:
- Planning before coding
- Simplifying large refactoring tasks
- Figuring any semantic / functional gaps before modifying the code
- Eliminating the risk of forgetting things
- New programmers can take over incomplete programs
However, in order to make this technique effective, we need to make the compiler / IDE warn us if there are TODO’s left in the compiled code. Otherwise, incomplete code might go to production.
Looking at some other platforms;
- Pycharm (Python IDE) shows #TODO comments as a separate list in the IDE
- XCode (Swift IDE) evaluates #warning commands as compiler warnings and shows them every time you compile the code
As far as I know, ABAP lacks such a feature. The closest thing that I know is the task list feature of Eclipse, but they are stored in the local machine; so a new programmer doesn’t see them at all.
My simple but effective solution is to use a harmless fake pragma: ##TODO.
SAP doesn’t recognize this pragma, so every time I check or activate a code containing ##TODO , SAP will show a warning. Eclipse or SE80, works in both.
Here is how a typical todo looks like:
##TODO. " Complete ZCL_CLASS1=>METHOD1 first " call METHOD1 here " ensure that the returned value is OK " otherwise, raise an exception
Me & some fellow ABAP programmers are using this technique since a while, and we are happy with the results.
This approach can also be used when the architect and programmer are different people. The architect can create all the programs, classes, critical methods, interfaces, etc and fill them with ##TODO comments. After that, programmers can step in and start coding; clearing the architectural ##TODO ‘s.
You can also get creative and invent your own fake pragmas; such as: ##TODO_TICKET_123 or ##TODO_PRIO_2 .
I hope that this approach will benefit other fellow developers as well.