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
651

Hi,

If a local class is to be created, which parameter is to be used as importing and which is to be used as exporting.I have seen some examples, but could not understand that which should be importing parameter and which is to be exporting one? Please Give AN EXAMPLE.

Rgds,

khadeer.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
579

Hi Khadeer,

While creating a local class, In a method the parameters you want from user to be entered, that parameters will be declared as Importing Parameters.

The parameters, that you want as output after some calculation or logic using importing parameters, will be declared as Exporting Parameters....

I am giving you a very basic Example of a class :

DATA: w_princ TYPE p DECIMALS 2 VALUE 1000,

w_time TYPE p VALUE 5,

w_rate TYPE p DECIMALS 2 VALUE 10,

w_intr TYPE p DECIMALS 2.

----


  • CLASS NITIN DEFINITION

----


*

----


CLASS interest DEFINITION.

PUBLIC SECTION.

METHODS: calculate IMPORTING princ TYPE p

time TYPE p

rate TYPE p

EXPORTING intr TYPE p.

ENDCLASS. "INTEREST DEFINITION

----


  • CLASS INTEREST IMPLEMENTATION

----


*

----


CLASS interest IMPLEMENTATION.

METHOD calculate.

intr = ( ( princ * time * rate ) / 100 ).

ENDMETHOD. "CALCULATE

ENDCLASS. "INTEREST IMPLEMENTATION

START-OF-SELECTION.

DATA: obj1 TYPE REF TO interest.

CREATE OBJECT: obj1.

CALL METHOD : obj1->calculate EXPORTING princ = w_princ

time = w_time

rate = w_rate

IMPORTING intr = w_intr.

WRITE:/5 'INTEREST FOR PRINCIPLE : 1000 , RATE : 10% , TIME : 5 WILL BE'

.

WRITE:/5 w_intr COLOR 4.

Hope this will help you....

Regards,

Nitin.

4 REPLIES 4
Read only

Former Member
0 Likes
579

Hi,

Refer to the following link. You will get many simple sample code.

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

Regards,

Jaya Vani.

Read only

Former Member
0 Likes
580

Hi Khadeer,

While creating a local class, In a method the parameters you want from user to be entered, that parameters will be declared as Importing Parameters.

The parameters, that you want as output after some calculation or logic using importing parameters, will be declared as Exporting Parameters....

I am giving you a very basic Example of a class :

DATA: w_princ TYPE p DECIMALS 2 VALUE 1000,

w_time TYPE p VALUE 5,

w_rate TYPE p DECIMALS 2 VALUE 10,

w_intr TYPE p DECIMALS 2.

----


  • CLASS NITIN DEFINITION

----


*

----


CLASS interest DEFINITION.

PUBLIC SECTION.

METHODS: calculate IMPORTING princ TYPE p

time TYPE p

rate TYPE p

EXPORTING intr TYPE p.

ENDCLASS. "INTEREST DEFINITION

----


  • CLASS INTEREST IMPLEMENTATION

----


*

----


CLASS interest IMPLEMENTATION.

METHOD calculate.

intr = ( ( princ * time * rate ) / 100 ).

ENDMETHOD. "CALCULATE

ENDCLASS. "INTEREST IMPLEMENTATION

START-OF-SELECTION.

DATA: obj1 TYPE REF TO interest.

CREATE OBJECT: obj1.

CALL METHOD : obj1->calculate EXPORTING princ = w_princ

time = w_time

rate = w_rate

IMPORTING intr = w_intr.

WRITE:/5 'INTEREST FOR PRINCIPLE : 1000 , RATE : 10% , TIME : 5 WILL BE'

.

WRITE:/5 w_intr COLOR 4.

Hope this will help you....

Regards,

Nitin.

Read only

Former Member
0 Likes
579

This is a example

CLASS CL_PRICE_DATA DEFINITION.

PUBLIC SECTION.

  • Hotspot Method

CLASS-METHODS : HOTSPOT FOR EVENT HOTSPOT_CLICK OF

CL_GUI_ALV_GRID

IMPORTING E_ROW_ID .

DATA: UCOMM TYPE SY-UCOMM.

  • Constructor

METHODS : CONSTRUCTOR

IMPORTING CONTAINER TYPE REF TO CL_GUI_CONTAINER,

  • toolbar for Fixed Pricing

HANDLE_TOOLBAR

FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID

IMPORTING E_OBJECT E_INTERACTIVE.

In the above methods Importing means when these methods are E_ROWID would be having a value E_OBJECT E_INTERACTIVE wouldf haaving the pass passed by the event associated .so from the events it would exporting and in the local it would importing .

Please reward if useful..

Read only

Former Member
0 Likes
579

Hi,

DATA:NUM1 TYPE I,

NUM2 TYPE I.

CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: NAME1 IMPORTING VALUE(VAR1) TYPE i

EXPORTING VALUE(VAR2) TYPE i.

ENDCLASS.

CLASS counter IMPLEMENTATION.

METHOD name1.

VAR2 = VAR1 + 2.

ENDMETHOD.

ENDCLASS.

CREATE OBJECT cnt.

CALL METHOD cnt->name1 EXPORTING VAR1 = NUM1

IMPORTING VAR2 = NUM2.

it is nothing like a functiob module bcoz...in class if u specify importing c1 and exporting c2 it 'll cosidered in a reverse manner in program like exporting c1 and impoting c2.

Thanks,

Arunprasad.P