SAP ABAP New Syntax
SAP ABAP New Syntax
SAP ABAP New Syntax
Sandeshthakre · Follow
Sep 27, 2020 · 6 min read
After version 7.4 in SAP, new syntax where introduced which increases the efficiency
of the code written and also makes it easy for developers, which includes Inline
Declaration, Table Expression, Data Operations.
Here are some of the new syntax which I have come across and found out to be very
useful for working in ABAP and making coding less complex.
1.Inline Declaration:
Before 7.4 New syntaxes were not introduced the variable needs to be declared before
using it, now using inline declaration variable can we declare and use at the same time,
Below are some of the syntax which has changed after 7.4.
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 1/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
Old Syntax.
DATA var1 TYPE char5.
var1 = ‘ABC’.
New Syntax.
DATA(var1) = ‘ABC’.
Old Syntax.
DATA wa TYPE ....
SELECT SINGLE fld1 fld2 FROM ....
INTO wa
WHERE fld1 = var1
AND fld2 = var2.
New Syntax.
SELECT SINGLE fld1, fld2, FROM ....
INTO @DATA(wa)
WHERE fld1 = @var1
AND fld2 = @var2.
Old Syntax.
DATA itab TYPE TABLE OF ....
SELECT fld1 fld2 FROM ....
INTO TABLE itab
WHERE fld1 = var1
AND fld2 = var2.
New Syntax.
SELECT fld1, fld2 FROM ....
INTO TABLE @DATA(itab)
WHERE fld1 = @var1
AND fld2 = @var2.
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 2/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
New Syntax.
LOOP AT itab INTO data(wa).
or
READ TABLE itab into data(wa) WITH KEY field1 = var1.
Old Syntax.
DATA lt_tab LIKE itab.
lt_tab[] = itab[].
New Syntax.
DATA(lt_tab) = itab[].
Old Syntax.
FIELD-SYMBOLS: <line> type …
LOOP AT itab ASSIGNING <line>.
or
READ TABLE itab ASSIGNING <line> WITH KEY FLD1 = VAR1.
New Syntax.
LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).
OR
READ TABLE itab ASSIGNING FIELD-SYMBOL(<line>) WITH KEY FLD1 = VAR1.
2.Table Expression:
In SAP whenever the data is to be taken from Internal Table to any variable in Code for
further processing, Loop or Read Table are generally used to get that data from
Internal Table to work area and then move to another variable, so this effort can be
lessened by using the new syntax.
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 3/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
Old Syntax.
Open in app
READ TABLE itab INTO DATA(wa) WITH KEY fld1 = var1. Get started
New Syntax.
DATA(wa) = itab[ fld1 = var1 ].
Old Syntax.
READ TABLE itab INTO DATA(wa) index 1.
New Syntax.
DATA(wa) = itab[ 1 ].
Old Syntax.
READ TABLE itab INTO wa WITH KEY fld1 = var1.
IF sy-subrc EQ 0.
lv_var2 = wa-var2.
ENDIF.
New Syntax.
lv_var2 = itab[ fld1 = var1 ]-var2.
Old Syntax.
READ TABLE itab TRANSPORTING NO FIELDS WITH KEY fld1 = var1.
IF sy-subrc = 0.
ENDIF.
New Syntax.
IF line_exists( itab[ fld1 = var1 ] ).
ENDIF.
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 4/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
Old Syntax.
READ TABLE itab TRANSPORTING NO FIELDS fld1 = var1.
Open in app Get started
IF sy-subrc eq 0
lv_tabix = sy-tabix.
ENDIF.
New Syntax.
lv_tabix = line_index( itab[ fld1 = var1 ] ).
Old Syntax.
READ TABLE itab ASSIGNING <lfs_tab> fld1 = var1.
IF sy-subrc eq 0
<lfs_tab>-fld2 = 'Text'.
ENDIF.
New Syntax.
itab[ fld1 = var1 ]-fld2 = 'Text'.
Note: While Using these Syntaxes in case of Table Expression use with Try Catch with
cx_sy_itab_line_not_found and Entry.
3.Data Operations:
Here are some of the new Syntax which can be used for manipulating, changing, and
storing data according to requirement.
Old Synatx.
For Removing Leading Zeros
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_OUTPUT’
EXPORTING
input = var1
IMPORTING
OUTPUT = var1 .
For Adding Leading Zeros
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input = var1
IMPORTING
OUTPUT = var1 .
New Syntax.
For Removing Leading Zeros
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 5/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
Old Syntax.
IF cond1.
var1 = fld1.
ELSE.
var1 = fld2.
ENDIF.
New Syntax.
var1 = COND #( WHEN cond1 THEN fld1 ELSE fld2 ).
Case Endcase.
Old Syntax.
CASE var1.
WHEN cond1.
var1 = fld1.
WHEN cond2.
var1 = fld2.
ENDCASE.
New Syntax.
var1 = SWITCH #( var1 WHEN cond1 THEN fld1
WHEN cond2 THEN fld2 ).
Old Syntax.
DATA: itab TYPE TABLE OF structure,
wa TYPE structure.
wa-fld1 = 1.
wa-fld2 = 'A'.
APPEND wa TO itab.
CLEAR WA.
wa-fld1 = 2.
wa-fld2 = 'B'.
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 6/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
APPEND wa TO itab.
CLEAR WA. Open in app Get started
New Syntax.
DATA(itab) = VALUE structure(( fld1 = 1 fld2 = 'A' )
( fld1 = 2 fld2 = 'B' )).
Old Syntax.
DATA: itab TYPE TABLE OF structure,
wa TYPE structure.
wa-fld1 = 1.
wa-fld2 = 'A'.
APPEND wa TO itab.
CLEAR WA.
wa-fld1 = 2.
wa-fld2 = 'B'.
APPEND wa TO itab.
CLEAR WA.
New Syntax.
itab = VALUE #( BASE itab
( fld1 = 1 fld2 = 'A' )
( fld1 = 2 fld2 = 'B' ) ).
Concatenate for data type apart from C, N, D, T, or STRING. Before 7.4 use to get
Syntax Error saying this, but with new Syntax, it’s possible for any Data Type.
Old Syntax.
CONCATENATE 'The Value in inr is' var1 into fld1.
New Syntax.
fld1 = |The Value in inr is { var1 }|.
Old Syntax.
MOVE-CORRESPONDING itab1 to itab2.
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 7/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
New Syntax.
itab2 = CORRESPONDING #( itab1 ). Open in app Get started
Using Above Syntax only fields which are identical in the container will be moved to
move it to other fields this new syntax can be used.
If some fields need to excluded while moving corresponding fields, this syntax can be
used.
*--Defining Structure
TYPES: BEGIN OF gty_s_rseg_key,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
END OF gty_s_rseg,
gty_rseg TYPE STANDARD TABLE OF gty_s_rseg WITH EMPTY KEY.
Old Syntax.
DATA: lt_awkey TYPE gty_rseg,
lw_awkey TYPE gty_s_rseg.
New Syntax.
DATA(lt_awkey) = VALUE gty_rseg( FOR <lfs_bkpf> IN lt_bkpf
( belnr = <lfs_bkpf>-awkey+0(10)
gjahr = <lfs_bkpf>-awkey+10(4) ) ).
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 8/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
Old Syntax.
DATA lv_name TYPE sy-ucomm. Open in app Get started
DATA lv_output TYPE char20.
CONCATENATE 'The User ID is' lv_name INTO lv_output SEPARATED BY
space.
MESSAGE lv_output TYPE 'E' DISPLAY LIKE 'E'.
New Syntax.
MESSAGE |The User ID is { lv_name }| TYPE 'E' DISPLAY LIKE 'E'.
Object-Oriented.
Old Syntax.
DATA: binary_content TYPE solix_tab.
DATA: xl_content TYPE xstring .
New Syntax.
binary_content = cl_bcs_convert=>xstring_to_solix( ip_xstring =
xl_content ).
Old Syntax.
DATA oref TYPE REF TO class.
CREATE OBJECT oref EXPORTING …
New Syntax.
DATA oref TYPE REF TO class.
oref = NEW #( … ).
or
with an inline declaration
DATA(oref) = NEW class( … )
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 9/10
2/12/22, 8:47 AM SAP ABAP New Syntax. After version 7.4 in SAP, new syntax… | by Sandeshthakre | Medium
https://sandesh19thakre.medium.com/sap-abap-new-syntax-d5ea9143bccd 10/10