A Walk through on New and Old Abap Syntax


With release 7.40 and 7.50 several new ABAP language elements have been introduced. Learning them in theory is one thing, using them in daily life quite another. While working on that, the idea of an overview sheet came up, comparing “old” and “new” syntax, in the form of: “When i notice things are done in this “old” way, can we use some new elements here?”
This overview is meant to be printable, to have it right on the desk or wall beside you for a quick reference.
And one more thing, i do not mention or care about releases and service packs here. Depending on your system, some or all of the new features will not be available.

Old ABAP New ABAP
DATA and FIELD-SYMBOLS declarationsInline declarations
MOVE CORRESPONDINGConstructor expression CORRESPONDING, or CL_ABAP_CORRESPONDING
struc1-field1 = struc2-fielda
struc1-field2 = struc2-fieldb
CREATE DATA / CREATE OBJECTConstructor expression NEW
GET REFERENCE OFConstructor expression REF
variable only used once, e.g. parameter for a method callConstructor expression VALUEInline declarations
helper variable for type conversionConstructor expression CONV
?=Constructor expression CAST
assigning a value to a single variable within several case or if blocks, e.g. IF cond. var = 1. ELSE. var = 2. ENDIF.
Constructor expressions SWITCH or COND
READ TABLETable expressions; Note: throws exception, while READ TABLE sets sy-subrc. Catch exception and handle error case, or use a standard value
READ TABLE … TRANSPORTING NO FIELDSline_exists( … ) or line_index( … )
internal table WITH DEFAULT KEYsuitable key, or WITH EMPTY KEY
LOOP AT…FOR … IN in constructor expressions
[result of method call] IS (NOT) INITIAL, or [result of method call] = abap_true/abap_falsepredicative method call ( omit the ” = abap_true” part )
DO / WHILEFOR … UNTIL / WHILE in constructor expressions
calculating or otherwise assembling one result from input data, e.g. from table rowsConstructor expression REDUCE; Note: “one result” can be a value, but also a table or complex object
LOOP AT … AT NEW, or other means of going through grouped dataLOOP AT … GROUP BY … / LOOP AT GROUP
LOOP + DELETEConstructor expression FILTER
type checking (?= with TRY/CATCH block, or usage of CL_ABAP_TYPEDESCR)IS INSTANCE OF, CASE TYPE OF
CONCATENATE; string literalsString templates
SELECTnew SQL expressions; use @ to escape host variables

Comments

Popular posts from this blog

ABAP 7.50 – CORRESPONDING

ABAP 7.40 – Inline Declarations