Application Development 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: 

Inline Internal Table Declaration

Former Member
0 Kudos

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

SuhaSaha
Advisor
Advisor

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

SuhaSaha
Advisor
Advisor

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

former_member226519
Active Contributor

for example:

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

split data at ';' into table tab.

raymond_giuseppi
Active Contributor

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

Former Member
0 Kudos

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