‎2010 Nov 03 8:34 PM
Hi,
Using RTTI, I am trying to download database table data dynamically. I have code that works fine for one table at a time. If I need to download data from multiple tables in one go. How can I do this using RTTI?
Thanks in advance,
VG
My code is...
DATA: go_struct TYPE REF TO cl_abap_structdescr,
go_table TYPE REF TO cl_abap_tabledescr,
gi_data type ref to data.
FIELD-SYMBOLS: <gi_data> TYPE STANDARD TABLE.
* Dynamically getting the line type of the specified table
go_struct ?= cl_abap_typedescr=>describe_by_name( v_tabname ) .
TRY.
CALL METHOD cl_abap_tabledescr=>create
EXPORTING
p_line_type = go_struct
p_table_kind = 'S'
RECEIVING
p_result = go_table.
CATCH cx_sy_table_creation .
*MESSAGE e000 WITH text-004.
ENDTRY.
* creating internal table of table type just created
CREATE DATA gi_data TYPE HANDLE go_table.
* Assigning the internal table to field symbol
ASSIGN gi_data->* TO <gi_data>.
** get the data into the internal table from db table
SELECT * INTO TABLE <gi_data> FROM (v_tabname).
download....
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* filename = 'C:\test.txt'
filename = p_file1
write_field_separator = 'X'
TABLES
data_tab = <gi_data>
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.Edited by: Thomas Zloch on Nov 5, 2010 9:42 AM - please use code tags
‎2010 Nov 05 7:30 AM
Hi,
DATA: go_struct TYPE REF TO cl_abap_structdescr,
go_table TYPE REF TO cl_abap_tabledescr,
gi_data type ref to data.
FIELD-SYMBOLS: <gi_data> TYPE STANDARD TABLE.
LOOP AT GT_TAB_LIST INTO GS_TAB_LIST.
* Dynamically getting the line type of the specified table
go_struct ?= cl_abap_typedescr=>describe_by_name( GS_TAB_LIST-tabname ) .
TRY.
CALL METHOD cl_abap_tabledescr=>create
EXPORTING
p_line_type = go_struct
p_table_kind = 'S'
RECEIVING
p_result = go_table.
CATCH cx_sy_table_creation .
*MESSAGE e000 WITH text-004.
ENDTRY.
* creating internal table of table type just created
CREATE DATA gi_data TYPE HANDLE go_table.
* Assigning the internal table to field symbol
ASSIGN gi_data->* TO <gi_data>.
** get the data into the internal table from db table
SELECT * INTO TABLE <gi_data> FROM ( GS_TAB_LIST-tabname ).
download....
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* filename = 'C:\test.txt'
filename = p_file1
write_field_separator = 'X'
TABLES
data_tab = <gi_data>
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
endloop.
‎2010 Nov 05 7:30 AM
Hi,
DATA: go_struct TYPE REF TO cl_abap_structdescr,
go_table TYPE REF TO cl_abap_tabledescr,
gi_data type ref to data.
FIELD-SYMBOLS: <gi_data> TYPE STANDARD TABLE.
LOOP AT GT_TAB_LIST INTO GS_TAB_LIST.
* Dynamically getting the line type of the specified table
go_struct ?= cl_abap_typedescr=>describe_by_name( GS_TAB_LIST-tabname ) .
TRY.
CALL METHOD cl_abap_tabledescr=>create
EXPORTING
p_line_type = go_struct
p_table_kind = 'S'
RECEIVING
p_result = go_table.
CATCH cx_sy_table_creation .
*MESSAGE e000 WITH text-004.
ENDTRY.
* creating internal table of table type just created
CREATE DATA gi_data TYPE HANDLE go_table.
* Assigning the internal table to field symbol
ASSIGN gi_data->* TO <gi_data>.
** get the data into the internal table from db table
SELECT * INTO TABLE <gi_data> FROM ( GS_TAB_LIST-tabname ).
download....
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* filename = 'C:\test.txt'
filename = p_file1
write_field_separator = 'X'
TABLES
data_tab = <gi_data>
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
endloop.
‎2010 Nov 05 8:00 AM
If I need to download data from multiple tables in one go
By "one go" you mean to download couple internal tables with one GUI_DOWNLOAD fm call? If so, this would mean you need same number of files being generated and packed with i.e ZIP. Then you download this ZIP file.
Otherwise, all you need is to wrap table generation + data extraction + download in loop passing each time different tablename.
Regards
Marcin
‎2010 Nov 05 12:50 PM