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: 

Export Internal table by calling static method

Former Member
0 Kudos

Hi friends,

Can u please tell me how to get internal table in export parameter by calling static method.

OR can u tell me how to declare internal table in method parameter.

Thanks in advance

6 REPLIES 6

messier31
Active Contributor
0 Kudos

Hi,

Check example below. Here we pass internal table to method.

TYPES: BEGIN OF ITAB_TYPE,

TEXT(50),

NUMBER TYPE I,

END OF ITAB_TYPE.

DATA: ITAB TYPE STANDARD TABLE OF ITAB_TYPE WITH

NON-UNIQUE DEFAULT KEY INITIAL SIZE 100,

BEGIN OF ITAB_LINE,

TEXT(50),

NUMBER TYPE I,

END OF ITAB_LINE,

STRUC like T005T.

...

PERFORM DISPLAY TABLES ITAB

USING STRUC.

FORM DISPLAY TABLES PAR_ITAB STRUCTURE ITAB_LINE

USING PAR like T005T.

DATA: LOC_COMPARE LIKE PAR_ITAB-TEXT.

WRITE: / PAR-LAND1, PAR-LANDX.

...

LOOP AT PAR_ITAB WHERE TEXT = LOC_COMPARE.

...

ENDLOOP.

ENDFORM.

Hope this helps.

Enjoy SAP.

Pankaj Singh.

athavanraja
Active Contributor
0 Kudos

set the export parameter of type ref to data

(myitab type ref to data)

and within the method

get reference of [itabname] into myitab .

in the program calling this method.

field-symbols: <mytab> type any table .

assign myitab->* to <mytab> .

Regards

Raja

0 Kudos

Raja's method will work for all tables irrespective of the structure and is the best possible approach. However, if your requirement is simple and you do not have to deal with a lot many tables,

1. Create a Type-Pool, suppose ztypl

2. Within the type pool, declare a Structure type,


TYPES: BEGIN OF ztypl_struct1,
         "Place your fields here
       END OF ztypl_strict1,

       "Create a table of type ztypl_struct1 here
       ztypl_table1 TYPE TABLE OF ztypl_struct1.

Use "ZTYPL_TABLE1" as the "Associated type" in your method's Parameter definition in SE24.

eg.

IT_TABLE TYPE ZTYPL_TABLE1

If you are writing your class in an include,


    METHODS my_method1
      IMPORTING
        it_table1   TYPE ztypl_table1.

Do remember to include

TYPE-POOLS: ztypl.

in your class's Constructor / Include program.

Please award points if helpful.

Regards,

Ryan

Message was edited by:

Ryan Cannel

Former Member
0 Kudos

Hi,

with pointers (type ref to data) you loose some of the compiler checks vantages; because of the generic typing the compiler can't check any type incompatibility. Your have to check/catch yourself at the dereferencing and casting (assigning) point if maybe a exeption occurres. I don't think your need to beginn to programm generically for your requirements.

TYPE-POOLS are antiquated kind to declare types (from R/3 3.x) and SAP ITself does not model any new type-pools.

The right way to pass a internal table from a public method is to declare this table as Table Type in the data dictionary. First you have to declare the structure as in the data dictionary. This is the only right way (other that generically) to assing type of parameters to a public method of a class. If a method is public, the types that its parameters uses are to be public too..

Regards,

Gianpietro

0 Kudos

Hi,

Using Table type is obselete , try not to use it

Regards,

Pranshu

0 Kudos

Hello Virat

The previous posting is nonsense (see below). Table types are absolutely mandatory if you want to use itabs in public methods.

Regards

Uwe

> Hi,

>

> Using Table type is obselete , try not to use it

>

> Regards,

> Pranshu