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 (rich prog)

Former Member
0 Likes
825

how can i use this prog to download tables with ';'between every field any idea?

report z_dynamic.

type-pools : abap.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

start-of-selection.

perform get_structure.

perform create_dynamic_itab.

perform get_data.

perform write_out.

form get_structure.

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

  • Get the structure of the table.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].

loop at idetails into xdetails.

clear xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

append xfc to ifc.

endloop.

endform.

form create_dynamic_itab.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

endform.

form get_data.

  • Select Data from table.

select * into table <dyn_table>

from (p_table).

endform.

form Write_Out.

  • Write out data from table.

loop at <dyn_table> into <dyn_wa>.

do.

assign component sy-index

of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

write:/ <dyn_field>.

else.

write: <dyn_field>.

endif.

enddo.

endloop.

endform.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
642

Here is the modified program.



report z_dynamic.

type-pools : abap.

field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.

data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.

start-of-selection.

  perform get_structure.
  perform create_dynamic_itab.
  perform get_data.
<b>  perform download_data.</b>

*---------------------------------------------------------------------*
*       FORM get_structure                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form get_structure.

  data : idetails type abap_compdescr_tab,
  xdetails type abap_compdescr.

  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
  ref_table_des ?=
  cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[] = ref_table_des->components[].

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
  endloop.

endform.

*---------------------------------------------------------------------*
*       FORM create_dynamic_itab                                      *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form create_dynamic_itab.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
  exporting
  it_fieldcatalog = ifc
  importing
  ep_table = dy_table.

  assign dy_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

endform.


*---------------------------------------------------------------------*
*       FORM get_data                                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form get_data.

* Select Data from table.
  select * into table <dyn_table>
  from (p_table).

endform.



*---------------------------------------------------------------------*
*       FORM download_data                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
<b>form download_data.

  data: iout type table of string with header line.

  loop at <dyn_table> into <dyn_wa>.
    do.
      assign component sy-index
      of structure <dyn_wa> to <dyn_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      if sy-index = 1.
        iout = <dyn_field>.
      else.
        concatenate iout <dyn_field> into iout separated by ';'.
      endif.
    enddo.
    append iout.
  endloop.

  call function 'GUI_DOWNLOAD'
       exporting
            filename = 'C:text.txt'
       tables
            data_tab = iout.


endform.</b>


Regards,

RIch Heilman

how can i use this prog to download tables with ';'between every field any idea?

report z_dynamic.

type-pools : abap.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

start-of-selection.

perform get_structure.

perform create_dynamic_itab.

perform get_data.

perform write_out.

form get_structure.

data : idetails type abap_compdescr_tab,

xdetails type abap_compdescr.

data : ref_table_des type ref to cl_abap_structdescr.

  • Get the structure of the table.

ref_table_des ?=

cl_abap_typedescr=>describe_by_name( p_table ).

idetails[] = ref_table_des->components[].

loop at idetails into xdetails.

clear xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

append xfc to ifc.

endloop.

endform.

form create_dynamic_itab.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

endform.

form get_data.

  • Select Data from table.

select * into table <dyn_table>

from (p_table).

endform.

form Write_Out.

  • Write out data from table.

loop at <dyn_table> into <dyn_wa>.

do.

assign component sy-index

of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

write:/ <dyn_field>.

else.

write: <dyn_field>.

endif.

enddo.

endloop.

endform.

5 REPLIES 5
Read only

Former Member
0 Likes
642

how in the paramaters i can give him only a list of 10 tables

parameters: p_table(30) type c default 'T001'.

Read only

0 Likes
642

thanks.

what about the second QA.

can i give him list for 10 tables only

Read only

0 Likes
642

You want to have a dropdown of 10 default tables?

Regards,

Rich Heilman

Read only

0 Likes
642



report zrich_0001.

type-pools : abap.

field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.

data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
<b>parameters: p_table as listbox visible length 30.</b>
selection-screen end of block b1.


<b>at selection-screen output.

  perform build_table_drop_down_list.</b>
start-of-selection.

  perform get_structure.
  perform create_dynamic_itab.
  perform get_data.
  perform download_data.

************************************************************************
* build table_drop_down_list
************************************************************************
<b>form build_table_drop_down_list.

type-pools: vrm.

  data: name type vrm_id,
        list type vrm_values,
        value like line of list.


  clear list. refresh list.
  name = 'P_TABLE'.

  clear value.
  value-key = 'T000'.
  value-text = 'T000'.
  append value to list.

  clear value.
  value-key = 'T001'.
  value-text = 'T001'.
  append value to list.

  clear value.
  value-key = 'T001A'.
  value-text = 'T001A'.
  append value to list.

  clear value.
  value-key = 'T001B'.
  value-text = 'T001B'.
  append value to list.

  clear value.
  value-key = 'T001C'.
  value-text = 'T001C'.
  append value to list.

  clear value.
  value-key = 'T001D'.
  value-text = 'T001D'.
  append value to list.

  clear value.
  value-key = 'T001E'.
  value-text = 'T001E'.
  append value to list.

* Set the values
  call function 'VRM_SET_VALUES'
       exporting
            id     = name
            values = list.

endform.</b>

*---------------------------------------------------------------------*
*       FORM get_structure                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form get_structure.

  data : idetails type abap_compdescr_tab,
  xdetails type abap_compdescr.

  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
  ref_table_des ?=
  cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[] = ref_table_des->components[].

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
  endloop.

endform.

*---------------------------------------------------------------------*
*       FORM create_dynamic_itab                                      *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form create_dynamic_itab.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
  exporting
  it_fieldcatalog = ifc
  importing
  ep_table = dy_table.

  assign dy_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

endform.


*---------------------------------------------------------------------*
*       FORM get_data                                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form get_data.

* Select Data from table.
  select * into table <dyn_table>
  from (p_table).

endform.



*---------------------------------------------------------------------*
*       FORM download_data                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form download_data.

data: iout type table of string with header line.

loop at <dyn_table> into <dyn_wa>.
  do.
    assign component sy-index
    of structure <dyn_wa> to <dyn_field>.
    if sy-subrc <> 0.
      exit.
    endif.
    if sy-index = 1.
      iout = <dyn_field>.
    else.
      concatenate iout <dyn_field> into iout separated by ';'.
    endif.
  enddo.
  append iout.
endloop.

call function 'GUI_DOWNLOAD'
     exporting
          filename = 'C:text.txt'
     tables
          data_tab = iout.

endform.

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
643

Here is the modified program.



report z_dynamic.

type-pools : abap.

field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.

data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.

start-of-selection.

  perform get_structure.
  perform create_dynamic_itab.
  perform get_data.
<b>  perform download_data.</b>

*---------------------------------------------------------------------*
*       FORM get_structure                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form get_structure.

  data : idetails type abap_compdescr_tab,
  xdetails type abap_compdescr.

  data : ref_table_des type ref to cl_abap_structdescr.

* Get the structure of the table.
  ref_table_des ?=
  cl_abap_typedescr=>describe_by_name( p_table ).
  idetails[] = ref_table_des->components[].

  loop at idetails into xdetails.
    clear xfc.
    xfc-fieldname = xdetails-name .
    xfc-datatype = xdetails-type_kind.
    xfc-inttype = xdetails-type_kind.
    xfc-intlen = xdetails-length.
    xfc-decimals = xdetails-decimals.
    append xfc to ifc.
  endloop.

endform.

*---------------------------------------------------------------------*
*       FORM create_dynamic_itab                                      *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form create_dynamic_itab.

* Create dynamic internal table and assign to FS
  call method cl_alv_table_create=>create_dynamic_table
  exporting
  it_fieldcatalog = ifc
  importing
  ep_table = dy_table.

  assign dy_table->* to <dyn_table>.

* Create dynamic work area and assign to FS
  create data dy_line like line of <dyn_table>.
  assign dy_line->* to <dyn_wa>.

endform.


*---------------------------------------------------------------------*
*       FORM get_data                                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form get_data.

* Select Data from table.
  select * into table <dyn_table>
  from (p_table).

endform.



*---------------------------------------------------------------------*
*       FORM download_data                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
<b>form download_data.

  data: iout type table of string with header line.

  loop at <dyn_table> into <dyn_wa>.
    do.
      assign component sy-index
      of structure <dyn_wa> to <dyn_field>.
      if sy-subrc <> 0.
        exit.
      endif.
      if sy-index = 1.
        iout = <dyn_field>.
      else.
        concatenate iout <dyn_field> into iout separated by ';'.
      endif.
    enddo.
    append iout.
  endloop.

  call function 'GUI_DOWNLOAD'
       exporting
            filename = 'C:text.txt'
       tables
            data_tab = iout.


endform.</b>


Regards,

RIch Heilman