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 Table Creation

Former Member
0 Likes
1,405

I am trying to create a dynamic table based on a transparent table, but the component table returned by method <b>l_r_structype->get_components( )</b> does not contain the fields in an .include structure.

Does anyone know of a way around this?

  l_r_structype ?= cl_abap_typedescr=>describe_by_name( p_tbl ).

  l_t_comp_tab = l_r_structype->get_components( ).

  LOOP AT l_t_comp_tab INTO l_s_comp_tab.
    WRITE:/ l_s_comp_tab-name.
  ENDLOOP.

LOGDPID          
OBJVERS          
VARIANT          
SOURCE           
TYP              
LOGSYS           
LOGDPID_N        
FIRSTFLAG        
UNAME            
TIMESTAMP        
OLTPSOURCE       
OLTPTYP          
GENERATED        
CRT_PACKAGE      

From FM DB_GET_TABLE_FIELDS (included fields are bold-faced):

LOGDPID                 
OBJVERS                 
VARIANT                 
SOURCE                  
TYP                     
LOGSYS                  
LOGDPID_N               
FIRSTFLAG               
UNAME                   
TIMESTAMP       
<b>        
OBJSTAT                 
CONTREL                 
CONTTIMESTMP            
OWNER                   
BWAPPL                  
</b>
OLTPSOURCE              
OLTPTYP                 
GENERATED               
CRT_PACKAGE             

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,310

Please see the example program. Does this pull all of the fields?




report zrich_0001 .


type-pools : abap.

data : it_details type abap_compdescr_tab,
       wa_details type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.

selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.

* Get the structure of the table.
<b>ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].</b>

loop at it_details into wa_details.
  write:/ wa_details-name.
endloop.

Regards,

Rich Heilman

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,311

Please see the example program. Does this pull all of the fields?




report zrich_0001 .


type-pools : abap.

data : it_details type abap_compdescr_tab,
       wa_details type abap_compdescr.

data : ref_descr type ref to cl_abap_structdescr.

selection-screen begin of block b1 with frame title text .
parameters: p_table(30) type c.
selection-screen end of block b1.

* Get the structure of the table.
<b>ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].</b>

loop at it_details into wa_details.
  write:/ wa_details-name.
endloop.

Regards,

Rich Heilman

Read only

0 Likes
1,310

It sure does. Thanks. I'll have to study it to see how it differs.

Read only

0 Likes
1,310

What is your DATA statment for l_r_structype?

Regards,

Rich Heilman

Read only

0 Likes
1,310

It is

l_r_structype        TYPE REF TO cl_abap_structdescr,

Seems similar to your:

data : ref_descr type ref to cl_abap_structdescr.

statement.

Read only

0 Likes
1,310

What version of SAP are you on?

Regards,

Rich Heilman

Read only

0 Likes
1,310

My version gets the component table from a method call

l_t_comp_tab = l_r_structype->get_components( ).

whereas yours references it directly.

it_details[] = ref_descr->components[].

I wonder if that is the difference.

Read only

0 Likes
1,310

We're on BW, kernel version 6.40

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,310

In my 46c system, It doesn't seem that the method get_components exists for this class.

Regards.

Rich Heilman

Read only

Former Member
0 Likes
1,310

This code will help you to create a workarea and display the contents of the transparent table you specify.

************************************

REPORT ZMART_DYNAMIC_TABLE .

PARAMETERS : tname(30).

DATA: dref TYPE REF TO DATA,tab type ref to data.

*data tname TYPE string.

field-symbols : <f> TYPE any,<fc> type any,<fcd>,<ft> type standard table.

*tname = TABNAME.

CREATE DATA dref TYPE (tname).

ASSIGN dref->* TO <f>.

create data tab like table of <f>.

assign tab->* to <ft>.

SELECT * INTO table <ft> from (tname).

LOOP AT <ft> INTO <f>.

do.

assign component sy-index

of structure <f> to <fcd>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

write:/ <fcd>.

else.

write: <fcd>.

endif.

enddo.

ENDLOOP.

Please reward points if find informative.