Skip to Content

Inline Internal Table Declaration

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Nov 29, 2016 at 01: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

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 29, 2016 at 01:48 PM

    for example:

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

    split data at ';' into table tab.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 29, 2016 at 02: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

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 30, 2016 at 10:26 AM

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

    Add comment
    10|10000 characters needed characters exceeded