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

Former Member
0 Likes
430

Hi All,

I have created a dynamic table. I could like to read the component name of the dynamic table. How should i do this.

Thanks.

Regards,

Swarna

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
383

If you requirement is to be able to read back the components of the dynamic internal table that you created, you can do something like this. I have taken Eswar's example and expanded on it a little.



report zrich_0001.

data: gt_fieldcat type lvc_t_fcat,
      gt_table type ref to data.
data: ls_fieldcat type lvc_s_fcat.

field-symbols: <gt_table> type table.

data: it_dfies like dfies occurs 0 with header line,
<b>      lv_table type ddobjname value 'T001'.</b>




call function 'DDIF_NAMETAB_GET'
     exporting
          tabname   = lv_table
     tables
          dfies_tab = it_dfies
     exceptions
          not_found = 1
          others    = 2.
if sy-subrc <> 0.
endif.

loop at it_dfies.
  ls_fieldcat-fieldname = it_dfies-fieldname.
  ls_fieldcat-inttype = it_dfies-inttype.
  ls_fieldcat-outputlen = it_dfies-outputlen.
  append ls_fieldcat to gt_fieldcat.
endloop.


call method cl_alv_table_create=>create_dynamic_table
  exporting
    it_fieldcatalog = gt_fieldcat
  importing
    ep_table        = gt_table.

assign gt_table->* to <gt_table>.

select *
from (lv_table)
into table <gt_table>.

<b>data:  descr_ref type ref to cl_abap_typedescr.
data:  descrt_ref type ref to cl_abap_tabledescr.
data:  descr_key type abap_keydescr.

descr_ref = cl_abap_typedescr=>describe_by_data( <gt_table> ).
descrt_ref ?= descr_ref.

loop at descrt_ref->key into descr_key.
  write:/ descr_key-name.
endloop.</b>

REgards,

Rich Heilman

2 REPLIES 2
Read only

Former Member
0 Likes
383
HI

  Welcome to SDN.

  Hope the below code will help you.


data: gt_fieldcat type LVC_T_FCAT,
      gt_table type ref to data.
data: ls_fieldcat type lvc_s_fcat.

field-symbols: <gt_table> type table.

data: it_dfies like dfies occurs 0 with header line,
      lv_table type ddobjname.

select single kotab from t681 into lv_table
       where kvewe = 'A' and kotabnr = '005' and kappl = 'V'.

CALL FUNCTION 'DDIF_NAMETAB_GET'
  EXPORTING
    TABNAME           = lv_table
 TABLES
   DFIES_TAB         = it_dfies
 EXCEPTIONS
   NOT_FOUND         = 1
   OTHERS            = 2.
IF SY-SUBRC <> 0.
ENDIF.

  loop at it_dfies.
       ls_fieldcat-fieldname = it_dfies-fieldname.
       ls_fieldcat-inttype = it_dfies-inttype.
       ls_fieldcat-outputlen = it_dfies-outputlen.
       append ls_fieldcat to gt_fieldcat.
  endloop.


CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog = gt_fieldcat
  IMPORTING
    ep_table        = gt_table.

ASSIGN gt_table->* TO <gt_table>.

  SELECT *
  FROM (lv_table)
  into table <gt_table>.

loop at <gt_table> assigning <wa_table>.
  l_num = 1.
  do.
   assign component l_num of structure <wa_table> to <temp>.
   if sy-subrc eq 0.
   write: <temp>.
   l_num = l_num + 1.
   else.
   exit.
   endif.
 enddo.
endloop.

Kind Regards
Eswar

Message was edited by: Eswar Rao Boddeti

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
384

If you requirement is to be able to read back the components of the dynamic internal table that you created, you can do something like this. I have taken Eswar's example and expanded on it a little.



report zrich_0001.

data: gt_fieldcat type lvc_t_fcat,
      gt_table type ref to data.
data: ls_fieldcat type lvc_s_fcat.

field-symbols: <gt_table> type table.

data: it_dfies like dfies occurs 0 with header line,
<b>      lv_table type ddobjname value 'T001'.</b>




call function 'DDIF_NAMETAB_GET'
     exporting
          tabname   = lv_table
     tables
          dfies_tab = it_dfies
     exceptions
          not_found = 1
          others    = 2.
if sy-subrc <> 0.
endif.

loop at it_dfies.
  ls_fieldcat-fieldname = it_dfies-fieldname.
  ls_fieldcat-inttype = it_dfies-inttype.
  ls_fieldcat-outputlen = it_dfies-outputlen.
  append ls_fieldcat to gt_fieldcat.
endloop.


call method cl_alv_table_create=>create_dynamic_table
  exporting
    it_fieldcatalog = gt_fieldcat
  importing
    ep_table        = gt_table.

assign gt_table->* to <gt_table>.

select *
from (lv_table)
into table <gt_table>.

<b>data:  descr_ref type ref to cl_abap_typedescr.
data:  descrt_ref type ref to cl_abap_tabledescr.
data:  descr_key type abap_keydescr.

descr_ref = cl_abap_typedescr=>describe_by_data( <gt_table> ).
descrt_ref ?= descr_ref.

loop at descrt_ref->key into descr_key.
  write:/ descr_key-name.
endloop.</b>

REgards,

Rich Heilman