06-01-2004 10:46 AM
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.
06-01-2004 11: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
06-01-2004 12:34 PM
Hi Michael,
so problem is that the internal table i am passing to the method is in deed generic.so i do not know what structure my table has when passing it to the method and so i also do not know how the workarea has to look. so the workarea should be created dynamically when calling the method
06-01-2004 1:44 PM
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.
*
06-04-2004 1: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