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

OO programing

Former Member
0 Likes
753

Hi Gurus,

Can any explain me with a sample code how to declare an internal table and use that OO programming? Suppose I want to display 10 records from a DB table. How to retrieve and how to display. Please explain me I am new to OO programming. Explain with a sample code how to declare a class and implementing a class using methods.

7 REPLIES 7
Read only

Former Member
0 Likes
711

Hi Sirram,

Retrieving data using SELECT, and declaring internal tables same like general ABAP.

OO ABAP differs in Object oriented programming concepts only.

See the course BC401 will helps to you.

Regards

Bhupal Reddy

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
711

Hi,

Here is the simple example of OOPS ALV.Kindly reward points if it helps.This is the simple program without GUI.

CLASS lcl_event_receiver DEFINITION DEFERRED.

class cl_gui_container definition load.

DATA : o_grid TYPE REF TO cl_gui_alv_grid,

o_docking TYPE REF TO cl_gui_docking_container,

w_layout TYPE lvc_s_layo,

  • Enable variant saving

w_variant TYPE disvariant.

DATA : itab TYPE STANDARD TABLE OF MARA,

wa type mara.

select * from mara into table itab up to 10 rows.

call screen 9000."Double click here to create screen

*IN the flow logic uncomment the PBO module

module STATUS_9000 output.

  • This form create the Docking container and the ALV grid.

if o_grid is initial.

CREATE OBJECT o_docking

EXPORTING

ratio = '95'.

CREATE OBJECT o_grid

EXPORTING

i_parent = o_docking.

endif.

w_layout-sel_mode = 'B'.

w_variant-report = sy-repid.

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

I_STRUCTURE_NAME = 'MARA'

is_variant = w_variant

i_save = 'A'

is_layout = w_layout

CHANGING

it_outtab = itab[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

endmodule. " STATUS_9000 OUTPUT

Read only

Former Member
Read only

Former Member
0 Likes
711

<i>* declaring attributes and methods for class c1</i>

<b>class definition c1.</b>

public section.

data: wa type scarr,

itab type table of scarr.

methods m1 importing para type scarr-carrid.

endclass.

<i>* implementing methods present in class c1

  • here we explain how method must react when called.</i>

<b>class implementation c1.</b>

method m1.

select * from scarr into table itab where carrid = para.

<i>* printing data from itab.</i>

loop at itab into wa.

write: / wa.

endloop.

endmethod.

endclass.

<b>start-of-selection.</b>

parameters pa type scarr-carrid.

<i>* creating obj(instance) for class c1.</i>

data obj type ref to c1.

create object obj.

<i>* calling method m1 of class c1 by object obj.</i>

call method obj->m1

exporting

para = p1.

Read only

Former Member
0 Likes
711

Have a lok at below link and Go to page 1291. It will help you to find out the details.

<a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf">OO Abap</a>

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

Former Member
0 Likes
711

There are ways to implement the class & accessing those programs. Here I am trying to explain thru' standard tools.

1. Create a simple class using Trans. <b>SE24</b>. Eg. YRK_OO

i. Define a method '<b>Read</b>' with visibility (<b>Instance - Public</b>) & assign parameter for this method to export an output.

ii. Inside the method, write your normal ABAP code to get an output.

2. Create a sample program using Trans. <b>SE38</b>.

DATA ref_rk TYPE REF TO yrk_oo.

CREATE OBJECT ref_rk.

CALL METHOD ref_rk->read

importing

<--


> = <--


>.

3. Now, execute the program & you'll get the output.

Instead of creating class & stuffs, you can directly define and implement the class within program itself.

For Ex....

REPORT ZOO.

----


  • CLASS counter DEFINITION

----


*

----


CLASS COUNTER DEFINITION.

PUBLIC SECTION.

METHODS INCREMENT.

PRIVATE SECTION.

DATA COUNT TYPE I.

ENDCLASS. "counter DEFINITION

----


  • CLASS counter IMPLEMENTATION

----


*

----


CLASS COUNTER IMPLEMENTATION.

METHOD INCREMENT.

COUNT = COUNT + 1.

WRITE:/ 'The Count is:', COUNT.

ENDMETHOD. "increment

ENDCLASS. "counter IMPLEMENTATION

DATA COUNT TYPE REF TO COUNTER.

START-OF-SELECTION.

CREATE OBJECT COUNT.

DO 5 TIMES.

CALL METHOD COUNT->INCREMENT.

ENDDO.

Like as the above one, declare the internal table and access the same.

I hope this will help you.

Regards,

Ramki.