Skip to Content
author's profile photo
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 comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • author's profile photo
    Former Member
    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 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.

      *

  • 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 comment
    10|10000 characters needed characters exceeded