Application Development and Automation 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: 
Read only

SAP Class protected method calling error in zcustom program

Former Member
0 Likes
1,974

Hi All,

I am trying to call a protected method from sap given class, and I am getting the below error , please help.

"method active_infotypes is unknown or protected or private."

Here is the code where i am trying to access the method from the sap standard class (method was defined as protected..)

CALL METHOD cl_hrecm00_status_change_appl=>activate_infotypes

         EXPORTING

           iv_orgunit         = iv_orgunit

           iv_test_mode       = iv_test_mode

           iv_note            = iv_note

           io_message_handler = io_message_handler

         IMPORTING

           ev_is_ok           = ev_is_ok.

Thanks

Krishna

9 REPLIES 9
Read only

Former Member
0 Likes
1,737

You cannot call a protected method of a class from outside.

It can only be called in the class methods or in its subclasses.

Read only

0 Likes
1,737

I am trying to make use of some of the standard sap class methods which are protected, so in that case it is not possible to reuse sap given methods in my program...

Thanks

Krishna

Read only

Former Member
0 Likes
1,737

As you know concept of OOPS..

Public Section

All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.

Protected Section

All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.

Private Section

Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.

So if you want to use it outside of class then make it public.

Read only

0 Likes
1,737

Hi Chandra,

****All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it.

As per this statement, if I inherit sap standard class can I access methods from protected class? Also we are on ECC6 EHP5.

Thanks

Krishna


Read only

0 Likes
1,737

If you inherit any class , then you can access its protected property in the sub class. This is OOPS concept.

Super class..

private Section.

Method1

Protected section:

Method2.

Sub class inherited form Super class..

Now Method2 will be accessible into it...

****Its a just simple English text. Not a code..

Read only

0 Likes
1,737

I am trying as below to access the sap given standard class method, still not able to access , please suggest what I am doing wrong:

form perform_action

* Create a reference type for the class:

  DATA: obj_cl_hrecm00 TYPE REF TO cl_hrecm00_status_change_appl.

*Create object for the referenced class

  CREATE object obj_cl_hrecm00.

* Call method with object reference:

   CALL METHOD obj_cl_hrecm00=>activate_infotypes

        EXPORTING

          iv_orgunit         = iv_orgunit

          iv_test_mode       = iv_test_mode

          iv_note            = iv_note

          io_message_handler = io_message_handler

        IMPORTING

          ev_is_ok           = ev_is_ok.

endform.

Please advice what I am missing.

Thanks

Krishna

Read only

0 Likes
1,737

This message was moderated.

Read only

0 Likes
1,737

create a new class with CL_HRECM00_STATUS_CHANGE_APPL as superclass. it is not final. you will be able to call protected methods.

Read only

0 Likes
1,737

And btw, ACTIVATE_INFOTYPES is instnace method not static. So you call it like -> not like =>