Application Development and Automation 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: 
Read only

Dynamic Internal Table Columns

Former Member
0 Likes
472

Hello,

I have the following code:


DATA: it_dy       TYPE REF TO data,
      wa_dy       TYPE REF TO data,
      i_fieldlist LIKE  lvc_t_fcat.

FIELD-SYMBOLS: <fs_it> TYPE table.
FIELD-SYMBOLS: <fs_wa> TYPE ANY.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = i_fieldlist
    IMPORTING
      ep_table                  = it_dy
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.
  IF sy-subrc  0.
    STOP.
  ENDIF.

ASSIGN it_dy->* TO <fs_it>.

CREATE DATA wa_dy LIKE LINE OF <fs_it>.
ASSIGN wa_dy->* TO <fs_wa>.

Lets suppose that i_fieldlist is correctly filled.

I want to access a certain column of my dynamic internal table (<fs_it>).

I can get the fieldname from the table i_fieldlist, and put it in a auxiliar variable (fieldname) and i wanna do something like this:


LOOP AT <fs_it> INTO <fs_wa>.
	WRITE : / <fs_it>-(fieldname). "ERROR
ENDLOOP.

But in this way its not possible. How can I do this?

Regards,

Pedro Bessa.

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
451

You have to assign that field to another Field-symbol.

Like:


LOOP AT <fs_it> INTO <fs_wa>.
    ASSIGN COMPONENT: fieldname OF STRUCTURE <fs_wa>  TO <fs_field>.
    WRITE : / <fs_field>.
ENDLOOP.

Regards,

Naimesh Patel

3 REPLIES 3
Read only

naimesh_patel
Active Contributor
0 Likes
452

You have to assign that field to another Field-symbol.

Like:


LOOP AT <fs_it> INTO <fs_wa>.
    ASSIGN COMPONENT: fieldname OF STRUCTURE <fs_wa>  TO <fs_field>.
    WRITE : / <fs_field>.
ENDLOOP.

Regards,

Naimesh Patel

Read only

0 Likes
451

Thanks Naimesh.

I can only test tomorrow.

I'll give news.

Regards,

Pedro Bessa

Read only

Former Member
0 Likes
451

Hi,

You will have to use assign component statement here, because with field symbols, the fields are not deteremined until runtime and therefore you are getting that error.. Change your code as follows :


field-symbols :<fs_field> type any.

LOOP AT <fs_it> INTO <fs_wa>.
	assign component (fieldname) of structure <fs_wa> to <fs_field>.
        if <fs_field> is assigned.
        WRITE : / <fs_field>.
        endif. 
ENDLOOP.

Hope this helps.

Best way would be to use an inner loop at the i_fieldlist and use the field name from that table instead of hard coding the field.


LOOP AT <fs_it> INTO <fs_wa>.
        loop at it_fieldlist.
	 assign component it_fieldlist-fieldname of structure <fs_wa> to <fs_field>.
         if <fs_field> is assigned.
         WRITE : <fs_field>.
        endif. 
        endloop.
        skip 1.
endloop.

regards,

Advait

Edited by: Advait Gode on Feb 12, 2009 9:47 PM