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

error in simple oops program

Former Member
0 Likes
645

Hi experts,

When executing a simple oops program ..i got the following error. Please correct the code.

"VAR" is not type-compatible with formal parameter "I_DATA".

----


  • CLASS main DEFINITION

----


CLASS main DEFINITION.

PUBLIC SECTION.

"// Instance Methods ( Note we use the statement 'METHODS'

"// to define an instance method )

METHODS set_data IMPORTING i_data TYPE string.

METHODS get_data RETURNING value(r_data) TYPE string.

METHODS print_attribute IMPORTING i_data TYPE string.

"// Instance Methods ( Note we use the statement 'CLASS-METHODS'

"// to define a static method )

CLASS-METHODS set_classdata IMPORTING i_data TYPE string.

CLASS-METHODS get_classdata RETURNING value(r_data) TYPE string.

CLASS-METHODS print_classattribute IMPORTING i_data TYPE string.

PROTECTED SECTION.

"// Instance Attribute ( Note we use the statement 'DATA'

"// to define an instance attribute )

DATA attribute TYPE string.

"// Static Attribute ( Note we use the statement 'CLASS-DATA'

"// to define a static attribute )

CLASS-DATA classattribute TYPE string.

PRIVATE SECTION.

"// Instace event ( Note we use the statement 'EVENTS'

"// to define aN instance event )

EVENTS event EXPORTING value(e_data) TYPE string.

"// Instace event ( Note we use the statement 'CLASS-EVENTS'

"// to define a static event )

CLASS-EVENTS classevent EXPORTING value(e_data) TYPE string.

"// For more informations about events see the following example:

"// ABAP Objects - Creating your First Local Class - Using Events

ENDCLASS. "main DEFINITION

----


  • CLASS main IMPLEMENTATION

----


CLASS main IMPLEMENTATION.

METHOD set_data.

CONCATENATE 'Instance Attribute value' i_data

INTO attribute SEPARATED BY space.

ENDMETHOD. "set_data

METHOD get_data.

MOVE attribute TO r_data.

ENDMETHOD. "get_data

METHOD set_classdata.

CONCATENATE 'Static Attribute value' i_data

INTO classattribute SEPARATED BY space.

ENDMETHOD. "set_classdata

METHOD get_classdata.

MOVE main=>classattribute TO r_data.

ENDMETHOD. "get_classdata

METHOD print_attribute.

WRITE: i_data, /.

ENDMETHOD. "print_attribute

METHOD print_classattribute.

WRITE: i_data, /.

ENDMETHOD. "print_classattribute

ENDCLASS. "main IMPLEMENTATION

DATA: var type char20.

START-OF-SELECTION.

"// Calling a Static method (note we don't have a object )

"// instead we use the <class name>=><method name>.

main=>set_classdata( 'SDN' ).

var = main=>get_classdata( ).

"// Print the var value

main=>print_classattribute( var ).

DATA: object_reference TYPE REF TO main.

CREATE OBJECT object_reference.

"// - Calling a Instance Method( Note we have to use a object to

"// access the insntace components of class main )

"// - Note we're using the statment "CALL METHOD", see looking for

"// functional & General methods for more informations

CALL METHOD object_reference->set_data( 'BPX' ).

var = object_reference->get_data( ).

object_reference->print_attribute( var ).

Thanks in Advance.

Regards

Nani

1 ACCEPTED SOLUTION
Read only

peter_ruiz2
Active Contributor
0 Likes
602

Hi Nani,

try changing your data definition for var from CHAR20 to STRING.

regards,

Peter

2 REPLIES 2
Read only

peter_ruiz2
Active Contributor
0 Likes
603

Hi Nani,

try changing your data definition for var from CHAR20 to STRING.

regards,

Peter

Read only

Former Member
0 Likes
602

DATA : VAR TYPE STRING.

SOLVED.