ABAP Obsolete - Form
When you are buidling a report in SAP the first thing you will need is a usefull structure, this is why many devolpers use Form for this. But what can you do now to replace this obsolete term.
Table of contents
The solution of the problem is quite simple and is already described in the official documentary in a short sentence. In any case, you should only use methods.
Many of the old programs in the system work just like that! They use forms to encapsulate coding components, to bring order into the source code and to reuse program components.
Solution
Just use classes! They structure the source code just as well and offer many advantages in handling and implementation in existing coding.
Since the restructuring of the Modern ABAP, many things are much easier. An example would be the implementation of method calls with returning parameters in IF statements, which is not possible with Forms until today.
" Method call
IF lcl_app=>check_selection( ) = abap_false.
" ... Code or message
ENDIF.
We check the return value of the selection screen and decide how to proceed in the report. This looks simple and clean, but before the modern ABAP that looked a bit different.
" Variable definition
DATA ld_check TYPE abap_bool.
" old version of a call
CALL METHOD lcl_app=>check_selection
IMPORTING
ed_check = ld_check.
" Check
IF ld_check = abap_false.
" ... Code or message
ENDIF.
Here the implementation looks more like the form implementation. That's the reason why many developers prefer to use there old technique, what we can understand at this point too.
Usage
The use in a new report is quite simple, you just have to define the class and then implement it, you can already call and use it in any part of the program.
" Class definition
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
check_selection
RETURNING VALUE(rd_check) TYPE abap_bool.
PRIVATE SECTION.
ENDCLASS.
" Class implementation
CLASS lcl_app DEFINITION.
METHOD check_selection.
" ... Code
ENDMETHOD.
ENDCLASS.
The implementation and definition of the interface are always separate, keeping the code clean. Double-clicking on the method name will allow you to jump between definition and implementation.
Advantages
With the implementation and the use of classes, there are also some smaller advantages that we want to mention here.
- Avoidance of an obsolete command
- Structure and encapsulation of the report
- Easy implementation of ABAP unit tests for the automated test of the code
- Use as inline methods
Conclusion
The transition is within your grasp, try it once in a new report or a small evaluation. You will notice how fast you have forgotten the Forms and also an obsolete part of a more modern language.
In a next article, we want to talk a bit more about the structure of a report after the form statement and show you some quick benefits of the structuring.
Source:
SAP Documentation - FORM