Application Development 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: 

Class Definition within a program

Former Member
0 Kudos

Hi All,

My requirement is such that I need to create a class within a program. My class has 3 methods.

1. In the first method, meth1, I need to import a select-option values(s_emp), that is entered on the selection screen.

2. In the second method, meth2, I need to import a table(t_emp) into the method.

3. In the third method, meth3, I need to export a table(t_emp2) from the method.

Can anyone pls let me know the correct syntax that I can use to define these methods(i.e., the class definition) ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Abhishek,

You can check these simple ABAP OBJECTs programs.

ABAP_OBJECTS_ENJOY_0           Template for Solutions of ABAP Object Enjoy Course
ABAP_OBJECTS_ENJOY_1           Model Solution 1: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_2           Model Solution 2: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_3           Model Solution 3: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_4           Model Solution 4: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_5           Model Solution 5: ABAP Objects Enjoy Course       
DEMO_ABAP_OBJECTS              Complete Demonstration for ABAP Objects           
DEMO_ABAP_OBJECTS_CONTROLS     GUI Controls on Screen                            
DEMO_ABAP_OBJECTS_EVENTS       Demonstration of Events in ABAP Objects           
DEMO_ABAP_OBJECTS_GENERAL      ABAP Objects Demonstration                        
DEMO_ABAP_OBJECTS_INTERFACES   Demonstration of Interfaces in ABAP Objects       
DEMO_ABAP_OBJECTS_METHODS      Demonstration of Methods in ABAP Objects          
DEMO_ABAP_OBJECTS_SPLIT_SCREEN Splitter Control on Screen                        

Cheers

VJ

4 REPLIES 4

Former Member
0 Kudos

Hi Abhishek,

You can check these simple ABAP OBJECTs programs.

ABAP_OBJECTS_ENJOY_0           Template for Solutions of ABAP Object Enjoy Course
ABAP_OBJECTS_ENJOY_1           Model Solution 1: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_2           Model Solution 2: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_3           Model Solution 3: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_4           Model Solution 4: ABAP Objects Enjoy Course       
ABAP_OBJECTS_ENJOY_5           Model Solution 5: ABAP Objects Enjoy Course       
DEMO_ABAP_OBJECTS              Complete Demonstration for ABAP Objects           
DEMO_ABAP_OBJECTS_CONTROLS     GUI Controls on Screen                            
DEMO_ABAP_OBJECTS_EVENTS       Demonstration of Events in ABAP Objects           
DEMO_ABAP_OBJECTS_GENERAL      ABAP Objects Demonstration                        
DEMO_ABAP_OBJECTS_INTERFACES   Demonstration of Interfaces in ABAP Objects       
DEMO_ABAP_OBJECTS_METHODS      Demonstration of Methods in ABAP Objects          
DEMO_ABAP_OBJECTS_SPLIT_SCREEN Splitter Control on Screen                        

Cheers

VJ

anversha_s
Active Contributor
0 Kudos

hi,

CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: method1 IMPORTING value(s_emp) TYPE give_type,

method2 IMPORTING table(t_emp) LIKE ITAB_NAME,

method3 EXPORTING table(t_emp2)LIKE ITAB_NAME2.

ENDCLASS.

rgds

anver

if helped mark points

Former Member
0 Kudos

Hi

this is a a little sample:

REPORT ZCLASS .

TABLES MARA.

SELECT-OPTIONS: SO_MATNR FOR MARA-MATNR.

CLASS MY_CLASS DEFINITION DEFERRED.

DATA: MY_OBJECT TYPE REF TO MY_CLASS.

TYPES: BEGIN OF TY_ITAB,

FIELD1,

FIELD2,

FIELD3,

END OF TY_ITAB.

DATA: EXPORT_ITAB TYPE STANDARD TABLE OF TY_ITAB,

IMPORT_ITAB TYPE STANDARD TABLE OF TY_ITAB.

----


  • CLASS MY_CLASS DEFINITION

----


  • ........ *

----


CLASS MY_CLASS DEFINITION.

PUBLIC SECTION.

METHODS: GET_SELECTION_SCREEN,

GET_INTERNAL_TABLE IMPORTING P_ITAB TYPE TABLE,

SET_INTERNAL_TABLE EXPORTING P_ITAB TYPE TABLE.

ENDCLASS.

----


  • CLASS MY_CLASS IMPLEMENTATION

----


  • ........ *

----


CLASS MY_CLASS IMPLEMENTATION.

METHOD GET_SELECTION_SCREEN.

IF SO_MATNR[] IS INITIAL.

ENDIF.

ENDMETHOD.

METHOD GET_INTERNAL_TABLE.

ENDMETHOD.

METHOD SET_INTERNAL_TABLE.

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

CREATE OBJECT MY_OBJECT.

CALL METHOD MY_OBJECT->GET_SELECTION_SCREEN.

CALL METHOD MY_OBJECT->GET_INTERNAL_TABLE

EXPORTING P_ITAB = EXPORT_ITAB.

CALL METHOD MY_OBJECT->SET_INTERNAL_TABLE

IMPORTING P_ITAB = IMPORT_ITAB.

Anyway you should consider all global data defined in a program are seen by local class, so perhaps you don't need to create methods to import global data.

Max

Former Member
0 Kudos

Thanks for the reply Max and also thanks to others for the valuable info. Points awarded.