Skip to Content
author's profile photo Former Member
Former Member

Internal table as a class attribute

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

Add comment
10|10000 characters needed characters exceeded

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 09, 2005 at 12:31 PM

    Hi,

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

    Regards

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • author's profile photo Former Member
    Former Member
    Posted on Mar 09, 2005 at 03:39 PM

    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?

    Add comment
    10|10000 characters needed characters exceeded