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 code

Former Member
0 Likes
613

hi

i am trying oops in ABAP .can any body correct this code below.

CLASS c_counter DEFINITION.

PUBLIC SECTION.

METHODS: set_counter IMPORTING value(set_value) TYPE i,

increment_counter,

get_counter EXPORTING value(get_value) TYPE i.

data count type i.

ENDCLASS. "C_COUNTER DEFINITION

----


  • CLASS C_COUNTER IMPLEMENTATION

----


*

----


CLASS c_counter IMPLEMENTATION.

METHOD set_counter.

count = 0.

ENDMETHOD. "SET_COUNTER

METHOD increment_counter.

DO 10 TIMES.

count = count + 1.

ENDDO.

ENDMETHOD. "INCREMENT_COUNTER

METHOD get_counter.

WRITE count.

ENDMETHOD. "GET_COUNTER

ENDCLASS. "C_COUNTER IMPLEMENTATION

DATA: obj1 TYPE REF TO c_counter.

call method obj1-> set_counter

importing

set_value = 0.

1 ACCEPTED SOLUTION
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
519

HI,

Problem solved check the code and the comments,

You need to put this code in a report program.

ANd for a report program to start exection you need

START-OF-SELECTION event block.

THen you need to create the object before you can call the method.

SO use CREATE OBJECT.

Then you need to EXPORT not IMPORT parameter, since you will be exporting the data to the method. when you declare the method as IMPORTING data when you call the method you need to use EXPORTING.


CLASS c_counter DEFINITION.
  PUBLIC SECTION.
    METHODS: set_counter IMPORTING value(set_value) TYPE i,
    increment_counter,
    get_counter EXPORTING value(get_value) TYPE i.
    DATA count TYPE i.

ENDCLASS. "C_COUNTER DEFINITION

*----------------------------------------------------------------------*
* CLASS C_COUNTER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c_counter IMPLEMENTATION.

  METHOD set_counter.
    count = 0.
  ENDMETHOD. "SET_COUNTER

  METHOD increment_counter.

    DO 10 TIMES.
      count = count + 1.
    ENDDO.
  ENDMETHOD. "INCREMENT_COUNTER

  METHOD get_counter.
    WRITE count.
  ENDMETHOD. "GET_COUNTER
ENDCLASS. "C_COUNTER IMPLEMENTATION

START-OF-SELECTION. "Need thisevent in report to start execution
 DATA: obj1 TYPE REF TO c_counter.

  CREATE OBJECT obj1." Need to create object

  CALL METHOD obj1->set_counter
    EXPORTING "Need to use Exporting not IMPORTING
      set_value = 0.

Regards,

Sesh

2 REPLIES 2
Read only

Former Member
0 Likes
519

What is the error you are getting ? Please mention it here.

Regards,

Manoj

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
520

HI,

Problem solved check the code and the comments,

You need to put this code in a report program.

ANd for a report program to start exection you need

START-OF-SELECTION event block.

THen you need to create the object before you can call the method.

SO use CREATE OBJECT.

Then you need to EXPORT not IMPORT parameter, since you will be exporting the data to the method. when you declare the method as IMPORTING data when you call the method you need to use EXPORTING.


CLASS c_counter DEFINITION.
  PUBLIC SECTION.
    METHODS: set_counter IMPORTING value(set_value) TYPE i,
    increment_counter,
    get_counter EXPORTING value(get_value) TYPE i.
    DATA count TYPE i.

ENDCLASS. "C_COUNTER DEFINITION

*----------------------------------------------------------------------*
* CLASS C_COUNTER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS c_counter IMPLEMENTATION.

  METHOD set_counter.
    count = 0.
  ENDMETHOD. "SET_COUNTER

  METHOD increment_counter.

    DO 10 TIMES.
      count = count + 1.
    ENDDO.
  ENDMETHOD. "INCREMENT_COUNTER

  METHOD get_counter.
    WRITE count.
  ENDMETHOD. "GET_COUNTER
ENDCLASS. "C_COUNTER IMPLEMENTATION

START-OF-SELECTION. "Need thisevent in report to start execution
 DATA: obj1 TYPE REF TO c_counter.

  CREATE OBJECT obj1." Need to create object

  CALL METHOD obj1->set_counter
    EXPORTING "Need to use Exporting not IMPORTING
      set_value = 0.

Regards,

Sesh