user11823122
user11823122

Reputation: 99

How to get protected attribute of class in another class

I need to get protected attribute attr_1 of class Class_1 in my own Z-class and use it as an input parameter for my method GET_CAMP_DATA().

Can anybody help me to solve my problem?

I want to do something like this:

DATA(lv_camp_id) = Class_1=>attr_1`.

CALL METHOD GET_CAMP_DATA
EXPORTING
  iv_camp_id            = lv_camp_id
IMPORTING
  et_result             = lt_result

Upvotes: 0

Views: 5032

Answers (1)

Haojie
Haojie

Reputation: 5713

Three options:

1.Implement a method get_attr_1 in Class_1, return attr_1 in this method.

2.Set attr_1 as public and read-only

class Class_1 definition
  public
  final
  create public global friends Z-class.

   public section.
    data attr_1 type your_type read-only.

   protected section.

   private section.

endclass.

3.Define Z-class as a friend of Class_1

class Class_1 definition
  public
  final
  create public global friends Z-class.

   public section.

   protected section.
    data: attr_1 type your_type.

   private section.

endclass.

Upvotes: 1

Related Questions