Application Development 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: 

How to call a method

Former Member
0 Kudos

Hello Every1,

I have created a implementaion for some definition.

Now I need to call a method from the implemenation in my program. Let me know how to call it?

Regards,

Siva.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

1. Create the instance of the class.

CREATE OBJECT C1. (If there are any parameters to the constructor of the method you will have to pass here.

2. Now call the method

CALL METHOD C1-->METHOD1. (Pass the parameters).

You can do this using the pattern of the ABAP Editor also.

If its a static class, you can directly call the method without instantiating the class

Regards,

Ravi

note : Please mark the helpful answers

Message was edited by: Ravikumar Allampallam

6 REPLIES 6

Former Member
0 Kudos

1. Create the instance of the class.

CREATE OBJECT C1. (If there are any parameters to the constructor of the method you will have to pass here.

2. Now call the method

CALL METHOD C1-->METHOD1. (Pass the parameters).

You can do this using the pattern of the ABAP Editor also.

If its a static class, you can directly call the method without instantiating the class

Regards,

Ravi

note : Please mark the helpful answers

Message was edited by: Ravikumar Allampallam

Former Member
0 Kudos

Hi,

You need to create a instance of the class and call the method using the syntax CALL METHOD instance_name->method_name if the method is an instance method.

For static methods you need to use the syntax CALL METHOD class_name=>method_name

-Kiran

Former Member
0 Kudos

Hi sivaprakash pandian ,

If u want to call the method of same class in the mplementation of another method,just u need to use CALL METHOD METHOD_NAME, other wise if u want to call the method of other class, u have create the object of that class and with that obj, uneed to call the method,

i.e,

CREATE OBJECT OBJ.

CALL METHOD OBJ->METH1.

Regards,

kiran B

Former Member
0 Kudos

Hi Siva,

Check the ABAPDOCU transaction. And go through this program....

REPORT demo_class_counter .

CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: set IMPORTING value(set_value) TYPE i,

increment,

get EXPORTING value(get_value) TYPE i.

PRIVATE SECTION.

DATA count TYPE i.

ENDCLASS.

CLASS counter IMPLEMENTATION.

METHOD set.

count = set_value.

ENDMETHOD.

METHOD increment.

ADD 1 TO count.

ENDMETHOD.

METHOD get.

get_value = count.

ENDMETHOD.

ENDCLASS.

DATA number TYPE i VALUE 5.

DATA cnt TYPE REF TO counter.

START-OF-SELECTION.

CREATE OBJECT cnt.

CALL METHOD cnt->set EXPORTING set_value = number.

DO 3 TIMES.

CALL METHOD cnt->increment.

ENDDO.

CALL METHOD cnt->get IMPORTING get_value = number.

WRITE number.

Hope it helps u in some way.

Former Member
0 Kudos

Hai

Go through the following Code

&----


*& Report ZABAPOBJECTS_01 *

*& *

&----


*& *

*& *

&----


report ZABAPOBJECTS_01 .

parameter : p_matnr like mara-matnr.

----


  • CLASS lcl_material DEFINITION

----


*

----


class lcl_material definition.

public section.

data: v_matnr type mara-matnr.

methods : constructor importing matnr type mara-matnr,

get_material_description.

private section.

data : v_maktx type makt-maktx.

endclass. "lcl_material DEFINITION

----


  • CLASS lcl_material IMPLEMENTATION

----


*

----


class lcl_material implementation.

method get_material_description.

clear v_maktx.

select single maktx into v_maktx

from makt

where matnr = v_matnr and

spras = 'E'.

endmethod. "get_material_description

method constructor.

clear v_matnr.

v_matnr = matnr.

endmethod. "constructor

endclass. "lcl_material IMPLEMENTATION

data : obj type ref to lcl_material.

start-of-selection.

create object obj exporting matnr = p_matnr.

call method obj->get_material_description.

Thanks & regards

Sreenivasulu P

Former Member
0 Kudos

data: c1 TYPE REF TO object.

CREATE OBJECT c1 TYPE class.

create method c1 type method