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: 

Type conflict during dynamic method call.

Former Member
0 Kudos

While executing the following program I get the error "Type conflict during dynamic method call.":

DATA: container_r  TYPE REF TO object,
      grid_r       TYPE REF TO object,
      itab_saplane TYPE TABLE OF saplane.

* IMPORTANT NOTE: class names must be in UPPER CASE
DATA: str_cnt TYPE seoclsname VALUE 'CL_GUI_CUSTOM_CONTAINER',
      str_gui TYPE seoclsname VALUE 'CL_GUI_ALV_GRID',
      meth_name TYPE STRING VALUE 'SET_TABLE_FOR_FIRST_DISPLAY'.

TYPE-POOLS abap.

DATA: ptab    TYPE abap_parmbind_tab,
      wa_ptab LIKE LINE OF ptab,
      ref     TYPE REF TO data.

CREATE OBJECT container_r TYPE (str_cnt)
  EXPORTING container_name = 'CUSTOM_CONTROL1'. " Name of the custom control area (UC!)

* Construct parameter itab
GET REFERENCE OF container_r INTO ref.
wa_ptab-name  = 'I_PARENT'.  " Must be upper-case
wa_ptab-value = ref.

INSERT wa_ptab INTO TABLE ptab.

*   EXPORTING i_parent = container_r.
CREATE OBJECT grid_r TYPE (str_gui)
  PARAMETER-TABLE ptab.

SELECT * FROM saplane INTO CORRESPONDING FIELDS OF TABLE itab_saplane.

* Cannot call set_table_for_first_display directly...
CALL METHOD grid_r->(meth_name)
  EXPORTING I_STRUCTURE_NAME = 'SAPLANE'  " Type of the rows in the internal table  (UC!)
  CHANGING  IT_OUTTAB = itab_saplane.     " The internal table itself

CALL SCREEN 100.

Any help would be appreciated!

1 ACCEPTED SOLUTION

former_member69765
Contributor
0 Kudos

well it is quiet simple...

The error you are getting is "Type conflict during dynamic method call"

TYPE CONFLICT tells us that there during some method call the type you are passing is not compaitable to what is expected...

Now check you code ..

CREATE OBJECT grid_r TYPE (str_gui)

PARAMETER-TABLE ptab.

Here, you are creating an object of CL_GUI_ALV_GRID. When you create an object, the CONSTRUCTOR method is called..

Since you are making a dynamic call .. you need to populate 3 things .. type (Importing, Ecporting or changeng) etc..

NAme which is I_PARENT and the value .. which should be the reference !!

When you do "GET REFERENCE OF container_r INTO ref." the value of ref is the class name I believe...

You should directly populate the container_r to wa_ptab-value and it should work...

Try this.. meanwhile I will write a code myself to see if it works..

Cheers.

Varun

10 REPLIES 10

former_member69765
Contributor
0 Kudos

Hi..

Not sure why are you complicating it when it could have been very simple !!

Nevertheless ...

Creating a object of Custom container is correct.. no errors here.

Creating an object of ALV GRID.. here .. it should be like this -

CREATE OBJECT grid_r TYPE (str_gui)

i_parent = container_r

I mean its not required that you find the reference, get it into table and pass the table ...

For an simple example refer some controls related example here:

http://www.abaplearning.com/index.php?option=com_content&view=section&id=2&Itemid=14

you will have to register since this section is for members only..

PS: Let us know at which statement you are getting the error ..

Cheers.

Former Member
0 Kudos

Thank you for your reply. Unfortunately I still get the same error if I apply your modifications to my code. If your solution did work for you, can you please post the entire program so I can check where the problem lies?

And to answer your other question: The program is intentionally this complex; its only purpose is to improve my understanding of ABAP Objects. However, the type error resulting from executing the program is very uninformative... So I hope someone can help me pinpoint the problem in the original program (without simplifying it) so I can fix it.

By the way, the above program is based on this more straightforward variant:

DATA: container_r  TYPE REF TO cl_gui_custom_container,
      grid_r       TYPE REF TO cl_gui_alv_grid,
      itab_saplane TYPE TABLE OF saplane.

CREATE OBJECT container_r
  EXPORTING container_name = 'CUSTOM_CONTROL1'. " Name of the custom control area

CREATE OBJECT grid_r
  EXPORTING i_parent = container_r.

SELECT * FROM saplane INTO CORRESPONDING FIELDS OF TABLE itab_saplane.

CALL METHOD grid_r->set_table_for_first_display
  EXPORTING I_STRUCTURE_NAME = 'SAPLANE'  " Type of the rows in the internal table
  CHANGING  IT_OUTTAB = itab_saplane.     " The internal table itself

CALL SCREEN 100.

0 Kudos

Hi..

I solved it ... IT worked for me...

Please see the tutorial and example on the below link:

http://www.abaplearning.com (the tutorial is on the front page... )

The tutorial is for all ...

The code examples is http://www.abaplearning.com/index.php?option=com_content&view=section&id=2&Itemid=14

PS: This is a members only section so you will have to register

Cheers...

former_member69765
Contributor
0 Kudos

well it is quiet simple...

The error you are getting is "Type conflict during dynamic method call"

TYPE CONFLICT tells us that there during some method call the type you are passing is not compaitable to what is expected...

Now check you code ..

CREATE OBJECT grid_r TYPE (str_gui)

PARAMETER-TABLE ptab.

Here, you are creating an object of CL_GUI_ALV_GRID. When you create an object, the CONSTRUCTOR method is called..

Since you are making a dynamic call .. you need to populate 3 things .. type (Importing, Ecporting or changeng) etc..

NAme which is I_PARENT and the value .. which should be the reference !!

When you do "GET REFERENCE OF container_r INTO ref." the value of ref is the class name I believe...

You should directly populate the container_r to wa_ptab-value and it should work...

Try this.. meanwhile I will write a code myself to see if it works..

Cheers.

Varun

0 Kudos

CONSTRUCTOR of CL_GUI_ALV_GRID wants a CL_GUI_CONTAINER as parent and you give her an OBJECT (static type). Without inheritance between OBJECT and CL_GUI_CONTAINER there is no polymorphism or casting, so you'll get a type conflict.

With container_r TYPE REF TO CL_GUI_CONTAINER it works for me, cause container_r now has static type CL_GUI_CONTAINER and dynamic type CL_GUI_CUSTOM_CONTAINER (str_cnt)

regards, Karsten

Former Member
0 Kudos

Thanks for the help (and the explanation as to why my code yielded a type error)!

0 Kudos

By the way...

you code gives type conflict because you missed the type E (for exporting) ..

NOT because of CL_GUI_CONTAINER and CUSTOM_CONTAINER.

What you missed was : "ls_param-kind = 'E'."

If you see my example.. I used the CL_GUI_CUSTOM_CONTAINER only and it works..

Cheers

Former Member
0 Kudos

Thanks for pointing that out. However, if I add

wa_ptab-kind  = 'E'.

to my code without also adding

container_r  TYPE REF TO CL_GUI_CONTAINER,

I still get the same type error.

0 Kudos

Hi ...

Apologies ... for confusion ... actually both are required ...

the type 'E' as well as CL_GUI_CONTAINER.

The below code worked for me ...

check out how I cast it to the parent class type ...

******************************************************************



  DATA : lv_container   TYPE seoclsname VALUE 'CL_GUI_CUSTOM_CONTAINER',
         lv_control     TYPE seoclsname VALUE 'CL_GUI_ALV_GRID',
         lv_method      TYPE string VALUE 'SET_TABLE_FOR_FIRST_DISPLAY',
         lt_par_tab     TYPE abap_parmbind_tab,
         ls_param       LIKE LINE OF lt_par_tab,
         lref_cont      TYPE REF TO cl_gui_container,
         lv_data        TYPE REF TO data.

CREATE OBJECT lref_container
      TYPE
        (lv_container)
      EXPORTING
        container_name = 'ALV_AREA'.

    ls_param-name = 'I_PARENT'.
    ls_param-kind = 'E'.
    lref_cont ?= lref_container.
    GET REFERENCE OF lref_cont INTO lv_data.
    ls_param-value = lv_data.
    INSERT ls_param INTO TABLE lt_par_tab.

**  Now create ALV Control.
    CREATE OBJECT lref_alv_ctrl
      TYPE
        (lv_control)
      PARAMETER-TABLE
        lt_par_tab.

**  Set table for 1st display
    DATA : lv.
    lv = lref_alv_ctrl->mc_fc_print.

    CALL METHOD lref_alv_ctrl->(lv_method)
      EXPORTING
        i_structure_name = 'T001'
      CHANGING
        it_outtab        = lt_company.

Cheers

Edited by: Varun Verma on Aug 12, 2008 4:19 PM

Former Member
0 Kudos

Thanks! It is good to know that the same can also be accomplished using a widening cast.