03-24-2008 11:24 AM
hi friends
how to pass the internal table value into method.
regards
pauldharma
03-24-2008 8:15 PM
Hi,
To pass an internal table to a method, you need to create a parameter (importing, exporting or changing) with the table type (or like a generic table) and then pass it in the call.
For example:
TYPES lty_sflight TYPE STANDARD TABLE OF sflight WITH NON-UNIQUE DEFAULT KEY.
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
example1 EXPORTING et_sflight TYPE lty_sflight,
example2 EXPORTING et_table TYPE STANDARD TABLE.
ENDCLASS. "lcl_class DEFINITION
DATA:
lt_sflight TYPE lty_sflight.
START-OF-SELECTION.
lcl_class=>example1( IMPORTING et_sflight = lt_sflight ).
lcl_class=>example2( IMPORTING et_table = lt_sflight ).
CLASS lcl_class IMPLEMENTATION.
METHOD example1.
SELECT * FROM sflight INTO TABLE et_sflight.
ENDMETHOD. "example1
METHOD example2.
SELECT * FROM sflight INTO TABLE et_table.
ENDMETHOD. "example2
ENDCLASS. "lcl_class IMPLEMENTATION
Regards,
If it helps, please rewards.
03-24-2008 11:49 AM
hi,
Methods are internal procedures in classes that determine the behavior of an object. They can access all
attributes in their class and can therefore change the state of an object.
Methods have a parameter interface that enables them to receive values when they are called and pass
values back to the calling program.
In ABAP Objects, methods can have IMPORTING, EXPORTING, CHANGING and RETURNING
parameters as well as EXCEPTIONS. All parameters can be passed by value or reference.
You can define a return code for methods using RETURNING. You can only do this for a single parameter,
which additionally must be passed as a value. Also, you cannot then define EXPORTING and CHANGING
parameters. You can define functional methods using the RETURNING parameter (explained in more
detail below).
All input parameters (IMPORTING, CHANGING parameters) can be defined as optional parameters in the
declaration using the OPTIONAL or DEFAULT additions. These parameters then do not necessarily have
to be passed when the object is called. If you use the OPTIONAL addition, the parameter remains
initialized according to type, whereas the DEFAULT addition allows you to enter a start value.
CLASS <classname> DEFINITION.
METHODS: <method_name>
[ IMPORTING <im_var> TYPE <type>
EXPORTING <ex_var> TYPE <type>
CHANGING <ch_var> TYPE <type>
RETURNING VALUE(<re_var>) TYPE <type>
EXCEPTIONS <exception> ].
ENDCLASS.
Pass the internal table in the changing parameter.
Hope this helps, Do reward.
03-24-2008 8:15 PM
Hi,
To pass an internal table to a method, you need to create a parameter (importing, exporting or changing) with the table type (or like a generic table) and then pass it in the call.
For example:
TYPES lty_sflight TYPE STANDARD TABLE OF sflight WITH NON-UNIQUE DEFAULT KEY.
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
example1 EXPORTING et_sflight TYPE lty_sflight,
example2 EXPORTING et_table TYPE STANDARD TABLE.
ENDCLASS. "lcl_class DEFINITION
DATA:
lt_sflight TYPE lty_sflight.
START-OF-SELECTION.
lcl_class=>example1( IMPORTING et_sflight = lt_sflight ).
lcl_class=>example2( IMPORTING et_table = lt_sflight ).
CLASS lcl_class IMPLEMENTATION.
METHOD example1.
SELECT * FROM sflight INTO TABLE et_sflight.
ENDMETHOD. "example1
METHOD example2.
SELECT * FROM sflight INTO TABLE et_table.
ENDMETHOD. "example2
ENDCLASS. "lcl_class IMPLEMENTATION
Regards,
If it helps, please rewards.
03-25-2008 7:41 PM
Hi Dharma,
You can pass the internal table to a method in
CHANGING
or in
TABLES
Thanks & Regards,
AMK.
REWARD POINTS IF USEFUL.