cancel
Showing results for 
Search instead for 
Did you mean: 

No CALL METHOD syntax used in Dynpro programming

Former Member
0 Kudos

Hi Gurus,

I have just starded with Web Dynpro ABAP. I found that while writing code we don't use CALL METHOD .

i.eTABLE_NODE = WD_CONTEXT->GET_CHILD_NODE('MY_TABLE_NODE').

How can we directly call a method using interface variable e.g WD_CONTEXT without syntax CALL METHOD?

Can anyone explain?

I am not much familiar with OOPs.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

mohammed_anzys
Contributor
0 Kudos

Hi

let me add some more clarification .

A be an interface , having three method definitions.

B is a class which implements A ( So B will be having implementation of 3 methods of A as well as some additional methods of B , let it 2 ). so B will be having total five method implementation.

So when create an instance of B and assign that to a variable of A , only the 3 methods will be copied .

You could go to the thread for more info.

And you can't directly call from a variable of the interface unless an object is assigned to it.

Thanks

Anzy

Please awrd points if this solves your problem

Message was edited by:

Mohammed Anzy S

Former Member
0 Kudos

Hi Anzy,

Can u correct this program to let me understand this concept. ( An example ABAP OOPs program)

REPORT zjt_test_interface.

INCLUDE zjt_test_interfac_class.

DATA : dd TYPE REF TO demo ,

inter TYPE REF TO sample,

inter1 TYPE REF TO sample.

START-OF-SELECTION.

CREATE OBJECT dd .

inter = dd.

call method inter->test. ******No error with this statement

  • inter1 = inter->test. *********** This statement gives error "Field 'Test' unknown

The below code is a separate include program.

&----


*& Include ZJT_TEST_INTERFAC_CLASS

&----


INTERFACE sample .

METHODS test .

ENDINTERFACE. "sample

----


  • CLASS demo DEFINITION

----


*

----


CLASS demo DEFINITION.

PUBLIC SECTION.

INTERFACES sample .

METHODS : constructor.

ENDCLASS. "demo DEFINITION

----


  • CLASS demo IMPLEMENTATION

----


*

----


CLASS demo IMPLEMENTATION.

METHOD constructor.

ENDMETHOD. "constructor

METHOD sample~test.

WRITE : 'Method test of Interface sample executed'.

ENDMETHOD. "sample~test

mohammed_anzys
Contributor
0 Kudos

Hi Shinu,

i have gone through the program and there is nothing exceptional .

inter and inter1 are of type SAMPLE ( interface ) and it has a method test.

In DEMO class , it implements the interface SAMPLE.

when create object dd ( where dd is of the type DEMO )

so automatically it will be having the method Test from the interface SAMPLE , and implementation of the method ,depends on the implementation DEMO class..

call method inter->test. ******No error with this statement

This statement is correct , as the inter is of type SAMPLE and can hold DD ( simce it implements SAMPLE) . so the TEST method will be available there.

  • inter1 = inter->test. *********** This statement gives error "Field 'Test' unknown

But in this scenario , the system expects test as an attribute and the assignment is wrong.

Thanks and reagrds

Anzy

Awrd points if this solves your doubt

Former Member
0 Kudos

Hi Shinu,

This is with reference to your code - the line in which you are getting the error.

In general, when we use the assignment operator ( = ), the data type on either side should be the same or compatible types. In your case, the following things have to be noted:

1. The method 'test' does not return any data. It simply writes some text.

2. The mode of assignment is not correct. As mentioned earlier, the types on either side of the assignment operation are incompatible.

You can try the following, however, if that is your need. If you want to call the method '

test

' from the interface object '

inter1

', then do it as follows:

inter1 = inter.

call method inter1->test.

Further, whenever you are calling a method of an interface or a class, it is always better to use the 'CALL

METHOD cls_name->meth_name

' syntax. Though the '

call method

' part is optional, it is considered a good programming convention and the code also looks more professional.

Hope this helps you. Please post back in case you have further queries.

Regards,

Ram

Answers (1)

Answers (1)

mohammed_anzys
Contributor
0 Kudos

Hi

The interface will be holding an instance of the implementaion class of the IF_WD_CONTEXT_NODE...so we can directly call that method...without using the call method...

Thanks

Anzy