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: 

how to pass the internal table into method

Former Member
0 Kudos

hi friends

how to pass the internal table value into method.

regards

pauldharma

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

3 REPLIES 3

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi Dharma,

You can pass the internal table to a method in

CHANGING

or in

TABLES

Thanks & Regards,

AMK.

REWARD POINTS IF USEFUL.