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

ooabap

Former Member
0 Likes
652

Hi all,

i want a simple demo for simple clas and super clas in ooabap.

pls tell me the differenece.if possible tell me with screen shots

thanks

haasini

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
621

Hi haasini,

pls try with the below code.it will works.

REPORT Z_OOABAP18 .CLASS lcl_employee DEFINITION.

PUBLIC SECTION.

*----


  • The public section is accesible from outside

*----


TYPES:

BEGIN OF t_employee,

no TYPE i,

name TYPE string,

END OF t_employee.

METHODS:

constructor

IMPORTING im_employee_no TYPE i

im_employee_name TYPE string,

display_employee.

  • Class methods are global for all instances

CLASS-METHODS: display_no_of_employees.

PROTECTED SECTION.

*----


  • The protecetd section is accesible from the class and its subclasses

*----


  • Class data are global for all instances

CLASS-DATA: g_no_of_employees TYPE i.

PRIVATE SECTION.

*----


  • The private section is only accesible from within the classs

*----


DATA: g_employee TYPE t_employee.

ENDCLASS.

*--- LCL Employee - Implementation

CLASS lcl_employee IMPLEMENTATION.

METHOD constructor.

g_employee-no = im_employee_no.

g_employee-name = im_employee_name.

g_no_of_employees = g_no_of_employees + 1.

ENDMETHOD.

METHOD display_employee.

WRITE:/ 'Employee', g_employee-no, g_employee-name.

ENDMETHOD.

METHOD display_no_of_employees.

WRITE: / 'Number of employees is:', g_no_of_employees.

ENDMETHOD.

ENDCLASS.

************************************************************************

  • R E P O R T

*********************************************************************

DATA: g_employee1 TYPE REF TO lcl_employee,

g_employee2 TYPE REF TO lcl_employee.

START-OF-SELECTION.

CREATE OBJECT g_employee1

EXPORTING im_employee_no = 1

im_employee_name = 'Vikram.C'.

CREATE OBJECT g_employee2

EXPORTING im_employee_no = 2

im_employee_name = 'Raghava.V'.

CALL METHOD g_employee1->display_employee.

CALL METHOD g_employee2->display_employee.

finlly execute.

i hope it wil help you thanks

sankar.

4 REPLIES 4
Read only

Former Member
0 Likes
622

Hi haasini,

pls try with the below code.it will works.

REPORT Z_OOABAP18 .CLASS lcl_employee DEFINITION.

PUBLIC SECTION.

*----


  • The public section is accesible from outside

*----


TYPES:

BEGIN OF t_employee,

no TYPE i,

name TYPE string,

END OF t_employee.

METHODS:

constructor

IMPORTING im_employee_no TYPE i

im_employee_name TYPE string,

display_employee.

  • Class methods are global for all instances

CLASS-METHODS: display_no_of_employees.

PROTECTED SECTION.

*----


  • The protecetd section is accesible from the class and its subclasses

*----


  • Class data are global for all instances

CLASS-DATA: g_no_of_employees TYPE i.

PRIVATE SECTION.

*----


  • The private section is only accesible from within the classs

*----


DATA: g_employee TYPE t_employee.

ENDCLASS.

*--- LCL Employee - Implementation

CLASS lcl_employee IMPLEMENTATION.

METHOD constructor.

g_employee-no = im_employee_no.

g_employee-name = im_employee_name.

g_no_of_employees = g_no_of_employees + 1.

ENDMETHOD.

METHOD display_employee.

WRITE:/ 'Employee', g_employee-no, g_employee-name.

ENDMETHOD.

METHOD display_no_of_employees.

WRITE: / 'Number of employees is:', g_no_of_employees.

ENDMETHOD.

ENDCLASS.

************************************************************************

  • R E P O R T

*********************************************************************

DATA: g_employee1 TYPE REF TO lcl_employee,

g_employee2 TYPE REF TO lcl_employee.

START-OF-SELECTION.

CREATE OBJECT g_employee1

EXPORTING im_employee_no = 1

im_employee_name = 'Vikram.C'.

CREATE OBJECT g_employee2

EXPORTING im_employee_no = 2

im_employee_name = 'Raghava.V'.

CALL METHOD g_employee1->display_employee.

CALL METHOD g_employee2->display_employee.

finlly execute.

i hope it wil help you thanks

sankar.

Read only

Sm1tje
Active Contributor
0 Likes
621

Demo (sample) report BCALV_GRID* (not sure about the exact name), make use of this principle. CL_GUI_ALV_GRID is a subclass which gets properties of superclass.

Read only

Former Member
0 Likes
621

Hi shankar,

really amazing. i got the solution. thanksfor u n sdn. its working.

haasini

Read only

Former Member
0 Likes
621

hi check this..

http://www.saptechnical.com/Tutorials/OOPS/MainPage.htm

Demo program illustrating Simple class and Super class

&----


*& Report Z_OOABAP18 *

*& *

&----


REPORT Z_OOABAP18 .

CLASS lcl_employee DEFINITION.

PUBLIC SECTION.

*----


  • The public section is accesible from outside

*----


TYPES:

BEGIN OF t_employee,

no TYPE i,

name TYPE string,

END OF t_employee.

METHODS:

constructor

IMPORTING im_employee_no TYPE i

im_employee_name TYPE string,

display_employee.

  • Class methods are global for all instances

CLASS-METHODS: display_no_of_employees.

PROTECTED SECTION.

*----


  • The protecetd section is accesible from the class and its subclasses

*----


  • Class data are global for all instances

CLASS-DATA: g_no_of_employees TYPE i.

PRIVATE SECTION.

*----


  • The private section is only accesible from within the classs

*----


DATA: g_employee TYPE t_employee.

ENDCLASS.

*--- LCL Employee - Implementation

CLASS lcl_employee IMPLEMENTATION.

METHOD constructor.

g_employee-no = im_employee_no.

g_employee-name = im_employee_name.

g_no_of_employees = g_no_of_employees + 1.

ENDMETHOD.

METHOD display_employee.

WRITE:/ 'Employee', g_employee-no, g_employee-name.

ENDMETHOD.

METHOD display_no_of_employees.

WRITE: / 'Number of employees is:', g_no_of_employees.

ENDMETHOD.

ENDCLASS.

************************************************************************

  • R E P O R T

*********************************************************************

DATA: g_employee1 TYPE REF TO lcl_employee,

g_employee2 TYPE REF TO lcl_employee.

START-OF-SELECTION.

CREATE OBJECT g_employee1

EXPORTING im_employee_no = 1

im_employee_name = 'Vikram.C'.

CREATE OBJECT g_employee2

EXPORTING im_employee_no = 2

im_employee_name = 'Raghava.V'.

CALL METHOD g_employee1->display_employee.

CALL METHOD g_employee2->display_employee.

regards,

venkat