Skip to Content
0
Sep 09, 2009 at 01:55 PM

Columns in a dynamic table

18 Views

Hi guys!

I'm working with field symbols and dynamic tables and i have this code:

REPORT zpractica03.

PARAMETERS: p_tabla TYPE dd02l-tabname.

DATA: tabla_name TYPE dd02l-tabname,

tabla_generica TYPE REF TO data,

linea_generica TYPE REF TO data.

FIELD-SYMBOLS: <fs_tabla> TYPE ANY TABLE,

<fs_linea> TYPE ANY,

<fs_campo> TYPE ANY.

tabla_name = p_tabla.

CREATE DATA tabla_generica TYPE STANDARD TABLE OF (tabla_name).

ASSIGN tabla_generica->* TO <fs_tabla>.

CREATE DATA linea_generica TYPE (tabla_name).

ASSIGN linea_generica->* TO <fs_linea>.

SELECT *

INTO CORRESPONDING FIELDS OF TABLE <fs_tabla>

FROM (tabla_name).

DATA: lv_indice_campo TYPE sy-tabix,

lv_valor_campo.

LOOP AT <fs_tabla> INTO <fs_linea>.

CLEAR lv_indice_campo.

lv_indice_campo = sy-tabix.

ASSIGN COMPONENT lv_indice_campo OF STRUCTURE <fs_linea> TO <fs_campo>.

IF sy-subrc EQ 0.

MOVE <fs_campo> TO lv_valor_campo.

ENDIF.

ENDLOOP.

In the last step, I know that I need something like this in order to get one line and save the info in a workarea and then create an ALV :

Do n Times

ASSIGN COMPONENT lv_indice_campo OF STRUCTURE <fs_linea> TO <fs_campo>.

IF sy-subrc EQ 0.

MOVE <fs_campo> TO lv_valor_campo.

ENDIF.

Enddo.

What I don't know how to do is how can I get the number 'N' ? Can somebody explain me how can I get the number of the columns in a table that can be different any time that i run the program?

Thank you very much.

Gaby