Skip to Content
author's profile photo
Former Member

Getters & Setters in ABAP?

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!

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Posted on Aug 21, 2007 at 01:26 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 01:30 PM

    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?

    Add comment
    10|10000 characters needed characters exceeded

    • 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