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: 

passing a internal table from method

Former Member
0 Kudos

Hi All,

I am using Object Oriented Programming in my program.

I want to pass a Internal Table from a method calling statement written in a start-of-selection.

Can any one give me the syntax for

1. Declaring a method with importing parameter as internal table.

2. Syntax for Method Implementation

3. Syntax for calling the method from start-of-selection.

helpful answers are rewarded.

Regards,

Azaz Ali.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here is a simple example.



 report zrich_0001.

*---------------------------------------------------------------------*
*       CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
 class lcl_app definition.

   public section.

     types: t_t001 type table of t001.

     class-data: it001 type table of t001,
                 xt001 type t001.

     class-methods: put_data importing im_t001 type t_t001,
                    write_data.

 endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_app  IMPLEMENATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
 class lcl_app implementation.

   method put_data.
     it001[] = im_t001[].

   endmethod.

   method write_data.
     loop at it001 into xt001.
       write:/ xt001.
     endloop.

   endmethod.

 endclass.

 data: itab type table of t001.

 start-of-selection.

   select * into table itab from t001.

   call method lcl_app=>put_data( itab ).
   call method lcl_app=>write_data.

Regards,

Rich Heilman

5 REPLIES 5

Former Member
0 Kudos

Hi,

Check this program

DEMO_ABAP_OBJECTS_METHODS

Give ur Id will send docs on OO ABAP

Regards

Message was edited by: Manoj Gupta

0 Kudos

Hi Manoj,

In program which you have mentioned no where call method statement is using exporting statement with internal Table.

Regards,

Azaz Ali.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Here is a simple example.



 report zrich_0001.

*---------------------------------------------------------------------*
*       CLASS lcl_app DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
 class lcl_app definition.

   public section.

     types: t_t001 type table of t001.

     class-data: it001 type table of t001,
                 xt001 type t001.

     class-methods: put_data importing im_t001 type t_t001,
                    write_data.

 endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_app  IMPLEMENATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
 class lcl_app implementation.

   method put_data.
     it001[] = im_t001[].

   endmethod.

   method write_data.
     loop at it001 into xt001.
       write:/ xt001.
     endloop.

   endmethod.

 endclass.

 data: itab type table of t001.

 start-of-selection.

   select * into table itab from t001.

   call method lcl_app=>put_data( itab ).
   call method lcl_app=>write_data.

Regards,

Rich Heilman

former_member927251
Active Contributor
0 Kudos

Hi Azaz,

1. Declare the parameter as follows in the parameter list of the method :

Parameter : t_table

Type : Exporting or Changing

Typing Method : Type

Associated Type : Table Type

2. Double Click the method name in SE24 and write the code.

3. CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST

EXPORTING

FILE = SOURCE

RECEIVING

RESULT = RC

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

WRONG_PARAMETER = 3

others = 4.

<b>Reward points if it helps.</b>

Former Member
0 Kudos

Hi,

Calling Method is similar to calling function Module.

CALL METHOD cl_gui_frontend_services=>gui_download

exporting

filename =

  • IMPORTING

  • FILELENGTH =

changing

data_tab = <b>( this is ur internal table name )</b>* EXCEPTIONS

  • FILE_WRITE_ERROR = 1.

<b>In OO ABAP u avoid creating table with header line</b>

Best way to call method is to use <b>PATTERN</b> Button

1) Click Pattern Button

2) Select Abap Object Pattern

3) Enter

4) Select Call Method

5) Enter instance name ( i. e used for create object ) ( No need for static method like gui_download )

6) Enter Class / Interface name

7) Enter Method Name

done.

<b>passing value to method is similar to FM.

Creating internal table for Method

any TYPE ........SAY TY_Intern

Then Syntax Should Be

DATA : OO_INTERNAL_TABLe type table of TY_Intern.

pass this to the Method.

Hope This will solve ur problem.

Please Mark Helpful Answers</b>

Message was edited by: Manoj Gupta