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: 

Getters & Setters in ABAP?

Former Member
0 Kudos

In C# and in Java we have special functions that operate on private class data called getters and setters. These are almost always public and allow the "outside" to interact safely with the private class data. An example would be :

[C#]

public class Vehicle

{

private string _make;

private string _model;

public string Make { get { return _make; } set { _make = value; } }

public string Model { get { return _model; } set { _model = value; } }

}

[Java]

public class Vehicle

{

private string _make;

private string _model;

public string getMake() { return _make; }

pubic string setMake(string value) { _make = value; }

public string getModel() { return _ model; }

public string setModel(string value) { _model = value; }

}

This allows controlled access to the private data (_make and _model). For instance, I can put rules into the setters that makes sure the data is valid that's coming in from the outside, or in both the setter and getter that checks the user's permissions to see if they have the right to access this data. It's simply a way to implement "encapsulation".

Does ABAP use getters/setters? If so, are they implemented as in Java or does ABAP have its own implementation?

Thanks!

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, ABAP does have setter/getters, these are methods just like in java where you are accessing private or protected attributes of the class. These methods are not special in anyway, other than the method same will begin with SET or GET and as of the last release, the functionality to generate the setter/getter methods is not there, like it is in java.

Regards,

RIch Heilman

PS. I've noticed that on your previous threads, that you have simply mark it as solved on your own without awarding points to the people who have ansered your questions. It is sort of the SDN way of saying thank you, so you might want to consider awarding points for helpful answers. Thanks in advance.

5 REPLIES 5

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, ABAP does have setter/getters, these are methods just like in java where you are accessing private or protected attributes of the class. These methods are not special in anyway, other than the method same will begin with SET or GET and as of the last release, the functionality to generate the setter/getter methods is not there, like it is in java.

Regards,

RIch Heilman

PS. I've noticed that on your previous threads, that you have simply mark it as solved on your own without awarding points to the people who have ansered your questions. It is sort of the SDN way of saying thank you, so you might want to consider awarding points for helpful answers. Thanks in advance.

0 Kudos

If you would like to see some setters/getters, just look at the methods of the class CL_GUI_ALV_GRID in SE24. You will see a bunch that start with SET or GET.

Regards

Rich Heilman

Former Member
0 Kudos

Thanks, you definitely answered my question.

I'm sorry I didn't award points. Is there any way to do it after the fact? Also, I'm not even sure how to do it. Would you give me instructions, please?

0 Kudos

Never mind - I got it! Thanks again.

0 Kudos

No reason to be sorry, I understand that you simply didn't know. Here is the run-down. You can award points to any answers that you find helpful. If one answer in particular has solved your problem, you then mark the radiobutton next to that answer which is blue, this gives the person 10 points. If the answer was very helpful, then select the green star, this is 6 points to the user, and if helpful, mark yellow star for two points. If not helpful at all, then don't mark any. You can also, mark the thread as "Solved on your own". This closes the thread by giving it a blue star, but doesn't give any points to anyone(which is what you have done to the other posts ) It is very good that you have closed the threads, because this gives visibility that your problem was solved or your question is answered. But awarding 10 points to the answer which solved your issue, will also close the thread.

You can go back and revisit your other threads and award points according.

Help this helps, and welcome to SDN.

Regards,

Rich Heilman