Skip to Content

[ABAP] Returning const reference to an object aka completely read-only objects?

I'm coming from C++ and there we can create methods, which return a so called const reference.
This means, the caller can not modify the returned value/object (lets put const_cast and pointer magic away for a moment). For example if a method returns a const reference to an object, the caller can not call methods on that returned object, which would modify the object itself, but he is allowed to call methods, which do not modify the object e.g. getter methods are fine, setter methods are permitted.

Today I found out that ABAP has Read-Only for attributes. But for example if we have an object as a Read-only attribute, you can still call methods, which would modify the object.

Is there a way in ABAP to return a read-only object (reference to that object), which allows only to call methods, which wont modify the object?

Here is a short C++ example which demonstrates what I mean and essentially what I would like to implement in ABAP, if possible:

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

0 Answers

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.