My Table Mover(Part 2)
May 13, 2008Ok, so I finally found some time to write Part 2(took me a couple of months). Part 1 of this blog only dealt with what the Table Mover program does and the broad mechanics used. In this blog I want to discuss the table download mechanism in order to explain some of the dynamic ABAP techniques used.
The first step is to get the list of database tables that need to be downloaded. I did this using a direct select of the Data Dictionary table dd02l. It may have been better to find the appropriate function module.
data: lt_tables type table of dd02l,
ls_tables type dd02l.
select * into table lt_tables from dd02l
where tabname in so_tab
and as4local = 'A'
and tabclass = 'TRANSP'.
The following variables are of importance for what is to follow:
data: lr_table type ref to data. field-symbols: <lt_table> type standard table. field-symbols: <ls_table> type any.
We will then loop at each table name in lt_tables and create a dynamic variable that will contain the data to be selected from the database. The statements below create this variable and can be accessed from field-symbol <lt_table>.
lv_tab = ls_tables-tabname.
create data lr_table type standard table of (lv_tab)
with non-unique default key.
assign lr_table->* to <lt_table>.
The Create Data statement above creates a new variable with the same type as the Data Dictionary definition of the Database Table we want to select from. Then we do a dynamic SQL select into our table <lt_table>.
select * into table <lt_table>
from (lv_tab).
The next step is to build an internal table that will enable us to download the table into a text format. In order to do this you must ensure that each field is converted first into character format. Also, we want to add our separator here.
loop at <lt_table> assigning <ls_table>.
ls_dnl-tabname = lv_tab.
clear: ls_dnl-content, sy-subrc, sep.
while sy-subrc = 0. "Map each component of the structure to a single field
assign component sy-index of structure <ls_table> to <lv_field>.
if sy-subrc = 0.
lv_1024 = <lv_field>. "This is for character conversion.
concatenate ls_dnl-content sep lv_1024 into ls_dnl-content.
sep = c_sep. "Add the separator
endif.
endwhile.
append ls_dnl to lt_dnl.
endloop.
My clever format conversion routine( lv_1024 = <lv_field> ) is not failsafe, and I have not tested it thoroughly, but at least it converts GUIDs, Dates and Numbers to text that will not destroy my download file.
But, the internal table lt_dnl now contains all the entries we want to download. All that remains is to download the table to the front end.
cl_gui_frontend_services=>gui_download(
exporting
filename = lv_name
filetype = 'ASC'
write_field_separator = ' '
changing
data_tab = lt_dnl
Here is the link to the source code of the full report:






