Skip to Content

Hi,

in other development tools like Eclipse it is pretty standard that you are able to generate all GET and SET methods for your classes.

I decided to write a Report program that does the generation of GET and SET methods for you (source code in the Wiki

The report will ask you for class in the Selection Screen. While running it,all attributes are analysed and the Methods are created and activated right away.

The program is new, so I look forward for your hints or improvements.  

Kind Regards Timo John 

Tags: generate, GET, SET, Methods, ABAP, ABAP-OO 

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Edward Pelyavskyy
    There is definitely a need for SET-ers.

    But do we really need GET-ers?

    ABAP Objects has READ-ONLY property of an attribute. This property is not available in other languages therefore they need GET-ers.


    class lcl_test definition.
      public section.
        data lv_name type string READ-ONLY.
        method get_name returning value(rv_name) type string.
    endclass.
    (0) 
      1. Rainer Dörntge
        The reason to implement GET-ters (and, of course, SET-ters) is to make the underlying structure(s) opaque and create a process-based interface for the caller in a way that the underlying data structures can be exchanged without notice. If the main issue here is just to pass through the class attributes, then indeed *those* GET-ters are pointless.

        Rainer

        (0) 
        1. Andreas Profitlich
          Well, good point. You are publishing the data structure of the class variable. But is this a real problem?

          In most cases it should be enough to use more generic types for class variables instead of a special type like CHAR30.

          If we are talking about widely used classes, there maybe a reason to hide the data structure of your class variables. But in most cases the use of GET-ters are imho just bloat.

          (0) 
  2. Thomas Jung
    Of course if you have a Persistent Object then the GET/SET methods are already generated for you.

    Actually in the 7.10 and higher code line (not be confused with 7.0 and its enhancement packages that run under the Business Suite), SAP has added GET/SET generation to the Refactoring capabilities within the class editor. Here are some screen shots:
    http://www.flickr.com/photos/tjung/4520126431/

    This is one of the few features that hasn’t been backported to the 7.0x codeline via Enhancement Packages.

    The question you should ask is do you really want individual SET/GET methods? Often many attributes are accessed together (as the case with a business object). Therefore would it not be more efficient to have a structure with all the related attributes and a single GET/SET. This has more to do with the typical usage of ABAP than any pure langauge construct.

    (0) 
      1. Thomas Jung
        >is accessing READ-ONLY attributes that much faster?
        Short answer – yes although on a scale that might not be noticable. However if begin to mulitple this out by a great many attributes and a large number of object instances (say you are reading data for report) it can add up.  More importantly I was just thinking about coding ergonomics.  If you have 50 attibutes in a business object do you want to have to call 50 GET/SET methods?  As I said, this has more to do with use case than anything technically in the language.
        (0) 
  3. Timo John Post author
    Yes I also see and use the READ-ONLY feature of ABAP objects. So there is a valid point that getters might not be needed.

    GREAT to see that such a feature in the Workbench comes up with the next releases. Personally I am very much looking forward to the NW 7.20 thanks to Thomas and his nice demos on the WD features etc…but working at a customer you are often “suffering” with older versions …

    Thanks for you comments and reply!

    (0) 
  4. Rainer Dörntge
    Hi,

    it seems there is another program missing named “Z_SRCGEN_GET_SET”, since this is what the dump LOAD_PROGRAM_NOT_FOUND states…

    Sorry,
    Rainer

    (0) 
    1. Timo John Post author
      Hello Rainer,
      I checked the source and there were two other programs missing. The code is included now.

      Thanks for reminding me!

      (0) 

Leave a Reply