11-29-2016 1:35 PM
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
11-29-2016 1:45 PM
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
11-29-2016 1:45 PM
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
11-29-2016 1:48 PM
for example:
data: data type string value 'cat;dog;duck;',
data: tab type table of string.
split data at ';' into table tab.
11-29-2016 2:28 PM
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
11-30-2016 10:26 AM
Thanks all, together your three answers gave me a great overview of all the ways to do this!