SAP MODERN ABAP - Guide
Get Example source ABAP code based on a different SAP table
Modern ABAP
ABAP_BACKGROUND
ABAP is a living programming language that is continually being developed. Since its introduction some 30 years ago, new ABAP programs have been developed continually, with work to advance the ABAP language ongoing at the same time. Developments to the ABAP language are either extensions of the existing language properties for implementing new functions, or they replace existing functions with more advanced concepts. The replacement of existing language elements with new ones usually makes the existing language elements superfluous or obsolete. The most prominent example of a development of the ABAP language is still the implementation of ABAP Objects.
With regard to the ABAP language, SAP has committed itself to a policy of strict downward compatibility. On the one hand, this means that an ABAP program written for ABAP_RELEASE 3.0, for example, can be executed on an AS ABAP in ABAP_RELEASE 7.0 or higher (provided that a non-Unicode system is being used). On the other hand, this also has the following implications:
These problems can be solved using the following simple rule.
ABAP_RULE
Do not use obsolete language elements for new developments. We also recommend an incremental changeover to new concepts as they become available.
ABAP_DETAILS
Newer language elements are always the better language elements. Obsolete language elements are only provided for downward compatibility reasons. A statement or statement addition is declared as obsolete only when a more powerful alternative exists or when the language element is identified as being prone to errors (in the sense that it invites insecure and non-robust programming). It follows that you cannot ensure secure and robust programming if you use obsolete language elements, which is why obsolete language elements should not be used for new developments.
If ABAP Objects is used, the majority of the obsolete statements and additions are already prohibited in the syntax. For this reason among others, we strongly recommend
ABAP_EXAMPLE_BAD
The following source code shows the solution of a task using obsolete language elements. A procedure is supposed to replace all occurrences of
new TYPE csequence
CHANGING text TYPE csequence.
DATA: pattern TYPE string,
subrc TYPE sy-subrc.
CONCATENATE '*' substring INTO pattern.
SEARCH text FOR pattern.
IF sy-subrc <> 0.
CLEAR subrc.
WHILE subrc = 0.
REPLACE substring WITH new INTO text.
subrc = sy-subrc.
ENDWHILE.
ENDIF.
ENDFORM.>
In the above source code, aside from the modularization with
ABAP_EXAMPLE_END
ABAP_EXAMPLE_GOOD
The following source code executes the same task as above; however, it uses the latest available language elements.
FIND PCRE substring ` b` IN text.
IF sy-subrc <> 0.
REPLACE ALL OCCURRENCES OF substring IN text WITH new.
ENDIF.
ENDMETHOD.>
The subroutine is replaced with a method. Using
ABAP_EXAMPLE_END
Note
In connection with the above rule, the question on the coexistence of old and new concepts within a program unit arises. There is only one area in which this is clearly defined in the syntax, namely when using the
This does not, however, mean that obsolete language elements should be used in enhancements to existing procedures to preserve consistency just because they already exist. Instead, this is the best moment to switch the entire procedure to the corresponding new language elements. By using unit tests to cover the procedures to be changed, it is possible to ensure that there are no unpleasant surprises during the changeover.