‎2006 Dec 07 10:40 AM
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.
‎2006 Dec 07 10:43 AM
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
‎2006 Dec 07 10:45 AM
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
‎2006 Dec 07 10:50 AM
Hi Hari,
Refer sample code below:
Few links on ABAP OO Concepts
OOPS
http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt
http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf
http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt
http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
Reward points if this Helps.
Manish
‎2006 Dec 08 6:32 AM
Hi Hari,
These links will u as a fresher to OO ABAP
OO ABAP
http://www.sapgenie.com/abap/OO/eg.htm
http://www.sapgenie.com/abap/OO/syntax.htm
http://www.sapgenie.com/abap/OO/index.htm
http://www.sapgenie.com/abap/OO/defn.htm
Rgds,
Prakash
‎2006 Dec 11 5:12 AM
<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.
‎2006 Dec 11 5:15 AM
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
‎2006 Dec 11 9:39 AM
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.