Skip to Content
0

Inline Internal Table Declaration

Nov 29, 2016 at 01:35 PM

249

avatar image

Hi all,

I'm looking for any ABAP techniques to do more of an 'inline' (or even in just less lines) of declaring internal tables.

In many languages (javascript, python, etc) we can declare arrays in a single line as such:

pets = ["cat", "dog", "duck", "fish", "turtle"]

And then perhaps go on to work that list in a loop or something similiar.

Is there an equivalent declaration method with abap? Or must I always write (in ABAP):

DATA: gt_pets TYPE TABLE OF string,

gs_pets LIKE LINE OF gt_pets.

gs_pets = 'cat'.

APPEND gs_pets TO gt_pets.

gs_pets = 'dog'.

APPEND gs_pets TO gt_pets.

(and so on)

Even if it's not "standard" ABAP, i'd be very interested in learning about it!

Thanks all!

Chris

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Suhas Saha
Nov 29, 2016 at 01:45 PM
1

Depends on the ABAP version you are using.

Basically if you are using ABAP Version > 740 you should be able to use VALUE to construct internal table values.

See: https://help.sap.com/abapdocu_740/en/abenvalue_constructor_params_itab.htm

Share
10 |10000 characters needed characters left characters exceeded
Volker Binder Nov 29, 2016 at 01:48 PM
1

for example:

data: data type string value 'cat;dog;duck;',
data: tab type table of string.

split data at ';' into table tab.

Share
10 |10000 characters needed characters left characters exceeded
Raymond Giuseppi
Nov 29, 2016 at 02:28 PM
1

In recent versions, try a

TYPES t_itab TYPE TABLE OF string WITH UNIQUE KEY table_line.
DATA(itab) = VALUE t_itab( ( 'cat' ) ( 'dog' ) ( 'duck' ) ( 'fish' ) ( 'turtle' ) ).

Regards,
Raymond

Share
10 |10000 characters needed characters left characters exceeded
Christopher Frewin Nov 30, 2016 at 10:26 AM
0

Thanks all, together your three answers gave me a great overview of all the ways to do this!

Share
10 |10000 characters needed characters left characters exceeded