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: 

Source type is not compatible, for purposes of assignment,with target type

Former Member
0 Kudos

Hi Friends,

I have copied a standard class into a Z class.

In my Z class instead of

lr_cucopartner TYPE REF TO cl_crm_ic_cucopartner_impl

I have given

lr_cucopartner TYPE REF TO zcl_crm_ic_cucopartner_impl

Now when I execute it gives me an error

Source type \CLASS=CL_CRM_IC_CUCOPARTNER_IMPL is not compatible, for the purposes of assignment, with target type \CLASS=ZCL_CRM_IC_CUCOPARTNER_IMPL

the error comes at the point

lr_cucopartner ?=

me->get_custom_controller( 'CuCoPartner' ).

What is the problem?

Regards,

Raju

1 ACCEPTED SOLUTION

marcelo_ramos
Active Contributor
0 Kudos

Hi,

This occurs because the method <b>get_custom_controller</b> returning a object typed CL_CRM_IC_CUCOPARTNER_IMPL and not ZCL_CRM_IC_CUCOPARTNER_IMPL.

Make sure that both class is equal.

Regards.

Marcelo Ramos

<b>Forgives me was not my intention post the same as Walter Tighzert, i delayed to save my text, thus, My post can be deleted by moderator !</b>

Message was edited by:

Marcelo Ramos

8 REPLIES 8

Former Member
0 Kudos

Hello,

it seems the method get_custom_controller returns a "cl_crm_ic_cucopartner_impl" and not a "zcl_crm_ic_cucopartner_impl"

Regards,

Walter

marcelo_ramos
Active Contributor
0 Kudos

Hi,

This occurs because the method <b>get_custom_controller</b> returning a object typed CL_CRM_IC_CUCOPARTNER_IMPL and not ZCL_CRM_IC_CUCOPARTNER_IMPL.

Make sure that both class is equal.

Regards.

Marcelo Ramos

<b>Forgives me was not my intention post the same as Walter Tighzert, i delayed to save my text, thus, My post can be deleted by moderator !</b>

Message was edited by:

Marcelo Ramos

0 Kudos

Hi Marcelo & Walter,

Thanks for the reply.

But how to resolve this problem.

The returning parameter of the method get_custom_controller is

TYPE REF TO CL_BSP_WD_CUSTOM_CONTROLLER.

How to work with it?

Regards,

Raju

marcelo_ramos
Active Contributor
0 Kudos

Hi Raju,

I think you could inheriting the class ZCL_CRM_IC_CUCOPARTNER_IMPL from CL_CRM_IC_CUCOPARTNER_IMPL and redefine the methods necessary, Thus, when you run the code above, lr_cucopartner will do what was inherited and redefined in your 'Z' class


"If you inserted new components in your class as Methods, attributes. etc. Use as below:
DATA: lr_cucopartner TYPE REF TO ZCL_CRM_IC_CUCOPARTNER_IMPL.
"But if you only modified some functionality.
DATA: lr_cucopartner TYPE REF TO CL_CRM_IC_CUCOPARTNER_IMPL.

lr_cucopartner ?= me->get_custom_controller( 'CuCoPartner' ).

<b>Check if CL_CRM_IC_CUCOPARTNER_IMPL wasn't defined as FINAL. If was, We must think in other alternative!</b>

Regards.

Marcelo Ramos

0 Kudos

Hi Marcelo

Thanks a lot for the reply.

The class CL_CRM_IC_CUCOPARTNER_IMPL is not final.

I have tried both the ways (copied the class CL_CRM_IC_CUCOPARTNER_IMPL to ZCL_CRM_IC_CUCOPARTNER_IMPL / created new class ZCL_CRM_IC_CUCOPARTNER_IMPL and gave the super class as CL_CRM_IC_CUCOPARTNER_IMPL).

The problem is I have two statements.

<b>1. lr_cucopartner ?= me->get_custom_controller( 'CuCoPartner' ).</b> and

<b>2. CALL METHOD LR_CUCOPARTNER->SET_RESP_TO_ORDER</b>

If I use

DATA: lr_cucopartner TYPE REF TO ZCL_CRM_IC_CUCOPARTNER_IMPL.

then I can make the modifications in the method, but the statement 1 gives me error.

If I use

DATA: lr_cucopartner TYPE REF TO CL_CRM_IC_CUCOPARTNER_IMPL.

then I cant modify the method SET_RESP_TO_ORDER and I have to modify that.

So, how to go with that?

Regards,

Raju

marcelo_ramos
Active Contributor
0 Kudos

Hi Raju,

Look at this example:


" Considers it as CL_CRM_IC_CUCOPARTNER_IMPL
*---------------------------------------------------------------------*
*       CLASS test DEFINITION
*---------------------------------------------------------------------*
CLASS main DEFINITION.

  PUBLIC SECTION.
    METHODS constructor
               IMPORTING i_value TYPE i.

    METHODS get
               EXPORTING e_value TYPE i.

    METHODS add.

    METHODS print
               IMPORTING i_value TYPE i.

  PROTECTED SECTION.

    METHODS: set IMPORTING i_value TYPE i.

    DATA count TYPE i.

ENDCLASS.


*---------------------------------------------------------------------*
*       CLASS main IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS main IMPLEMENTATION.

  METHOD constructor.

    CALL METHOD me->set EXPORTING i_value = i_value.

  ENDMETHOD.

  METHOD set.
    MOVE i_value TO count.
  ENDMETHOD.

  METHOD add.
    ADD 1 TO count.
  ENDMETHOD.

  METHOD get.
    MOVE count TO e_value.
  ENDMETHOD.

  METHOD print.

    WRITE:  / 'Value =',  i_value.

  ENDMETHOD.
ENDCLASS.


" Considers it as ZCL_CRM_IC_CUCOPARTNER_IMPL
*---------------------------------------------------------------------*
*       CLASS second DEFINITION
*---------------------------------------------------------------------*
CLASS second DEFINITION INHERITING FROM main.

  PUBLIC SECTION.
    METHODS constructor
               IMPORTING i_value TYPE i.

"  Here is the method changed
    METHODS add REDEFINITION.

ENDCLASS.


*---------------------------------------------------------------------*
*       CLASS second IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS second IMPLEMENTATION.

  METHOD constructor.

    CALL METHOD super->constructor EXPORTING i_value = i_value.

  ENDMETHOD.

  METHOD add.
    ADD 10 TO count.
  ENDMETHOD.

ENDCLASS.


" Considers it as as class that contain 'me->get_custom_controller'
*---------------------------------------------------------------------*
*       CLASS third DEFINITION
*---------------------------------------------------------------------*
CLASS third DEFINITION.

  PUBLIC SECTION.
"  This method return an object of class 'main'
    METHODS get_obj RETURNING value(obj) TYPE REF TO main.

ENDCLASS.


*---------------------------------------------------------------------*
*       CLASS third IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS third IMPLEMENTATION.

  METHOD get_obj.
"   Try to change this 
*    CREATE OBJECT obj
*           EXPORTING i_value = 10.

"   Try this way
    CREATE OBJECT obj TYPE second
           EXPORTING i_value = 10.

  ENDMETHOD.
ENDCLASS.


DATA v_value TYPE i.
DATA obj_second TYPE REF TO second.
DATA obj_third TYPE REF TO third.

START-OF-SELECTION.

  CREATE OBJECT obj_third.
" Here your object obj_second filled.
  obj_second ?= obj_third->get_obj( ).

  DO 5 TIMES.
"   The method ADD is running with your modifications
    CALL METHOD obj_second->add.
  ENDDO.

" The methods below are being executed as it was implemented in the super class
  CALL METHOD obj_second->get
       IMPORTING e_value = v_value.

  CALL METHOD obj_second->print
       EXPORTING i_value = v_value.

I know that you are trying to make an modification in a standard functionality, and this isn't very simple as in my example, but unfortunately i'm working with SAP 4.6 and i can't run your class here, but i think we can hope for others SDN'ers help <b>with 4.7 or above</b>.

By any way, i'll continue working here to find a solution for this problem !

Regards.

Marcelo Ramos

0 Kudos

Hi Marcelo,

Thanks a lot for your valuable reply...

Iam working in CRM 4.0

Iam really clueless what to do. Can we change

<b>lr_cucopartner ?= me->get_custom_controller( 'CuCoPartner' ).</b> so that it returns the Z class instead of standard class?

Please give your ideas. This is an urgent issue.

Thanks & Regards

Raju

0 Kudos

Hi,

i don't have CRM system.

But:

Is the method get_custom_controller redefineable?

If yes is this the solution:

1)Your Z.. class have to be a subclass of the SAP Class.

2)Your can redefine the method SET_RESP_TO_ORDER and programming your changes there (if needed/necessary you can first or last call super->set_resp_to_order)

3)Now the statement

lr_cucopartner ?= me->get_custom_controller( 'CuCoPartner' )

runs..

Have your already tried this?

Regards,

Gianpietro