You are on page 1of 5

3/15/2020 Internal Table Expressions in ABAP 7.

4 Release | SAP FREE Tutorials

Internal Table Expressions in ABAP 7.4 Release


ABAP for HANA

07/02/2016

Hello everyone, in this blog you we are going to learn about Internal Table Expressions in ABAP 7.4
Release. This is second part in series of blog on What’s New in ABAP 7.4 Release.

Please read our rst blog on Inline Declarations for DATA and FIELD-SYMBOL. Lets get started.

Internal Table Expressions


A table expression consists of internal table name, directly followed by square brackets [ ]

READ TABLE
Before ABAP 7.4 we use READ TABLE syntax to read the internal table, but with new release of ABAP 7.4
SAP has introduced table expressions to read the internal table with brand new syntax.

We can read the internal table data with 3 possible ways.You will learn how to use table expressions to
read the internal table which is di erent from old syntax READ TABLE … .

1. READ INDEX – Read the internal table data using the table index

Old Syntax

READ TABLE IT_MARA INTO DATA(WA_MARA) INDEX 1.

New Syntax

DATA(WA_MARA) = IT_MARA[ 1 ].

2. READ USING a FREE KEY – Read the internal table using the free key.

Old Syntax

READ TABLE IT_BOOKINGS INTO WA_BOOKINGS WITH KEY CARRID = 'AA'


CONNID = '17'
CUSTTYPE = 'P'.

New Syntax

DATA(WA_BOOKINGS) = IT_BOOKINGS[ CARRID = 'AA'


CONNID = '17'
CUSTTYPE = 'P' ].

3. READ USING a TABLE KEY – Read the internal table by specifying  table
keys
https://www.saplearners.com/internal-table-expression-in-abap-7-4-release/ 1/5
3/15/2020 Internal Table Expressions in ABAP 7.4 Release | SAP FREE Tutorials

Old Syntax

READ TABLE IT_BOOKINGS INTO WA_BOOKINGS WITH TABLE KEY CARRID = 'AA'
CONNID = '17'.

 New Syntax

DATA(WA_BOOKINGS) = IT_BOOKINGS[ KEY keyid COMPONENTS CARRID = 'AA'


CONNID = '17' ].

APPEND

Before Netweaver 7.4 we use APPEND syntax to append rows to the internal table, but with new
release of Netweaver 7.4 SAP has introduced table expressions to initialize the internal table with brand
new syntax.

Old Syntax

TYPES: BEGIN OF ty_old,


f1 TYPE c,
END OF ty_old.

DATA: wa_old TYPE ty_old,


it_old TYPE STANDARD TABLE OF ty_old WITH EMPTY KEY.

wa_old-f1 = 'A'.
APPEND wa_old TO it_old.

wa_old-f1 = 'B'.
APPEND wa_old TO it_old.

wa_old-f1 = 'C'.
APPEND wa_old TO it_old.

 New Syntax

TYPES: BEGIN OF ty_new,


f1 TYPE c,
END OF ty_new,
tty_new TYPE TABLE OF ty_new WITH EMPTY KEY.

DATA(it_new) = VALUE tty_new( ( f1 = 'A')


( f1 = 'B') ).

MODIFY

https://www.saplearners.com/internal-table-expression-in-abap-7-4-release/ 2/5
3/15/2020 Internal Table Expressions in ABAP 7.4 Release | SAP FREE Tutorials

We use MODIFY statement to modify the contents in internal table. In ABAP Netweaver 7.4 release SAP
has introduced brand new syntax using table expressions. We also use FIELD-SYMBOL to modify the
contents in internal table. We will look at both versions and you will also learn the new ABAP 7.4 new
syntax

Old Syntax

* Modify the contents based on INDEX


READ TABLE IT_BOOKINGS ASSIGNING <FS_BOOKINGS> INDEX 1.
IF sy-subrc = 0.
<FS_BOOKINGS>-CARRID = 'NP'.
ENDIF.

* Modify the contents based on FREE-KEY


READ TABLE IT_BOOKINGS ASSIGNING <FS_BOOKINGS> WITH KEY CARRID = 'AA'
CONNID = '17'.
IF sy-subrc = 0.
<FS_BOOKINGS>-CARRID = 'NP'.
ENDIF.

* Modify the contents based on TABLE-KEY


READ TABLE IT_BOOKINGS ASSIGNING <FS_BOOKINGS> WITH TABLE KEY CARRID = 'AA'
CONNID = '17'.
IF sy-subrc = 0.
<FS_BOOKINGS>-CARRID = 'NP'.
ENDIF.

 New Syntax

*** Using Table Expressions **


* Modify the contents based on INDEX
TRY.
it_bookings[ 1 ]-carrid = 'NP'.
CATCH cx_sy_itab_line_not_found.
ENDTRY.

* Modify the contents based on FREE-KEY


TRY.
it_bookings[ carrid = 'AA' connid = '17' ]-carrid = 'NP'.
CATCH cx_sy_itab_line_not_found.
ENDTRY.

* Modify the contents based on TABLE-KEY


TRY.
it_bookings[ KEY keyid COMPONENTS carrid = 'AA'
connid = '17' ]-carrid = 'NP'.

https://www.saplearners.com/internal-table-expression-in-abap-7-4-release/ 3/5
3/15/2020 Internal Table Expressions in ABAP 7.4 Release | SAP FREE Tutorials

CATCH cx_sy_itab_line_not_found.
ENDTRY.

Functions of Internal Tables

#1. LINE_EXISTS( )
In ABAP 7.4, we have new syntax to check if the record exists in the internal table based on some
conditions. This syntax is short form to READ TABLE with TRANSPORTING NO FIELDS followed by sy-
subrc check. LINE_EXISTS function will return “true” if the row exists and “false” if the row does not
exists.

Old Syntax

READ TABLE it_bookings TRANSPORTING NO FIELDS WITH KEY carrid = 'AA'


connid = '17'.
IF sy-subrc = 0.

.....
ENDIF.

New Syntax

IF line_exists( it_bookings[ carrid = 'AA'


connid = '17'] ).
.....
ENDIF.

#2. LINE_INDEX( )

In ABAP 7.4 release, we have new syntax LINE_INDEX() to identify the index of a row when a condition is
met while reading the internal table. The new syntax is similar to READ TABLE with TRANSPORTING
NO FIELDS followed by sy-subrc check. if sy-subrc = 0, then sy-tabix will give the index of the row.

Old Syntax

READ TABLE it_bookings TRANSPORTING NO FIELDS WITH KEY carrid = 'AA'


connid = '17'.
IF sy-subrc = 0.
WRITE: sy-tabix. "index
ENDIF.

 New Syntax

DATA(indx) = line_index( it_bookings[ carrid = 'AA'


connid = '17'] ).
WRITE: indx.

https://www.saplearners.com/internal-table-expression-in-abap-7-4-release/ 4/5
3/15/2020 Internal Table Expressions in ABAP 7.4 Release | SAP FREE Tutorials

Congrats! You have successfully learned new features in ABAP 7.4 release. Next time when you write
code try using the new syntax and let us know your experience. Please stay tuned for ABAP for
HANA/ABAP 7.4 tutorials. Leave a comment in the below comment section and let us know your
feedback.

Prakash
SAP Fiori Consultant

https://www.saplearners.com/internal-table-expression-in-abap-7-4-release/ 5/5

You might also like