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

creating a workare from a generic internal table

How can i create a workarea from an internal table in a method of a class. the problem is that the internal table gets a generic type when passing it to the method.

i tried:

data wa type ref to data.

create data wa like line of itab.

but when trying...

loop itab into wa.

... i get a conversion error.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 01, 2004 at 10:22 AM

    Hello Tobias,

    the brutal way is:

    Define into the method (or global) an internal table as

    you need and relate the passing table to it.

    fex.:

    data: lt_tab type standard table of 'Hugo'.

    data: lf_itab type 'HUGO'.

    lt_tab[] = Par_Tab[]. " type any table

    loop at itab into lf_itab.

    ...

    endloop.

    Hope i could help You

    BR

    Michael

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Tobias,

      In this case You have to use field-symbols.

      This report creates list-output from any tables.

      It shows You an geneally way to solve Your problem:

      Hope I could help You

      BR

      Michael

      REPORT zmbt_generic_list .

      CLASS gcl_lister DEFINITION.

      PUBLIC SECTION.

      CLASS-METHODS:

      mth_write_list IMPORTING par_table TYPE ANY TABLE.

      ENDCLASS.

      CLASS gcl_lister IMPLEMENTATION.

      METHOD mth_write_list.

      FIELD-SYMBOLS:

      <zeile> TYPE ANY,

      <field> TYPE ANY.

      *:--- Record generisch einlesen

      LOOP AT par_table ASSIGNING <zeile>.

      *:--- Felder des Records generisch auslesen

      DO.

      ASSIGN COMPONENT sy-index

      OF STRUCTURE <zeile> TO <field>.

      IF sy-subrc <> 0.

      EXIT.

      ENDIF.

      IF sy-index = 1.

      WRITE:/001 <field>.

      ELSE.

      WRITE: <field>.

      ENDIF.

      ENDDO.

      ENDLOOP.

      ENDMETHOD.

      ENDCLASS.

      TYPES: BEGIN OF table_type,

      name TYPE string,

      gdat LIKE sy-datum,

      END OF table_type.

      DATA: gt_names TYPE STANDARD TABLE OF table_type.

      DATA: gf_names TYPE table_type.

      START-OF-SELECTION.

      gf_names-name = 'Hugo Boss'.

      gf_names-gdat = '19800401'.

      APPEND gf_names TO gt_names.

      gf_names-name = 'Liesschen Fleissig'.

      gf_names-gdat = '19810401'.

      APPEND gf_names TO gt_names.

      END-OF-SELECTION.

      CALL METHOD gcl_lister=>mth_write_list

      EXPORTING par_table = gt_names.

      *

  • Posted on Jun 04, 2004 at 12:06 PM

    Hallo Tobias,

    if you really need a workarea you can also use the following:

    DATA: wa TYPE REF TO data.

    FIELD-SYMBOLS: <wa> TYPE ANY.

    CREATE DATA wa LIKE LINE OF itab.

    ASSIGN wa->* TO <wa>.

    LOOP AT itab INTO <wa>.

    ENDLOOP.

    Regards,

    Oliver

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.