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: 

Cleaner syntax for filling up internal tables with VALUE?

SuhaSaha
Advisor
Advisor
0 Kudos

Hello SDNers,

Let's consider this scenario.

I have a method fill_table( ) defined as


      fill_table

        IMPORTING it_integer TYPE int4_table

        CHANGING  ct_integer TYPE int4_table.

Implementation is:


  METHOD fill_table.

    ct_integer = VALUE #( BASE ct_integer ( LINES OF it_integer ) ).

    APPEND LINES OF it_integer TO ct_integer. " Looks cleaner compared to VALUE??

  ENDMETHOD.

Imho, the old APPEND/APPEND LINES OF constructs are cleaner than the VALUE. What are your thoughts?

BR,

Suhas

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

As a standalone statement yes. Why not use INSERT LINES OF. But in the moment you can get rid of an unnecessary helper variable, you use VALUE.

meth( VALUE #(  ( LINES OF it_integer ) ) ).


vs.


INSERT LINES OF it_integer INTO TABLE helper.

meth( helper).



And in the moment, you are getting used to it, well ...


7 REPLIES 7

Sandra_Rossi
Active Contributor
0 Kudos

I agree. New constructor operators add a little complexity, so for simple expressions the old constructs should be preferred.

0 Kudos
so for simple expressions the old constructs should be preferred.

Absolutely true!

For complex expressions i prefer using the VALUE operator.

UweFetzer_se38
Active Contributor
0 Kudos

True.

But just a remark: IMHO you should forget the keyword APPEND, always use INSERT.

Reason: you'll never get Dumps for sorted tables anymore. Example

    DATA source TYPE STANDARD TABLE OF i WITH EMPTY KEY.

    DATA target TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line.

    target = VALUE #( ( 5 ) ( 6 ) ( 7 ) ).

    source = VALUE #( ( 3 ) ( 2 ) ( 1 ) ).

    INSERT LINES OF source INTO TABLE target.

    cl_demo_output=>display( target ).

Try this with APPEND

0 Kudos

But just a remark: IMHO you should forget the keyword APPEND, always use INSERT.

Reason: you'll never get Dumps for sorted tables anymore.

Thanks for the tip. The code snippet was for demonstration purposes only

I work with SORTED & HASHED tables whenever possible.

0 Kudos

I know.

It's just because always when I'm seeing APPEND a trigger in my head is pushed and my hair stood on end ...

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

As a standalone statement yes. Why not use INSERT LINES OF. But in the moment you can get rid of an unnecessary helper variable, you use VALUE.

meth( VALUE #(  ( LINES OF it_integer ) ) ).


vs.


INSERT LINES OF it_integer INTO TABLE helper.

meth( helper).



And in the moment, you are getting used to it, well ...


Jelena
Active Contributor
0 Kudos

It does look cleaner and reads like plain English, which is a big plus IMHO.