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: 

creating a workare from a generic internal table

Former Member
0 Kudos

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.

4 REPLIES 4

Former Member
0 Kudos

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

0 Kudos

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

0 Kudos

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.

*

olivergrande
Associate
Associate
0 Kudos

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