Estava precisando para uma demanda, o nome dos campos de uma tabela interna em tempo de execução e achei essa codificação a mais completa e simples para ser usada......com um resultado bem satisfatório.....
font: http://abap-explorer.blogspot.com.br/2010/01/how-to-get-internal-table-components-at.html
segue o código......
*&---------------------------------------------------------------------*
*& Report ZTEST_INTERNAL_TAB_COMP
*&
*&---------------------------------------------------------------------*
*&***********DEMO Code for http://abap-explorer.blogspot.com/***********
*&
*&---------------------------------------------------------------------*
report ztest_internal_tab_comp line-size 100.type-pools: abap.
*Declare the type of the internal table
types: begin of x_final,
matnr type matnr,
werks type werks_d,
flag type c length 1,
value type p length 10 decimals 2,end of x_final.
data:*The Internal table whose components are to found
i_data type sorted table of x_final with unique key matnr,*Table to hold the components
tab_return type abap_compdescr_tab,*Work area for the component table
components like line of tab_return.
*Call Perform to get the Int. Table Components
perform get_int_table_fields using i_data
changing tab_return.*Display Components
loop at tab_return into components.
write: / components-name, components-type_kind,
components-length,components-decimals.endloop.
*&---------------------------------------------------------------------*
*& Form get_int_table_fields
*&---------------------------------------------------------------------*
* Get the Components of an internal table
*----------------------------------------------------------------------*
* -->T_DATA text
* -->T_RETURN text
*----------------------------------------------------------------------*
form get_int_table_fields using t_data type any table
changing t_return type abap_compdescr_tab.
data:
oref_table type ref to cl_abap_tabledescr,
oref_struc type ref to cl_abap_structdescr,
oref_error type ref to cx_root,
text type string.*Get the description of data object type
try.
oref_table ?=
cl_abap_tabledescr=>describe_by_data( t_data ).
catch cx_root into oref_error.
text = oref_error->get_text( ).
write: / text.
exit.
endtry.*Get the line type
try.
oref_struc ?= oref_table->get_table_line_type( ).
catch cx_root into oref_error.
text = oref_error->get_text( ).
write: / text.
exit.
endtry.
append lines of oref_struc->components to t_return.
endform. " GET_INT_TABLE_FIELDS
Ricardo BHZ
Nenhum comentário:
Postar um comentário