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: 

Internal table as a class attribute

Former Member
0 Kudos

Hello everybody.

I think many of you hhave passed through the same problem. I have a requirement to pass internal table to class as for example class constructor parameter. It is desirable that class should get the table of variable structure.

How coult that be realized?

Thank you in advance for your kind help.

--

Best regards,

Andrey

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

The parameter can be typed TYPE TABLE. Let us know if it helps.

Regards

4 REPLIES 4

Former Member
0 Kudos

Hi,

The parameter can be typed TYPE TABLE. Let us know if it helps.

Regards

0 Kudos

Here is a quick sample........



report zrich_0003 .


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

  public section.

    methods: constructor importing table type table.


endclass.



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

  method constructor.

    check sy-subrc = 0.

  endmethod.

endclass.


data: app type ref to lcl_app.
data: imara type table of mara.

start-of-selection.


  create object app
          exporting
                table = imara.

  check sy-subrc = 0.

Regards,

Rich Heilman

Former Member
0 Kudos

As mentioned earlier, you can TYPE the parameter as a generic table type, for example TYPE STANDARD TABLE, TYPE INDEX TABLE, etc.

Your next problem is how to use the table. You can create a work area with a DATA statement:

DATA:

wa_table LIKE LINE OF parameter_table.

You can:

LOOP AT parameter_table INTO wa_table.

Since your code does not know the field names, you must

access the fields by assigning to a field symbol using:

ASSIGN COMPONENT index OF ... TO ...

Is this what you need?

0 Kudos

Thank you all dear colleagues.

I've found a way to move due to your kind help.

--

With kind regards,

Andrey.