Para crear una tabla
interna dinámicamente hacemos lo siguiente:
FIELD-SYMBOLS: <lt_table> TYPE table,
<l_disp> TYPE table,
<l_line> TYPE ANY,
<fs_xlsdata> TYPE ANY.
<l_disp> TYPE table,
<l_line> TYPE ANY,
<fs_xlsdata> TYPE ANY.
DATA : lt_fieldcat TYPE lvc_t_fcat,
ls_fieldcat LIKE LINE OF lt_fieldcat,
indice(2) TYPE c,
cad(2) TYPE c.
DATA ls_layout TYPE lvc_s_layo.
DATA: gs_fieldcat TYPE lvc_s_fcat.
DATA: gt_fieldcat TYPE lvc_t_fcat.
DATA: lt_data TYPE REF TO data,
out_line TYPE REF TO data,
wa_fieldcat LIKE LINE OF lt_fieldcat,
l_objtab LIKE STANDARD TABLE OF ddfieldin,
wa_objtab LIKE LINE OF l_objtab,
ws_count(3) TYPE c VALUE '1',
wa_gxxltv TYPE gxxlt_v.
DATA: lv_ncampo(20) TYPE c.
ls_fieldcat LIKE LINE OF lt_fieldcat,
indice(2) TYPE c,
cad(2) TYPE c.
DATA ls_layout TYPE lvc_s_layo.
DATA: gs_fieldcat TYPE lvc_s_fcat.
DATA: gt_fieldcat TYPE lvc_t_fcat.
DATA: lt_data TYPE REF TO data,
out_line TYPE REF TO data,
wa_fieldcat LIKE LINE OF lt_fieldcat,
l_objtab LIKE STANDARD TABLE OF ddfieldin,
wa_objtab LIKE LINE OF l_objtab,
ws_count(3) TYPE c VALUE '1',
wa_gxxltv TYPE gxxlt_v.
DATA: lv_ncampo(20) TYPE c.
Añadimos los campos indicando el nombre de la columna, el
tipo de dato y la longitud
* Añadimos los campos generales
LOOP AT r_campos.
gs_fieldcat-fieldname = r_campos-low.
gs_fieldcat-outputlen = r_campos-high+4(3).
gs_fieldcat-datatype = r_campos-high(4).
CLEAR gs_fieldcat-col_pos.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
ENDLOOP.
LOOP AT r_campos.
gs_fieldcat-fieldname = r_campos-low.
gs_fieldcat-outputlen = r_campos-high+4(3).
gs_fieldcat-datatype = r_campos-high(4).
CLEAR gs_fieldcat-col_pos.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
ENDLOOP.
Generamos la estructura de la tabla interna con el siguiente
método
* create dynamic table with the frontend fieldcatalog
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fieldcat
IMPORTING
ep_table = lt_data
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fieldcat
IMPORTING
ep_table = lt_data
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
A partir de la estructura generada creamos la tabla interna y
una línea de cabecera utilizando field-simbols.
IF sy-subrc EQ 0.
ASSIGN lt_data->* TO <lt_table>.
ENDIF.
CREATE DATA out_line LIKE LINE OF <lt_table>.
ASSIGN out_line->* TO <l_line>.
No hay comentarios:
Publicar un comentario