Skip to Content

Can we define constants based on existing structure?

Seems like a basic ABAP question, but...

I'd like to define a constant based on an existing structure. I was hoping the new ABAP syntax might do it and tried:

types: begin of fullname, 
         firstname type string,
         lastname  type string, 
       end of fullname. 

constants default_name type fullname value #( firstname = `John` 
                                              lastname  = `Doe` ).

But it seems we can't use constructor expressions in declarations.

Background: I'm trying to pre-populate some fields of a structure. Of course I can declare a matching structure explicitly:

constants: begin of default_name, 
             firstname type string value `John`,
             lastname  type string value `Doe`, 
           end of default_name.

But then it must be adapted if the original structure changes.

An alternative is to define components individually:

constants default_firstname type string value `John`.
constants default_lastname  type string value `Doe`.

But that's just clumsy.

So now I'm using a static attribute, but am curious if there's a syntax trick I've missed?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Aug 08, 2017 at 10:03 AM

    The start value val can either be specified as a literal or as a predefined constant.

    No, constructor expressions in declarations are not possible.

    Add comment
    10|10000 characters needed characters exceeded