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

Re: oops

Former Member
0 Likes
343

Hi all ,

i am new to oops , i want to print the table 5 in the output.

I have written the code under,

I cant understand why it is not executing.

I wil give u fuul points If u modify and make it work.

class sasi definition..

public section.

methods ravi.

data: h type i,

j type i value 1,

res type i.

endclass.

class sasi implementation.

method ravi.

do 10 times.

data h type i.

move 5 to h.

write:/ h , ' * ' , j , '=' , h*j.

enddo.

endmethod.

*

*

*start-of-selection.

*data obj type ref to sasi.

*create object type obj.

*call method obj->ravi.

endclass.

regards

Sashi

1 ACCEPTED SOLUTION
Read only

0 Likes
317

&----


*& Report Z_HOLA_MUNDO *

*& *

&----


*& *

*& *

&----


REPORT z_hola_mundo LINE-SIZE 80.

----


  • CLASS sasi DEFINITION

----


*

----


CLASS sasi DEFINITION..

PUBLIC SECTION.

METHODS ravi.

DATA: h TYPE i,

j TYPE i VALUE 1,

res TYPE i.

ENDCLASS. "sasi DEFINITION

----


  • CLASS sasi IMPLEMENTATION

----


*

----


CLASS sasi IMPLEMENTATION.

METHOD ravi.

DATA: x TYPE i.

DO 10 TIMES.

DATA h TYPE i.

MOVE 5 TO h.

x = h * j.

WRITE:/ h , ' * ' , j , '=' , x.

ENDDO.

ENDMETHOD. "ravi

ENDCLASS. "sasi IMPLEMENTATION

START-OF-SELECTION.

DATA obj TYPE REF TO sasi.

CREATE OBJECT obj.

CALL METHOD obj->ravi.

2 REPLIES 2
Read only

0 Likes
318

&----


*& Report Z_HOLA_MUNDO *

*& *

&----


*& *

*& *

&----


REPORT z_hola_mundo LINE-SIZE 80.

----


  • CLASS sasi DEFINITION

----


*

----


CLASS sasi DEFINITION..

PUBLIC SECTION.

METHODS ravi.

DATA: h TYPE i,

j TYPE i VALUE 1,

res TYPE i.

ENDCLASS. "sasi DEFINITION

----


  • CLASS sasi IMPLEMENTATION

----


*

----


CLASS sasi IMPLEMENTATION.

METHOD ravi.

DATA: x TYPE i.

DO 10 TIMES.

DATA h TYPE i.

MOVE 5 TO h.

x = h * j.

WRITE:/ h , ' * ' , j , '=' , x.

ENDDO.

ENDMETHOD. "ravi

ENDCLASS. "sasi IMPLEMENTATION

START-OF-SELECTION.

DATA obj TYPE REF TO sasi.

CREATE OBJECT obj.

CALL METHOD obj->ravi.

Read only

matt
Active Contributor
0 Likes
317

It's not syntax checking because you the statement <b>write h*j.</b> is not a valid ABAP statement. You need p = h * j. write p.

As the program stands it doesn't do anything. You've just got a local class.

You need to put the "start-of-selection" bit after the ENDCLASS, and even then, the syntax is <b> CREATE OBJECT obj.</b>

Do all of this and you'll have a syntactically correct program, rather like Francisco Javier Carrillo Maldonado's above. But it will only print out<b> 5 * 1 = 5</b> 10 times. Not the five times table.

matt