Application Development and Automation 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: 
Read only

Hi all problem in demo OOPS program

Former Member
0 Likes
519

I have written small abap-oops program but it is giving error that

The line type of "OBJ" must be compatible with one of the types

"<b>OBJ_RECORD</b>".

Plz help me out.

REPORT zkclass1.

----


  • CLASS number1 DEFINITION

----


  • ........ *

----


CLASS number1 DEFINITION.

PUBLIC SECTION.

METHODS : constructor IMPORTING x1 TYPE i

y1 TYPE i.

METHODS : findsum EXPORTING z TYPE i.

PRIVATE SECTION.

DATA : x TYPE i,

y TYPE i.

ENDCLASS.

----


  • CLASS number IMPLEMENTATION

----


  • ........ *

----


CLASS number1 IMPLEMENTATION.

METHOD constructor.

x = x1.

y = y1.

ENDMETHOD.

METHOD findsum.

z = x + y.

WRITE : / z.

ENDMETHOD.

ENDCLASS.

DATA : obj TYPE REF TO number1.

DATA : z1 TYPE i.

PARAMETERS : s_x1 type i obligatory.

PARAMETERS : s_y1 type i obligatory.

START-OF-SELECTION.

CREATE OBJECT obj EXPORTING x1 = s_x1

y1 = s_y1.

CALL METHOD OF OBJ -> FINDSUM EXPORTING x1 = s_x1

y1 = s_y1.

1 ACCEPTED SOLUTION
Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
475

Hi,

Try this way.

*------------------------------------------------------------------*
* CLASS number1 DEFINITION
*------------------------------------------------------------------*
* ........ *
*------------------------------------------------------------------*
CLASS number1 DEFINITION.
  PUBLIC SECTION.
    METHODS : constructor IMPORTING x1 TYPE i
                                    y1 TYPE i.
    METHODS : findsum EXPORTING z TYPE i
                                y1 type i. "Changed
  PRIVATE SECTION.
    DATA : x TYPE i,
    y TYPE i.

ENDCLASS.
*------------------------------------------------------------------*
* CLASS number IMPLEMENTATION
*------------------------------------------------------------------*
* ........ *
*------------------------------------------------------------------*
CLASS number1 IMPLEMENTATION.

  METHOD constructor.
    x = x1.
    y = y1.
  ENDMETHOD.

  METHOD findsum.
    z = x + y.
    y1 = me->y. "Changed
    WRITE : / z.
  ENDMETHOD.

ENDCLASS.

DATA : obj TYPE REF TO number1.
DATA : z1 TYPE i.

PARAMETERS : s_x1 TYPE i OBLIGATORY.
PARAMETERS : s_y1 TYPE i OBLIGATORY.

START-OF-SELECTION.
  CREATE OBJECT obj EXPORTING x1 = s_x1
                              y1 = s_y1.

"Use This way here.
  CALL METHOD obj->findsum IMPORTING z = s_x1
                                     y1 = s_y1.

" Don't use this here.                        
*CALL METHOD OF OBJ -> FINDSUM EXPORTING x1 = s_x1
*y1 = s_y1.                          " 'OF' is used for OLE Objects

Regards.

Marcelo Ramos

3 REPLIES 3
Read only

Former Member
0 Likes
474

CALL METHOD OF OBJ -> FINDSUM EXPORTING x1 = s_x1

y1 = s_y1.

The above method is not called with proper interface parameters. Please check it once.

This method is having one export parameter which should be a IMPORT parameter here.

Message was edited by:

Raghavendra Goutham

Read only

0 Likes
474

How should i defined it ?

I wanna print addition of two no's given by user.

Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
476

Hi,

Try this way.

*------------------------------------------------------------------*
* CLASS number1 DEFINITION
*------------------------------------------------------------------*
* ........ *
*------------------------------------------------------------------*
CLASS number1 DEFINITION.
  PUBLIC SECTION.
    METHODS : constructor IMPORTING x1 TYPE i
                                    y1 TYPE i.
    METHODS : findsum EXPORTING z TYPE i
                                y1 type i. "Changed
  PRIVATE SECTION.
    DATA : x TYPE i,
    y TYPE i.

ENDCLASS.
*------------------------------------------------------------------*
* CLASS number IMPLEMENTATION
*------------------------------------------------------------------*
* ........ *
*------------------------------------------------------------------*
CLASS number1 IMPLEMENTATION.

  METHOD constructor.
    x = x1.
    y = y1.
  ENDMETHOD.

  METHOD findsum.
    z = x + y.
    y1 = me->y. "Changed
    WRITE : / z.
  ENDMETHOD.

ENDCLASS.

DATA : obj TYPE REF TO number1.
DATA : z1 TYPE i.

PARAMETERS : s_x1 TYPE i OBLIGATORY.
PARAMETERS : s_y1 TYPE i OBLIGATORY.

START-OF-SELECTION.
  CREATE OBJECT obj EXPORTING x1 = s_x1
                              y1 = s_y1.

"Use This way here.
  CALL METHOD obj->findsum IMPORTING z = s_x1
                                     y1 = s_y1.

" Don't use this here.                        
*CALL METHOD OF OBJ -> FINDSUM EXPORTING x1 = s_x1
*y1 = s_y1.                          " 'OF' is used for OLE Objects

Regards.

Marcelo Ramos