Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
ennowulff
Active Contributor

When programming classes you will have to think of which class attributes might be of concern to the caller (visible to caller) and which are not (private/ protected data).

If you prefer to make attributes PUBLIC you make your life easy. I prefer to declare attributes that might be used by the caller as PUBLIC. I have no trouble with creating GET-Methods and the caller can use any attribute he likes. The advantage of this is, that I as the designer of the class, do not have to think about if an attribute might be valuable for the caller. Especially when using controls and containers I prefer to make them PUBLIC because these classes have a lot of methods that might be used by the caller and I do not want to re-code all possible methods by local access-methods.

The disadvantage is, that the caller has full access to the attributes (as long as you don't set them to read-only). I don't mind.

However. If you like to work with GETTER-Methods in your classes you will have to create a method for each attribute the caller shall have access to.

GET_BUKRS

GET_MATERIAL

GET_TYPE

GET_WHATEVER

A simple and clever alternative is to have all your accessable data in a structure. You will then only have one GET-method and still have access to the elements of the structure.

Define a GET-method as usual with a RETURNING-Parameter

CLASS lcl_demo DEFINITION.

  PUBLIC SECTION.

  METHODS get_t000 RETURNING VALUE(rs_t000) TYPE t000.

ENDCLASS.

You will then have access to each element of the used structure like this:

IF ref->get_t000( )-mwaer = 'EUR'.

2 Comments