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 make Internal table in OO Abap

Former Member
0 Kudos

Hello all,

I want to create a local internal table in a method. How can i do that. ALso is it possible to use Loop at itab in method???

Regards,

Arpit

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, but the syntax is a little different.

You can't use header lines not OCCURS.




report zrich_0001.


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

  public section.

    data: it001 type table of t001.
    data: xt001 type t001.


    methods: get_it,
             write_it.


endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.

  method get_it.

    select * into table it001 from t001.

  endmethod.

  method write_it.

    loop at it001 into xt001.
      write:/ xt001-bukrs.
    endloop.

  endmethod.

endclass.


data: myapp type ref to lcl_app.

start-of-selection.

  create object myapp.
  call method myapp->get_it.
  call method myapp->write_it.


Regards,

Rich Heilman

5 REPLIES 5

former_member188685
Active Contributor
0 Kudos

loop at itab into wa.

endloop.

is possible.

and if you want to import or export a table then

importing itab type any

regards

vijay

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Yes, but the syntax is a little different.

You can't use header lines not OCCURS.




report zrich_0001.


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

  public section.

    data: it001 type table of t001.
    data: xt001 type t001.


    methods: get_it,
             write_it.


endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_app IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.

  method get_it.

    select * into table it001 from t001.

  endmethod.

  method write_it.

    loop at it001 into xt001.
      write:/ xt001-bukrs.
    endloop.

  endmethod.

endclass.


data: myapp type ref to lcl_app.

start-of-selection.

  create object myapp.
  call method myapp->get_it.
  call method myapp->write_it.


Regards,

Rich Heilman

0 Kudos

Thanks,

Rich, you rock man...

regards,

Arpit

0 Kudos

Thanks man. Glad to help.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi,

First define a structure with same field as in Internal table.

Then in method -- Method parameter declare

parameter Type type reference type

XXXXX Importing type structure name you created

the same u can used in loop.

Thanks

Rajeev