Obsolete Language Elements
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
ABAP has kept almost every statement it ever had. When a better way arrived, the old way was not removed: it was marked obsolete. An obsolete statement still runs, and SAP keeps it only so that old programs do not break. A newcomer meets obsolete statements the first day, because most books, forum answers and programs in a real system were written before the modern forms existed. This page lists the obsolete statements you are most likely to meet, shows each next to the statement that replaces it, runs the pairs that the local playground can run and says which ones it cannot. It is written against Standard ABAP release 8.16 and ABAP for Cloud Development release 9.20 (2608). Obsolete elements belong to classic Standard ABAP, on premise and in a private cloud system. In ABAP Cloud, the restricted language version ABAP for Cloud Development, nearly all of them are not allowed at all.
Before you read
-
Data Types and Data Objects: structures, table types and inline declarations, which several replacements use.
-
Expressions, Operators and Assignments: the assignment operators and calculation assignments that replace
MOVE,COMPUTEandADD. -
Internal Tables: what a header line is and why the table kinds replaced it.
-
Classes and Objects: methods, which replace subroutines and are called without
CALL METHOD. -
Class-Based Exceptions:
TRYandCATCH, which replaceCATCH SYSTEM-EXCEPTIONS.
Key terms
-
Obsolete language element: a statement or addition that still works for old programs but that SAP tells you not to use in new code.
-
Header line: a hidden work area with the same name as an internal table, created in old programs and not allowed in classes.
-
Ranges table: an internal table of the form sign, option, low and high that holds a set of conditions on one value.
-
Subroutine: a block of code between
FORMandENDFORMthat the statementPERFORMcalls, the old way to split a program into parts. -
Work area: a single structure that holds one row while you read it from or write it to a table.
-
Exception class: a class whose objects describe an error situation and that
TRYandCATCHhandle. -
ABAP Cloud: the restricted language version and development model for cloud-ready code, in which obsolete statements are mostly forbidden.
What obsolete means
The Keyword Documentation gives the rule in one paragraph. The language elements it lists as obsolete are available only for compatibility with older releases, you may still meet them in older programs, but they should no longer be used in new programs. Most of them are forbidden in the syntax of classes, so they can be used only outside classes, in reports, function modules and other classic program parts. The documentation also says that a replacement exists for every obsolete element and that the replacement is more efficient and easier to read.
The language version decides what the compiler accepts. In ABAP for Cloud Development most elements that Standard ABAP marks as obsolete are not allowed. The few that are still allowed there are marked as deprecated, which means their syntax is supported only for a time. The version baseline and the difference between the two language versions are explained in Language Versions and Released APIs.
Pairs of obsolete and modern statements
The table lists the pairs a newcomer meets most often. The right-hand column is what you write today. The last column says where the Keyword Documentation says the obsolete form is forbidden or what else you should know. Every row is written from the page of the Keyword Documentation for Standard ABAP that describes the obsolete statement; the pages are listed under References.
| Obsolete | Modern | What the documentation says |
|---|---|---|
|
A table without header line and a separate work area, or an inline declaration such as |
Header lines exist only outside classes and make a statement ambiguous, because the name means the table in one place and the hidden work area in another |
|
|
Forbidden in classes. The statement is exactly a standard table with the default key and an initial size |
Short forms |
The same statements with an explicit work area, |
They work only on tables with a header line and are forbidden in classes |
|
|
Equal to |
|
|
|
|
|
Forbidden in classes. Still needed only to pass data to and from the fields of a classic dynpro |
|
|
The documentation says to use only the assignment operators |
|
|
The keyword |
|
|
The calculation assignment |
|
|
The documentation says |
|
A method of a class, called as |
The documentation says not to create subroutines in new programs. Where a subroutine is still required, keep it as a thin wrapper around a method |
|
|
Forbidden in classes. External subroutine calls are obsolete anyway |
|
|
Each catchable runtime error has an exception class today. The two structures cannot be used in the same processing block |
|
An |
Forbidden in classes. The hidden helper variable is global to the program, which makes the structure error prone |
|
The component name in parentheses, |
Field symbols as sort or group criteria need header lines |
|
An internal table, or several |
Extracts have no data type and one dataset per program. The documentation says to use internal tables |
Logical databases and the event |
A global class that provides the data as a service |
No new logical databases should be created. The function module |
The same page of the Keyword Documentation also lists obsolete system fields, obsolete operand positions, obsolete language versions and a number of other statements. Not every entry has a one-line replacement, and a few are useful only to people who maintain very old systems, so this page does not repeat them.
Header lines and OCCURS
A header line is a work area that Standard ABAP creates for you with the same name as the table. The Keyword
Documentation lists the places that create one: the addition WITH HEADER LINE, the old statement string
DATA: BEGIN OF ... OCCURS, RANGES, SELECT-OPTIONS, and table parameters of function modules and subroutines. Outside
classes, a statement such as APPEND itab. then reads the hidden row, and itab[] names the table itself.
The first pair builds the same two lists the old way and the modern way. The first listing uses a header line and the
OCCURS form, the second a plain table, an explicit type and an inline work area. Both run in the local playground and
print total: 155, legacy lines: 1.
REPORT zobs_hl_old.
TYPES: BEGIN OF ty_item,
item_no TYPE i,
amount TYPE i,
END OF ty_item.
" obsolete: a table with a header line, and the OCCURS form
DATA items TYPE STANDARD TABLE OF ty_item WITH HEADER LINE.
DATA: BEGIN OF legacy OCCURS 0,
item_no TYPE i,
END OF legacy.
DATA total TYPE i.
items-item_no = 1.
items-amount = 120.
APPEND items.
items-item_no = 2.
items-amount = 35.
APPEND items.
legacy-item_no = 7.
APPEND legacy.
LOOP AT items.
total = total + items-amount.
ENDLOOP.
WRITE / |total: { total }, legacy lines: { lines( legacy ) }|.
Source: Keyword Documentation for Standard ABAP: DATA, OCCURS and Internal Tables with a Header Line
REPORT zobs_hl_new.
TYPES: BEGIN OF ty_item,
item_no TYPE i,
amount TYPE i,
END OF ty_item.
DATA items TYPE STANDARD TABLE OF ty_item WITH EMPTY KEY.
DATA legacy TYPE STANDARD TABLE OF i WITH EMPTY KEY.
DATA total TYPE i.
APPEND VALUE #( item_no = 1 amount = 120 ) TO items.
APPEND VALUE #( item_no = 2 amount = 35 ) TO items.
APPEND 7 TO legacy.
LOOP AT items INTO DATA(item).
total = total + item-amount.
ENDLOOP.
WRITE / |total: { total }, legacy lines: { lines( legacy ) }|.
The pitfall of a header line is that two things share one name. The Keyword Documentation shows it with REFRESH: after
REFRESH numbers on a table with a header line, the table body is empty but the header line still holds the last value
that was assigned to it. The following report reads both and prints which of them is still filled. In a real system it
prints that the header line is filled and the table body is not. It requires an SAP system; not run here, because the
local playground does not model the header line and the body as two separate objects.
REPORT zobs_hl2.
DATA numbers TYPE STANDARD TABLE OF i WITH HEADER LINE.
DATA header_set TYPE abap_bool.
DATA body_set TYPE abap_bool.
DO 3 TIMES.
numbers = sy-index.
APPEND numbers.
ENDDO.
REFRESH numbers.
IF numbers IS NOT INITIAL.
header_set = abap_true.
ENDIF.
IF numbers[] IS NOT INITIAL.
body_set = abap_true.
ENDIF.
WRITE / |header line filled: { header_set }, table body filled: { body_set }|.
MOVE, COMPUTE and ADD
MOVE, COMPUTE and ADD were the original statements for assigning and calculating, before the assignment operator
= and the calculation assignments existed. MOVE a TO b does what b = a does. The keyword COMPUTE in front of an
assignment changes nothing, apart from the addition EXACT. ADD 1 TO n is n += 1. The pair below runs both
ways in the playground and prints b: 6 c: 12. The modern listing declares c inline at its first use, which COMPUTE
does not allow.
REPORT zobs_calc_old.
DATA a TYPE i VALUE 5.
DATA b TYPE i.
DATA c TYPE i.
MOVE a TO b.
ADD 1 TO b.
COMPUTE c = b * 2.
WRITE / |b: { b } c: { c }|.
Source: Keyword Documentation for Standard ABAP: MOVE, ADD and COMPUTE
REPORT zobs_calc_new.
DATA a TYPE i VALUE 5.
DATA b TYPE i.
b = a.
b += 1.
DATA(c) = b * 2.
WRITE / |b: { b } c: { c }|.
CALL METHOD
In older programs a method is called with CALL METHOD, a parameter list with EXPORTING and IMPORTING, and a result
caught with RECEIVING. Today a method is called like a function: the parameters go into parentheses, and a method with
a returning parameter can be written wherever a value is expected. The old statement is not removed; the documentation says
it is now meant for dynamic method calls, where the method name comes from a variable. The two listings call the same
static and instance method and print r1: 42 r2: 5 in the local playground.
REPORT zobs_call_old.
CLASS lcl_calc DEFINITION.
PUBLIC SECTION.
CLASS-METHODS double IMPORTING value TYPE i RETURNING VALUE(result) TYPE i.
METHODS add IMPORTING a TYPE i b TYPE i RETURNING VALUE(result) TYPE i.
ENDCLASS.
CLASS lcl_calc IMPLEMENTATION.
METHOD double.
result = value * 2.
ENDMETHOD.
METHOD add.
result = a + b.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA calc TYPE REF TO lcl_calc.
DATA r1 TYPE i.
DATA r2 TYPE i.
CREATE OBJECT calc.
CALL METHOD lcl_calc=>double EXPORTING value = 21 RECEIVING result = r1.
CALL METHOD calc->add EXPORTING a = 2 b = 3 RECEIVING result = r2.
WRITE / |r1: { r1 } r2: { r2 }|.
REPORT zobs_call_new.
CLASS lcl_calc DEFINITION.
PUBLIC SECTION.
CLASS-METHODS double IMPORTING value TYPE i RETURNING VALUE(result) TYPE i.
METHODS add IMPORTING a TYPE i b TYPE i RETURNING VALUE(result) TYPE i.
ENDCLASS.
CLASS lcl_calc IMPLEMENTATION.
METHOD double.
result = value * 2.
ENDMETHOD.
METHOD add.
result = a + b.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(calc) = NEW lcl_calc( ).
DATA(r1) = lcl_calc=>double( 21 ).
DATA(r2) = calc->add( a = 2 b = 3 ).
WRITE / |r1: { r1 } r2: { r2 }|.
RANGES
RANGES declares a table of conditions, the same shape that a selection screen builds, but with a header line. The
modern TYPE RANGE OF gives the same table without it, and VALUE fills a row in one expression. Both listings print
50 in range: X, where X is the value of the true flag.
REPORT zobs_rng_old.
RANGES r_amount FOR sy-index.
DATA hit TYPE abap_bool.
r_amount-sign = 'I'.
r_amount-option = 'BT'.
r_amount-low = 10.
r_amount-high = 100.
APPEND r_amount.
IF 50 IN r_amount.
hit = abap_true.
ENDIF.
WRITE / |50 in range: { hit }|.
REPORT zobs_rng_new.
DATA r_amount TYPE RANGE OF i.
DATA hit TYPE abap_bool.
APPEND VALUE #( sign = 'I' option = 'BT' low = 10 high = 100 ) TO r_amount.
IF 50 IN r_amount.
hit = abap_true.
ENDIF.
WRITE / |50 in range: { hit }|.
TABLES and REFRESH
The statement TABLES zexp_claim creates a structure with the same name as the dictionary table and shares it with every
program of the same program group. The documentation says it is needed only to pass data between a classic dynpro and
the program, and that it is forbidden in classes. The modern way is an ordinary data declaration typed with the table
name. The pair also replaces REFRESH with CLEAR. The lab table ZEXP_CLAIM is a reduced version of the Expense claims
table with the columns claim_id, status and amount, so the listing uses only claim_id. Both listings print
claim: C-1001, ids: 0 in the local playground.
REPORT zobs_tab_old.
TABLES zexp_claim.
DATA ids TYPE STANDARD TABLE OF i WITH EMPTY KEY.
zexp_claim-claim_id = 'C-1001'.
APPEND 1 TO ids.
REFRESH ids.
WRITE / |claim: { zexp_claim-claim_id }, ids: { lines( ids ) }|.
REPORT zobs_tab_new.
DATA claim TYPE zexp_claim.
DATA ids TYPE STANDARD TABLE OF i WITH EMPTY KEY.
claim-claim_id = 'C-1001'.
APPEND 1 TO ids.
CLEAR ids.
WRITE / |claim: { claim-claim_id }, ids: { lines( ids ) }|.
FORM and PERFORM
A subroutine is a block between FORM and ENDFORM that PERFORM calls. It was the way to split a program before ABAP
Objects. The Keyword Documentation gives the reasons not to write new ones: the parameter interface has positional
parameters instead of keyword parameters, no real input parameters in pass by reference, only optional typing and no
optional parameters, and every subroutine belongs implicitly to the public interface of its program. It allows them
only as thin wrappers where a method cannot yet be used, for example with PERFORM ON COMMIT. Both listings add two
items and print total: 155.
REPORT zobs_form_old.
DATA gv_total TYPE i.
START-OF-SELECTION.
PERFORM add_item USING 120.
PERFORM add_item USING 35.
WRITE / |total: { gv_total }|.
FORM add_item USING amount TYPE i.
gv_total = gv_total + amount.
ENDFORM.
REPORT zobs_form_new.
CLASS lcl_totals DEFINITION.
PUBLIC SECTION.
METHODS add_item IMPORTING amount TYPE i.
METHODS total RETURNING VALUE(result) TYPE i.
PRIVATE SECTION.
DATA sum TYPE i.
ENDCLASS.
CLASS lcl_totals IMPLEMENTATION.
METHOD add_item.
sum = sum + amount.
ENDMETHOD.
METHOD total.
result = sum.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(totals) = NEW lcl_totals( ).
totals->add_item( 120 ).
totals->add_item( 35 ).
WRITE / |total: { totals->total( ) }|.
The form PERFORM subr(prog), with the program name in parentheses, is a separate obsolete variant. It calls a subroutine
of another program, and the Keyword Documentation calls external subroutine calls critical, because it cannot normally be
determined statically which program group the called program joins. Use a method or a function module as the explicit
interface of a program, as described in
Modularization Overview.
CATCH SYSTEM-EXCEPTIONS
Before class-based exceptions existed, a runtime error that a program could survive was a catchable runtime error. A
program handled one with CATCH SYSTEM-EXCEPTIONS: the block stops at the first error, the program continues after
ENDCATCH and sy-subrc holds the number that the program assigned. If an error occurs that the list does not name, the
program ends with a short dump. Each catchable runtime error now has an exception class, and TRY with CATCH handles it.
The obsolete listing requires an SAP system; not run here, because the local playground does not support the statement. The
modern listing runs in the playground and prints division failed.
REPORT zobs_sysex_old.
DATA a TYPE i VALUE 10.
DATA b TYPE i VALUE 0.
DATA c TYPE i.
CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 4.
c = a / b.
ENDCATCH.
IF sy-subrc = 4.
WRITE / 'division failed'.
ENDIF.
Source: Keyword Documentation for Standard ABAP: CATCH SYSTEM-EXCEPTIONS and Obsolete Catchable Runtime Errors
REPORT zobs_sysex_new.
DATA a TYPE i VALUE 10.
DATA b TYPE i VALUE 0.
DATA c TYPE i.
TRY.
c = a / b.
CATCH cx_sy_zerodivide.
WRITE / 'division failed'.
ENDTRY.
Class-Based Exceptions explains TRY, CATCH and the exception
categories in full.
ON CHANGE OF and sort criteria by field symbol
Two more structures need a few words and no listing. ON CHANGE OF field runs its block when the field differs from
the value it had the last time the statement ran. The program keeps that value in a hidden helper variable that is global
to the program, and the Keyword Documentation calls the structure particularly prone to errors and says to replace it by
branches with explicitly declared helper variables: declare a variable, compare it in an IF, and assign the new value.
The forms SORT itab BY <fs> and AT <fs> take their column from a field symbol that points into a header line; the
documentation says to use a parenthesized character-like data object holding the component name instead.
Whole concepts that are obsolete
Some obsolete elements are not one statement but a way of building a program.
-
Logical databases. A logical database is a program that reads a tree of tables and hands the rows one by one to a report through an interface work area and the event
GET. The Keyword Documentation says they should no longer be used, because they rely on global data shared across programs, implicit subroutine calls and event control, and that no new logical database should be created. A global class that provides the data as a service replaces them. When you must read an existing one from a method, the function moduleLDB_PROCESScan be called there. -
Extracts.
FIELD-GROUPS,EXTRACTand aSORTorLOOPover the extract dataset keep rows of different structures in one dataset per program. The documentation says internal tables should be used instead. -
Interface work areas. The statement
TABLEScreates a structure shared by the programs of a program group. The documentation says such work areas are error prone and are still useful only for classic dynpros.
Obsolete function modules
Programs also call obsolete function modules, and the language does not mark them. A page of the SAP Support knowledge
base (a knowledge-base page, not product documentation) lists replacements. Among its entries, WS_UPLOAD and UPLOAD
are replaced by GUI_UPLOAD, WS_DOWNLOAD and DOWNLOAD by GUI_DOWNLOAD, each as the function module or as the method of
CL_GUI_FRONTEND_SERVICES, WS_EXECUTE by the method EXECUTE of that class, and POPUP_TO_DECIDE by
POPUP_TO_CONFIRM. The functions GRAPH_DIALOG and GRAPH_SET_CUA_STATUS appear in the same list with no replacement
named. The older business graphics are not covered by a modern pair, and a newcomer who finds a call to a GRAPH_
function module should treat it as a candidate for a rebuild, not a statement to translate. The file transfer pair is
explained with a listing in
Files: Application Server and Front End. All of these
calls require an SAP system; not run here.
Source: SAP Support content: NEW FM in Place of Obsolete FM (a knowledge-base page, not product documentation)
Older material you may meet
The book Complete ABAP (SAP PRESS, 1st edition 2016, covering AS ABAP 7.4 and 7.5) is a broad classic source, and it
shows how much of the day-to-day style changed. It calls methods with CALL METHOD throughout, including the call of a
static method and of the parent class super, whereas today the parenthesized call is the rule and the statement is kept
for dynamic calls. It presents subroutines with FORM and PERFORM as the normal means to reuse code inside a program,
and it shows a ranges table with a header line, whereas new code writes TYPE RANGE OF and uses methods. The book
itself calls a few elements obsolete, among them the TABLES addition of a subroutine, macros and interface work areas.
When you learn from it, read the listings for the idea and write the modern form from the table above. The publisher
page of the current edition is listed in the Bibliography of this section.
Programs written before inline declarations also declare every variable at the top and fill tables row by row with a work area, as described in Internal Tables.
Finding and replacing obsolete code
A few habits make the work safe.
-
Do not rewrite code that works only because it looks old. Replace obsolete statements when you change that part of a program, one statement at a time, and run the tests after each change.
-
A tool finds them for you. The ABAP Test Cockpit reports obsolete statements through its check variants, and the open-source checker abaplint has rules for several of them. See ABAP Test Cockpit (ATC).
-
Moving a program to a class is the usual moment to drop most of them: the syntax check of a class refuses the elements that are forbidden there. The step-by-step method for a whole program is the subject of the page on migrating classic code to ABAP Cloud.
-
Where a statement has no entry in the table, look it up in the Keyword Documentation for Standard ABAP under Obsolete Language Elements, which gives the replacement on the page of each statement.
Summary
-
Obsolete elements still run, but SAP says not to use them in new code, and most of them are forbidden in classes and in ABAP Cloud.
-
A replacement exists for each:
WITH HEADER LINEandOCCURSgive way to explicit tables and work areas,RANGEStoTYPE RANGE OF,TABLESto a typed data object,MOVE,COMPUTEandADDto=and+=,CALL METHODto the parenthesized call,FORMto methods andCATCH SYSTEM-EXCEPTIONStoTRY. -
The playground ran every pair above except the obsolete
CATCH SYSTEM-EXCEPTIONSand the header line pitfall, which need a real system. -
Whole concepts such as logical databases and extracts have no one-line pair: rebuild them with classes and internal tables.
-
Old books show the old forms as normal; read them for the idea and write the modern form.
References
-
Keyword Documentation for Standard ABAP: ABAP - Obsolete Language Elements
-
Keyword Documentation for Standard ABAP: Internal Tables with a Header Line
-
Keyword Documentation for Standard ABAP: CALL METHOD, Static Method Call (Obsolete)
-
Keyword Documentation for Standard ABAP: CATCH SYSTEM-EXCEPTIONS
-
Keyword Documentation for Standard ABAP: Obsolete Catchable Runtime Errors
-
Keyword Documentation for Standard ABAP: Logical Databases (LDB, Obsolete)
-
SAP Support content: NEW FM in Place of Obsolete FM (knowledge-base page)