‎2010 Feb 03 8:15 PM
So my code looks like this:
DATA: o_ztransload_tools TYPE REF TO zcl_transload_toolbox.
CREATE OBJECT o_ztransload_tools.
o_ztransload_tools->zzcreate_date_range( zzobjin_dtlw = zzin_dtlw
zzobjin_dthigh = zzin_dthigh ) .This class method returns a date range. I would like to understand how to write this code without using the 'IMPORT' 'EXPORT' , parameter identifiers...if possible., and just using parentheses, as a shorthand way of writing the call method. So, from what I've read, it is possible to write the code this way.But when I try to add code for the single returning value, I get syntax errors. How should the code be written for the method's returning value to be syntactically correct?
Thank-You, Tom
‎2010 Feb 04 3:01 PM
There would a several different combinations you may have to use depending on the type of parameters.
If you have a single RETURNING parameter and single IMPORTING parameter, you can receive the results in that variable directly. Llike:
lv_Day = zcl_Test=>give_day( sy-datum ).
If you have multiple Importing parameters, you call the method like:
zcl_test=>get_data(
io_data = o_data
io_data2 = o_data ).
You can also set the the preferred parameter, when you have more than one importing parameter. Like IO_DATA and IO_DATA2. If make the preferred parameter as the IO_DATA2, than you can use pass this parameter without specifying parameter name.
zcl_test=>get_Data( o_data_second ).
If you have importing, exporting, changing parameters; than you have to explicitly mention the word EXPORTING, IMPORTING ... etc to let the system know what to change
zcl_test_alv=>factory(
EXPORTING
iv_alv_type = alv_1
IMPORTING
eo_alv = me->o_alv
changing
ct_Data = t_Data ).
You can't have Receiving parameter along with Changing and Exporting parameters in the same method.
Regards,
Naimesh Patel
‎2010 Feb 03 9:14 PM
If you have one necessary import parameter and one returning parameter you can call the method java / c# style.
l_day = lr_object->get_day_from_date( SY-DATUM ).
‎2010 Feb 04 4:43 AM
Halo Tom,
For your information there can only be one returning parameter for a method and that too will be set optional flag automatically
So your code should be like
As a part of SAP standard naming convention
Use lr_ for class reference variables
Use l_ for normal variables
Use lx_ for exception reference variables
Please dont use zz for method names ( as it is not mandatory to start with Z for method names )
and use i_* for importing parameters
So your code will have more clarity like below
DATA: lr_transload_tools TYPE REF TO zcl_transload_toolbox.
CREATE OBJECT lr_transload_tools.
l_transload_tools->create_date_range( i_objin_dtlw = in_dtlw
i_ objin_dthigh =in_dthigh ) .
‎2010 Feb 04 9:15 AM
Hi Tom,
You can write the code without using the IMPORTING Parameters in the following manner:
IMPORTING Parameter - If it is used in the class as NON - OPTIONAL or OPTIONAL Parameter
Example :
DATA : lr_test TYPE REF TO ZCLASS_TEST_001.
data : lv_name(20) TYPE c.
create OBJECT lr_test.
lr_test->call_me( name = lv_name
ret_name = lv_name ).
WRITE : lv_name.
Hope this will help.
Thanks,
Samantak.
Edited by: Samantak Chatterjee on Feb 4, 2010 2:45 PM
‎2010 Feb 04 9:33 AM
Hi,
Perhaps your class method definition must be incorrect. Make sure that you have a parameter of type "RETURNING" and not "EXPORTING". Only then you can assign a method call on the RHS to a variable directly on the LHS .
class lcl_class1 definition.
public section.
methods m1 importing i_input type i
returning value(r_output) type i.
endclass.
class lcl_class1 implementation.
method m1.
r_output = i_input.
endmethod.
endclass.
start-of-selection.
data ref_class1 type ref to lcl_class1.
data input type i value '10'.
data result type i.
create object ref_class.
result = ref_class->m1( input ).
If this is a global class, simple use the returning parameter and make sure to tick the Pass value checkbox.
Hope this helps.
Br,
Advait
‎2010 Feb 04 3:01 PM
There would a several different combinations you may have to use depending on the type of parameters.
If you have a single RETURNING parameter and single IMPORTING parameter, you can receive the results in that variable directly. Llike:
lv_Day = zcl_Test=>give_day( sy-datum ).
If you have multiple Importing parameters, you call the method like:
zcl_test=>get_data(
io_data = o_data
io_data2 = o_data ).
You can also set the the preferred parameter, when you have more than one importing parameter. Like IO_DATA and IO_DATA2. If make the preferred parameter as the IO_DATA2, than you can use pass this parameter without specifying parameter name.
zcl_test=>get_Data( o_data_second ).
If you have importing, exporting, changing parameters; than you have to explicitly mention the word EXPORTING, IMPORTING ... etc to let the system know what to change
zcl_test_alv=>factory(
EXPORTING
iv_alv_type = alv_1
IMPORTING
eo_alv = me->o_alv
changing
ct_Data = t_Data ).
You can't have Receiving parameter along with Changing and Exporting parameters in the same method.
Regards,
Naimesh Patel
‎2010 Feb 04 3:20 PM
Great answers! From the naming convention tips, to the syntax suggestions! Thank-You All!