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: 

NEW constractor expression

0 Kudos
688

Hi all,

I was wondering what is the defference between the two. In what ways IT_INPUT is different from IT_INPUT1?

TYPES: BEGIN OF ty_input,
        cola TYPE string,
        colb TYPE string,
       END OF ty_input.
DATA: it_input TYPE STANDARD TABLE OF ty_input.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
TYPES: ty_input1 TYPE TABLE OF t100 WITH EMPTY KEY.
DATA:it_input1 TYPE REF TO ty_input1.
it_input1 = NEW #( ).
6 REPLIES 6

FredericGirod
Active Contributor
617

the usage is different :

it_input = value #( ( cola = 'a'   colb = 'b' ) ).
it_input1->* = value #( ( text = 'a' ) ( text = 'b' ) ).

For me the big difference, is, you could modify the "ref to" data in another part of your code (another method even if you set USING).

I don't know why, NEW with data give me pimples

0 Kudos
617

Can you provide an example for what you said please?

For me the big difference, is, you could modify the "ref to" data in another part of your code (another method even if you set USING).

Sandra_Rossi
Active Contributor
617

One is an internal table, one is a reference to an internal table. Are you asking what is a data reference?

FredericGirod
Active Contributor
0 Kudos
617

class my_beautiful_class definition.
public section.
methods my_method_1.
methods my_method_2
importing
o_table type ref to ty_input1.
endclass.

class my_beautiful_class implementation.
method my_method_1.
data it_input1 type ref to ty_input1.
it_input1 = new #( ).
it_input1->* = value #( ( text = 'a' ) ).
my_method_2( it_input1 ).
cl_demo_output=>display_data( it_input1->* ).
endmethod.

method my_method_2.
append value t100( text = 'b' ) to o_table->*.
endmethod.
endclass.


start-of-selection.
data(o_cut) = new my_beautiful_class( ).
o_cut->my_method_1( ).
end-of-selection.

0 Kudos
617

sandra.rossi what do data references bring to the table? Meaning why should I used them instead of internal tables, is there anything to be gained; performance wise?

Also what are the key differences between a data reference and an internal table.

Already did some research but I am hoping a discussion between fellow ABAPers will add more value to my learning experience.

Sandra_Rossi
Active Contributor
617

1. what do data references bring to the table?

Nothing special concerning tables. The question concerns any kind of data type. I continue with the example of internal tables because you are focused on internal tables for some reason. Imagine that you want to refer to the same internal table from two different variables, and that you want any update to replicate automatically. You won't duplicate the internal table, it's easier to have one internal table, and have each variable point to the same internal table through a data reference.

2. Meaning why should I used them instead of internal tables, is there anything to be gained; performance wise?

Performance. Memory. Possibly more simple.

PS: if you don't have a use case, just forget about data references for now...