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: 

How to use VALUE in a method

former_member648393
Discoverer
0 Kudos

Hi,

I'm trying to learn the new 7.4 ABAP syntax for Value and adding new records into an internal table. I have code like:

BEGIN OF ty_data,
           fld1 TYPE CHAR10,
           fld2 TYPE i,
           fld3 TYPE i,
END OF ty_data.
data: it_data type standard table of ty_data.

do 10 times.
  it_data = value #( base it_Data ( fld1 = 'ITERATION'
                                    fld2 = sy-index
                                    fdl3 = 1 ) ).
enddo.

This works. But when I do this in a method and parameterize the internal table as a changing parameter, I get: No component exists with the name "(". "(". error.

  methods example
    changing
      !C_DATA type ty_data.
 methods example
   c_data = value ty_data( base it_Data ( fld1 = 'ITERATION'
                                          fld2 = sy-index
                                          fdl3 = 1 ) ).
 

What am I doing wrong?

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

It's because you declared your parameter as type TY_DATA which is a structure instead of a table type...

4 REPLIES 4

thanga_prakash
Active Contributor
0 Kudos

@Dae Jin Swope I noticed one thing, there is spell mistake in last line it should be fld3 = 1, as in your declaration it is fld3. Also I tried with below similar code and it doesn't give any syntax, you can try like below.

CLASS lcl_local DEFINITION.
  PUBLIC SECTION.
    TYPES:ty_t009 TYPE TABLE OF t009.
    METHODS example
      CHANGING
        c_data TYPE ty_t009.
ENDCLASS.




CLASS lcl_local IMPLEMENTATION.
  METHOD example.
    c_data = VALUE #( BASE c_data ( mandt = '100'
                                    periv = 'Z9' ) ).
  ENDMETHOD.
ENDCLASS.

0 Kudos

Hi Thanga,

Thanks for the quick feedback. Yes, you're right. Those are typos when writing up the sample code. I can try to fix it if I can edit my original post. Using your example, can you try this:

CLASS lcl_local DEFINITION.
  PUBLIC SECTION.

    METHODS example
      CHANGING
        c_data TYPE t009.
ENDCLASS.


CLASS lcl_local IMPLEMENTATION.
  METHOD example.
    c_data = VALUE #( BASE c_data ( mandt = '100'
                                    periv = 'Z9' ) ).
  ENDMETHOD.
ENDCLASS.<br>

Sandra_Rossi
Active Contributor

It's because you declared your parameter as type TY_DATA which is a structure instead of a table type...

0 Kudos

Thanks Sandra! That did the trick.