Modern versus classic — what to write instead¶
Level: 201 · working knowledge
One line: A translation table from the ABAP you will read to the ABAP you should write — each row a construct that still works, its 7.40+ replacement, and the page that explains the difference — because the hardest part of modernising is not learning the new form but recognising the old one.
The table¶
| You read | Write instead | Since | Page |
|---|---|---|---|
DATA lv TYPE i. lv = … at the top of a 2,000-line report |
DATA(lv) = … where it is used |
7.40 | DATA |
CREATE OBJECT lo. |
NEW |
7.40 | NEW |
MOVE a TO b. ADD 1 TO n. |
=, + |
forever | MOVE, ADD, COMPUTE |
READ TABLE … WITH KEY … + IF sy-subrc = 0 |
itab[ … ], line_exists( ), OPTIONAL |
7.40 | READ TABLE |
LOOP AT … INTO wa. … MODIFY itab FROM wa. |
LOOP AT … ASSIGNING |
6.x | LOOP AT |
SORT + AT NEW / AT END OF / SUM |
LOOP AT … GROUP BY |
7.40 | AT NEW |
a work area, APPEND per row |
VALUE #( ( … ) ( … ) ) |
7.40 | VALUE |
| a loop that builds a table from another | VALUE #( FOR … ) |
7.40 | FOR |
| a loop that totals | REDUCE |
7.40 | REDUCE |
IF … ELSEIF … ENDIF assigning one variable |
COND |
7.40 | COND and SWITCH |
CONCATENATE a b INTO c SEPARATED BY space. |
\|{ a } { b }\| |
7.02 | String templates |
CONDENSE lv. TRANSLATE lv TO UPPER CASE. |
condense( ), to_upper( ) |
7.02 | In-place string statements |
FIND REGEX |
FIND PCRE |
7.55 | Regular expressions |
SELECT * … INTO TABLE lt WHERE f = v. |
SELECT f1, f2 … WHERE f = @v INTO TABLE @DATA(lt). |
7.40 SP05 | SELECT |
SELECT … ENDSELECT over a small set |
INTO TABLE |
forever | Cursors |
a second SELECT in a LOOP |
a join, or a hashed lookup | forever | Open SQL |
RAISE EXCEPTION TYPE zcx EXPORTING … |
RAISE EXCEPTION NEW zcx( … ) |
7.52 | TRY, CATCH, RAISE |
CATCH SYSTEM-EXCEPTIONS |
TRY … CATCH cx_sy_… |
6.10 | Exceptions |
TRY … CAST … CATCH cx_sy_move_cast_error as a type test |
IS INSTANCE OF, CASE TYPE OF |
7.50 | CASE TYPE OF |
IF flag = 'X'. |
IF flag = abap_true.; xsdbool( ) |
7.02 | Booleans |
CONSTANTS: BEGIN OF gc_status, … END OF gc_status. |
TYPES BEGIN OF ENUM |
7.51 | Enumerations |
RANGES r FOR f. |
TYPE RANGE OF |
7.0 | Ranges tables |
TABLES, OCCURS, WITH HEADER LINE, TYPE-POOLS |
plain DATA and TYPES |
6.10 | Obsolete declarations |
FORM / PERFORM |
a method on a local class | 4.6 | FORM and PERFORM |
REUSE_ALV_GRID_DISPLAY |
cl_salv_table |
7.0 | ALV |
WRITE as a UI |
ALV | forever | WRITE |
EXEC SQL |
ADBC, or Open SQL | 7.0 | Native SQL |
DEFINE macros |
methods | forever | DEFINE |
BREAK-POINT. |
BREAK-POINT ID, or none |
6.20 | Checkpoint groups |
The rule about when¶
Every left-hand column still compiles on an on-premise system. Rewrite when the module is being reworked; do not rewrite in a bug fix, and do not rewrite in a system whose oldest member cannot run the right-hand column — see Which release am I writing for?. ABAP Cloud is the exception: there, several left-hand rows do not compile at all.
See also¶
- Constructor expressions — the new family, as a family
- Clean ABAP — the style argument
- ATC and Code Inspector — the checks that flag the left column
- ABAP Cloud — where the left column stops compiling