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

abap objects

Former Member
0 Likes
454

hi all

i tryin to create a report using object orianted approch, i created a class and tryin to display details of material using this class.

but not able to do it, can anyone tell me how shuld approch, abap objects are new concept for me.

regards

sunanda

2 REPLIES 2
Read only

Former Member
0 Likes
380

try the following simple code...this should get you started

class c1 definition.

public section.

<data declarations here>

protected section.

private section.

endclass.

class c1 implementation.

method m1.

<code>

endmethod.

endclass.

DATA obj TYPE REF TO object.

CREATE OBJECT obj TYPE c1.

now call the methods of class c1 using this object

obj->m1.

try it ....read documentation for more....

regards,

PJ

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
380

There is many different ways that this question can be answer. Tradtionally, ABAP OO is used for dialog programming rather than report programming. This may be changing though. Here is a quick little sample I threw together.



report zrich_0001.



*---------------------------------------------------------------------*
*       CLASS lcl_material DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_material definition.

  public section.

    data: matnr type mara-matnr.
    data: xmara type mara.
    data: xmakt type makt.
    data: xmarc type marc.
    data: imarc type table of marc.
    data: xmard type mard.
    data: imard type table of mard.

    methods: constructor importing im_matnr type mara-matnr,
             write.

  private section.
    methods: get_mara,
             get_makt,
             get_marc,
             get_mard.


endclass.

parameters: p_matnr type mara-matnr.

data: amaterial type ref to lcl_material.

create object amaterial
         exporting
              im_matnr = p_matnr.

call method amaterial->write( ).


*---------------------------------------------------------------------*
*       CLASS lcl_material IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_material implementation.

  method constructor.
    matnr = im_matnr.
    call method me->get_mara.
    call method me->get_makt.
    call method me->get_marc.
    call method me->get_mard.
  endmethod.

  method write.
    write:/ xmara.
    write:/ xmakt.
    loop at imarc into xmarc.
      write:/ xmarc.
    endloop.
    loop at imard into xmard.
      write:/ xmard.
    endloop.
  endmethod.

  method get_mara.
    select single * from mara into xmara
               where matnr = matnr.
  endmethod.

  method get_makt.
    select single * from makt into xmakt
               where matnr = matnr
                 and spras = sy-langu.
  endmethod.

  method get_marc.
    select  * into corresponding fields of table imarc
           from marc
               where matnr = matnr.
  endmethod.

  method get_mard.
    select  * into corresponding fields of table imard
           from mard
               where matnr = matnr.
  endmethod.


endclass.

Regards,

Rich Heilman