Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Inline Internal Table Declaration

Former Member
0 Likes
5,871

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

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
2,378

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

4 REPLIES 4
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
2,379

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

Read only

former_member226519
Active Contributor
2,378

for example:

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

split data at ';' into table tab.

Read only

RaymondGiuseppi
Active Contributor
2,378

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

Read only

Former Member
0 Likes
2,378

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