2017 Aug 08 9:56 AM
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?
2017 Aug 08 11: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.
2017 Aug 08 11: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.
2017 Aug 08 12:07 PM
Thanks, it seems like an odd omission of ABAP that we can't define ddic-structured constants, but it's only a minor inconvenience.