2013 May 16 11:33 AM
Dear experts,
Kindly guide me how to call an instance method inside a other class method.
i am already using the static method from same class. Pls refer the code
CALL METHOD /sapsrm/cl_pdo_msg=>/sapsrm/if_pdo_msg_provider~add_message_static
EXPORTING
it_messages = lt_messages_tend
CHANGING
co_message_handler = co_message_handler.
In the above code /sapsrm/if_pdo_msg_provider is the class where add_message_static is a static method.
But i want to call method DELETE_ALL_MESSAGES which is an instance method in same class /sapsrm/if_pdo_msg_provider.
Kindly guide me how to call the instance method of the class.
Thank & Regards
Arun.K.P
2013 May 16 12:57 PM
Hi Arun,
You should first create or get an instance in order to access the instance method.
Do you have get_instance( ) method for the class /sapsrm/if_pdo_msg_provider?
If so then do the following:
DATA:
lr_msg_provider TYPE REF TO /sapsrm/if_pdo_msg_provider.
lr_msg_provider = /sapsrm/if_pdo_msg_provider=>get_instance( ).
If there is no get_instance method, the do the following:
CREATE DATA lr_msg_provider.
IF lr_msg_provider IS BOUND.
CALL METHOD lr_msg_provider->delete_all_messages( ).
ENDIF.
The get instance method will create an instance if the instance in not created before, it the instance is created then it return the existing instance, so that the data can be preserved, you wont be having different set of data's.
Dear experts,
Kindly guide me how to call an instance method inside a other class method.
i am already using the static method from same class. Pls refer the code
CALL METHOD /sapsrm/cl_pdo_msg=>/sapsrm/if_pdo_msg_provider~add_message_static
EXPORTING
it_messages = lt_messages_tend
CHANGING
co_message_handler = co_message_handler.
In the above code /sapsrm/if_pdo_msg_provider is the class where add_message_static is a static method.
But i want to call method DELETE_ALL_MESSAGES which is an instance method in same class /sapsrm/if_pdo_msg_provider.
Kindly guide me how to call the instance method of the class.
Thank & Regards
Arun.K.P
2013 May 16 11:48 AM
Hello,
To call an instance method of a class you have to create an object of that class. In your case it is /sapsrm/if_pdo_msg_provider .
2013 May 16 12:04 PM
I don 't have the class /sapsrm/if_pdo_msg_provider in my SAP system, but basically you need either to instantiate an object by creating a variable reference to the class and instantiate it by calling the create method.
Or, the class probably has a static method get_reference_by_handler or something similar e.g. get_instance, since you are receiving back a handle (a reference) to the class instance.
Use that one to get a refernce to the instance and call the method
Example
Data: gr_msg_provider type ref to /sapsrm/if_pdo_msg_provider.
gr_msg_provider = call mehod /sapsrm/if_pdo_msg_provider=>get_reference.
CALL METHOD gr_msg_provider->DELETE_ALL_MESSAGES
2013 May 16 12:57 PM
Hi Arun,
You should first create or get an instance in order to access the instance method.
Do you have get_instance( ) method for the class /sapsrm/if_pdo_msg_provider?
If so then do the following:
DATA:
lr_msg_provider TYPE REF TO /sapsrm/if_pdo_msg_provider.
lr_msg_provider = /sapsrm/if_pdo_msg_provider=>get_instance( ).
If there is no get_instance method, the do the following:
CREATE DATA lr_msg_provider.
IF lr_msg_provider IS BOUND.
CALL METHOD lr_msg_provider->delete_all_messages( ).
ENDIF.
The get instance method will create an instance if the instance in not created before, it the instance is created then it return the existing instance, so that the data can be preserved, you wont be having different set of data's.
2013 May 16 1:08 PM
Hi Peter and Satish,
Thank you for the responses. I tried both the solutions but i am getting same error
"/SAPSRM/IF_PDO_MSG_PROVIDER=>GET_INSTANCE(", a field, a function or "(" expected.
Could you please guide me..
Thanks & Regards
Arun.K.P
2013 May 16 1:12 PM
Hi,
Check the get_instance method if it expects any input value.
Cheers,
Arindam
2013 May 16 1:17 PM
Hi,
I think get_instance( ) method is taking some importing parameters, check the get_instance( ) method and pass the proper values for getting the instance.
2013 May 16 1:20 PM
Use the pattern function to create the call to the method. Then you know which parameters you need to supply
2013 May 16 1:35 PM
Hi Satish and Arindam,
I checked that i dont have any instance_method here.. pls correct me if i am wrong and i dont have any parameters.
Thanks & Regards
Arun.K.P
2013 May 16 1:43 PM
Hi,
Then you should create an reference manually.
DATA:
lr_msg_provider TYPE REF TO /sapsrm/if_pdo_msg_provider.
CREATE DATA lr_msg_provider.
IF lr_msg_provider IS BOUND.
CALL METHOD lr_msg_provider->delete_all_messages( ).
ENDIF.
Any can you explain your business scenario so that we can understand you proper requirement.
2013 May 16 1:43 PM
Hi,
Check the class in SE24. I dont have system access now you must be having constructor then CREATE OBJECT should create an instance of the class. Also a quick way would be to do a where used list of the class and check its usage in system.
Cheers,
Arindam
2013 May 16 2:11 PM
Dear Satish,
I done what you have suggested but i am getting
Only types of the form "REF TO value_type" are permitted in "CREATE DATA".
2013 May 16 5:10 PM
Hi,
Try with this code:
DATA:
lr_msg_provider TYPE REF TO /sapsrm/if_pdo_msg_provider.
CREATE OBJECT lr_msg_provider.
IF lr_msg_provider IS BOUND.
CALL METHOD lr_msg_provider->delete_all_messages( ).
ENDIF.
If you dont know the parameters then, use "Pattern", select ABAP Objects Pattern,
Provide the following information:
Instance: lr_msg_provider
Class/Interface: /sapsrm/if_pdo_msg_provider
Method: Constructor
2013 May 17 7:50 AM
Hi Satish,
I am able to call the instance method using
data: lr_msg_provider type ref to /sapsrm/if_pdo_msg_provider.
CALL METHOD lr_msg_provider->DELETE_ALL_MESSAGES.
Thank you for your guidance.
Thanks & Regards
Arun.K.P
2013 May 16 1:03 PM
Hi,
For using instance methods you must instantiate the class. Its not readily available as static methods. Do a CREATE OBJECT or TYPE REF TO and create a instance. Check the link below
http://help.sap.com/saphelp_nw70/helpdata/en/c3/225b5f54f411d194a60000e8353423/content.htm
Cheers,
Arindam
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |