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

class method

Former Member
0 Likes
679

Hi,

I created code like this:

CLASS item DEFINITION.

PUBLIC SECTION.

METHODS:

constructor IMPORTING matnr type matnr

sstuf type sstuf,

write_result.

PROTECTED SECTION.

DATA: matnr type matnr,

maktx type maktx.

METHODS: get_maktx,

get_stuff.

endclass.

class item implementation.

method constructor.

data: obiekt type ref to item.

me->matnr = matnr.

"me->sstuf = sstuf.

call method: get_maktx, get_stuff.

call method obiekt->write_result.

method get_maktx.

select single maktx from mara into maktx where matnr = 'A103'.

ENDMETHOD.

method get_stuff.

select single stuff from mara into stuff where matnr = 'A103'.

endmethod.

method write_result.

write: maktx, stuff.

uline.

endmethod.

endclass.

After F8 i get info that: "statement endmethod missing".

What should i change in code?

Regards,

Joanna

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
608

Well, your first problem is that you are missing the ENDMETHOD for your CONSTRUCTOR method, but you will have other problems as well.



class item implementation.
method constructor.
data: obiekt type ref to item.

me->matnr = matnr.
"me->sstuf = sstuf.

call method: get_maktx, get_stuff.
call method obiekt->write_result.

ENDMETHOD      .    " <------ RIGHT HERE

method get_maktx. 
select single maktx from mara into maktx where matnr = 'A103'.
ENDMETHOD.

REgards,

RIch HEilman

4 REPLIES 4
Read only

Former Member
0 Likes
608

Hi,

So is this a FORM or a method. You open with FORM, but close with END METHOD and END CLASS.

If it is a FORM, then end with an ENDFORM. If it is a method, then you must begin with a METHOD statement.

Refre the link:

https://forums.sdn.sap.com/click.jspa?searchID=3880163&messageID=3220888

<b>Reward points</b>

Regards

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
609

Well, your first problem is that you are missing the ENDMETHOD for your CONSTRUCTOR method, but you will have other problems as well.



class item implementation.
method constructor.
data: obiekt type ref to item.

me->matnr = matnr.
"me->sstuf = sstuf.

call method: get_maktx, get_stuff.
call method obiekt->write_result.

ENDMETHOD      .    " <------ RIGHT HERE

method get_maktx. 
select single maktx from mara into maktx where matnr = 'A103'.
ENDMETHOD.

REgards,

RIch HEilman

Read only

0 Likes
608

This modified example, may help you further.



report zrich_0001 .

*---------------------------------------------------------------------*
*       CLASS item DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class item definition.
  public section.

    methods:
    constructor importing matnr type matnr,
    write_result.

  protected section.
    data: matnr type matnr,
          maktx type maktx,
          groes type groes.
    methods: get_maktx,
             get_groes.
endclass.

*---------------------------------------------------------------------*
*       CLASS item IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class item implementation.
  method constructor.
    me->matnr = matnr.
    call method: get_maktx, get_groes.
    call method me->write_result.
  endmethod.

  method get_maktx.
    select single maktx
             from makt into me->maktx
                      where matnr = me->matnr.
  endmethod.

  method get_groes.
    select single groes from mara into groes
                 where matnr = me->matnr.
  endmethod.

  method write_result.
    write:/ me->matnr, me->maktx, me->groes.
    uline.
  endmethod.
endclass.


data: o_ref type ref to item.

start-of-selection.

  create object o_ref
         exporting
              matnr = 'A103'.

Regards,

RIch Heilman

Read only

0 Likes
608

Rich!

Thaks u so much.

Regards,

Joanna