Skip to Content
0
Former Member
Jan 26, 2009 at 06:56 PM

Question on OOPS concept

26 Views

Hi,

I am trying to learn OOPS. I have tried to develop a CLASS just to add & subtract 2 variables (which will be given as input parameters).. Plz find my code below..

When I try to check syntax for the code, it gives me error "The obligatory parameter 'OP1' had no value assigned to it"... Can anyone plz help..

I might have missed some basic step..

REPORT ZVG_OOPS.

class amount definition deferred.

PARAMETERS: p_op1 LIKE bseg-dmbtr OBLIGATORY,

p_op2 LIKE bseg-dmbtr OBLIGATORY.

DATA: addnsub TYPE REF TO amount.

CLASS amount DEFINITION.

PUBLIC SECTION.

METHODS: constructor IMPORTING op1 TYPE dmbtr

op2 TYPE dmbtr,

add IMPORTING op1 TYPE dmbtr

op2 TYPE dmbtr

EXPORTING result TYPE dmbtr,

subtract IMPORTING op1 TYPE dmbtr

op2 TYPE dmbtr

EXPORTING result TYPE dmbtr.

PRIVATE SECTION.

DATA: result TYPE dmbtr.

ENDCLASS.

CLASS amount IMPLEMENTATION.

METHOD constructor.

IF op1 < op2.

MESSAGE e029(ZR) with text-001 p_op1 p_op2.

ENDIF.

ENDMETHOD.

METHOD add.

me->result = op1 + op2.

ENDMETHOD.

METHOD subtract.

me->result = op1 - op2.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA: r_op TYPE dmbtr.

CREATE OBJECT addnsub.

addnsub-> constructor( EXPORTING op1 = p_op1

op2 = p_op2).

addnsub->add( EXPORTING op1 = p_op1

op2 = p_op2

IMPORTING result = r_op ).

Thanks

Geetha