After participating in a wonderful discussion OO style ABAP Programming Vs Procedural ABAP Programming, I could not stop from thinking over it and as I possess limited or almost no expertise in this area, I thought of presenting a simple skeleton that I would use for a report program. The case here is a classical report. The requirement can be anything, but for sure, it will allow user to enter something, validate the user input, fetch data, process data and finally display it on screen. I am trying to discuss the concept here, so for the time being, I have kept the code away. Thus it is implied that the class methods have importing, exporting and changing parameters, they throw exceptions that are handled by the program. However, the class(es) do not have any other class(es) as their attribute and no interface is implemented. The only exception is output class that deals with ALV.
Most of the times, I end up developing a class for UI, Data Processing and Output. Usually, if I hear the client saying they need lots of reports based on this screen & data, I create a global Z class. Otherwise, I create a local class. This class has methods to validate selection screen elements and throw exceptions. Each method will accept an input of appropriate type, or as an alternate, I can assign user input as attributes of the class. Every method of the class raises exceptions. However, I have not mentioned complete signature anywhere below. Just trying to communicate what I prefer doing.
If everything goes well, then the data fetching starts, I call methods of another Z class. This class has private methods to fetch data, process it and return final table(s) .
Finally all the data goes to the output class. This class has internal methods to instantiate and display ALV.
I thought another way of doing this can be create a parametrized constructor for the class. Parameters will be the selection screen elements. So just one call to the class and the you will see the output. However, I felt the 1st approach each better and continued with it.
In a nutshell, something like this will happen. I know END-OF-SELECTION is not really required but I think no harm if I use it.
AT SELECTION SCREEN
Call method of the ZInputClass for validation / additional data
Help and Guidance welcome!!! Hope someone will find it worth responding.