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

Difference between (Export, Import) Versus (Receiving,Return)

Former Member
0 Likes
3,547

Hi all,

Can anyone tell me whats the difference between

the exporting the value from method and importing to object VERSUS

returning the value from method to receiving the value in the object.

Can anyone tell me the difference between first and second method

1) First Method

class lcl_vehicle definition.

public section.

data : test_met type i.

methods get_type importing test1 type i

test2 type i

exporting test3 type i.

endclass.

class lcl_vehicle implementation.

method get_type.

test3 = 10 + test1 + test2.

endmethod.

endclass.

data : test type i.

start-of-selection.

data : r_veh type ref to lcl_vehicle.

create object r_veh.

call method r_veh->get_type( exporting test1 = 5

test2 = 10

importing test3 = test ).

write : test.

O/P = 25

2) Second Method

class lcl_vehicle definition.

public section.

data : test_met type i.

methods get_type importing test1 type i

test2 type i

returning value(test3) type i.

endclass.

class lcl_vehicle implementation.

method get_type.

test3 = 10 + test1 + test2.

endmethod.

endclass.

data : test type i.

start-of-selection.

data : r_veh type ref to lcl_vehicle.

create object r_veh.

call method r_veh->get_type( exporting test1 = 5

test2 = 10

receiving test3 = test ).

write : test.

O/P = 25

Thanks

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,950

I would say without going to deep into lower level coding, they are the same, and there is no reason to try to pick them a part to find out the low level differences. Basically all that you need to remember is that when using RETURNING parameters, you can only ever have one, when using EXPORTING, you can have as many as you want. We use RETURNING in situations like, when we want to find out if a condition is true or false. For example, say we have a method called HAS_HEADER, , and has a returing parameter RESULT type ABAP_BOOL. Here the method implementation is like this.

method has_header..
  if <some_field> = 'X'.
    result = abap_true.
  endif.
endmethod.

We can then use this method "in-line", like this.

if me->has_header( ) = abap_true.

endif.

We could not do this if we used EXPORTING

Regards,

Rich Heilman

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,951

I would say without going to deep into lower level coding, they are the same, and there is no reason to try to pick them a part to find out the low level differences. Basically all that you need to remember is that when using RETURNING parameters, you can only ever have one, when using EXPORTING, you can have as many as you want. We use RETURNING in situations like, when we want to find out if a condition is true or false. For example, say we have a method called HAS_HEADER, , and has a returing parameter RESULT type ABAP_BOOL. Here the method implementation is like this.

method has_header..
  if <some_field> = 'X'.
    result = abap_true.
  endif.
endmethod.

We can then use this method "in-line", like this.

if me->has_header( ) = abap_true.

endif.

We could not do this if we used EXPORTING

Regards,

Rich Heilman

Read only

0 Likes
1,950

Thanks Rich,

I have one more question

I'm trying the importing or receiving value directly in to a variable but for some reason it doesn't allow me to do this

This is how i'm trying to do.

Test = call method r_veh->get_type( exporting test1 = 5

test2 = 10 )

This is the code

class lcl_vehicle definition.

public section.

data : test_met type i.

methods get_type importing test1 type i

test2 type i

returning value(test3) type i.

endclass.

class lcl_vehicle implementation.

method get_type.

test3 = 10 + test1 + test2.

endmethod.

endclass.

data : test type i.

start-of-selection.

data : r_veh type ref to lcl_vehicle.

create object r_veh.

This works

call method r_veh->get_type( exporting test1 = 5

test2 = 10

receiving test3 = test ).

this doesn't works

If iam not wrong there is a way where you move the import or receiving variable directly

test = call method r_veh->get_type( exporting test1 = 5

test2 = 10 )

Thanks

Let me know if oam wrong

Read only

0 Likes
1,950

Yes, you can do that, but there are rules to this syntax. First, you can not use the CALL METHOD, and second, you will remove the EXPORTING. When using the RETURNING, the IMPORTING parameters of the method do not have to be statically referenced with an EXPORTING in the method call, the reason is that the system knows that they are IMPORTING, because when you have a RETURNING parameter you can not have any EXPORTING parameters. yes, it is a little confusing.

You can do this.

test =  r_veh->get_type( test1 = 5 test2 = 10 ).

Regards,

Rich Heilman

Read only

0 Likes
1,950

Hi Rich,

Thanks for your time

I awarded full points