Application Development 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: 

How to download table schema into excel file.

harshvardhangholap
Discoverer
0 Kudos

I need to download table schem with all details like fieldname, datatype, lenght and description. I have created a program which exposes table schema into an ALV and from there we can export the file. But is there any more effective way to do that or any standard functionality?

DATA: OUTTAB TYPE TABLE OF DFIES,
TNAME TYPE DDOBJNAME.

DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.


PARAMETERS: p_tname TYPE TNAME, "name of table entered by user
P_FNAME TYPE STRING."RLGRAP-FILENAME.

CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = p_tname
TABLES
DFIES_TAB = OUTTAB.


wa_fieldcat-fieldname = 'TABNAME'.
wa_fieldcat-seltext_m = 'Table Name'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'FIELDNAME'.
wa_fieldcat-seltext_m = 'Field Name'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'LANGU'.
wa_fieldcat-seltext_m = 'Language Key'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'POSITION'.
wa_fieldcat-seltext_m = 'Position'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'OFFSET'.
wa_fieldcat-seltext_m = 'Offset'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'DOMNAME'.
wa_fieldcat-seltext_m = 'Domain Name'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'ROLLNAME'.
wa_fieldcat-seltext_m = 'Roll Name'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'CHECKTABLE'.
wa_fieldcat-seltext_m = 'Check Table'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'LENG'.
wa_fieldcat-seltext_m = 'Length'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'INTLEN'.
wa_fieldcat-seltext_m = 'Internal Length'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'OUTPUTLEN'.
wa_fieldcat-seltext_m = 'Output Length'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'DECIMALS'.
wa_fieldcat-seltext_m = 'Decimal Places'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'DATATYPE'.
wa_fieldcat-seltext_m = 'Data Type'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'INTTYPE'.
wa_fieldcat-seltext_m = 'Internal Type'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'REFTABLE'.
wa_fieldcat-seltext_m = 'Reference Table'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'REFFIELD'.
wa_fieldcat-seltext_m = 'Reference Field'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'PRECFIELD'.
wa_fieldcat-seltext_m = 'Precision Field'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'AUTHORID'.
wa_fieldcat-seltext_m = 'Author ID'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'MEMORYID'.
wa_fieldcat-seltext_m = 'Memory ID'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'LOGFLAG'.
wa_fieldcat-seltext_m = 'Log Flag'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'MASK'.
wa_fieldcat-seltext_m = 'Mask'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'MASKLEN'.
wa_fieldcat-seltext_m = 'Mask Length'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'CONVEXIT'.
wa_fieldcat-seltext_m = 'Conversion Exit'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'HEADLEN'.
wa_fieldcat-seltext_m = 'Header Length'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'SCRLEN1'.
wa_fieldcat-seltext_m = 'Screen Length 1'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'SCRLEN2'.
wa_fieldcat-seltext_m = 'Screen Length 2'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'SCRLEN3'.
wa_fieldcat-seltext_m = 'Screen Length 3'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'FIELDTEXT'.
wa_fieldcat-seltext_m = 'Field Text'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'REPTEXT'.
wa_fieldcat-seltext_m = 'Report Text'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'SCRTEXT_S'.
wa_fieldcat-seltext_m = 'Short Description'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'SCRTEXT_M'.
wa_fieldcat-seltext_m = 'Medium Description'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'SCRTEXT_L'.
wa_fieldcat-seltext_m = 'Long Description'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'KEYFLAG'.
wa_fieldcat-seltext_m = 'Key Flag'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'LOWERCASE'.
wa_fieldcat-seltext_m = 'Lowercase Flag'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'MAC'.
wa_fieldcat-seltext_m = 'Macintosh Flag'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'GENKEY'.
wa_fieldcat-seltext_m = 'Generated Key'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'NOFORKEY'.
wa_fieldcat-seltext_m = 'No Foreign Key'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'VALEXI'.
wa_fieldcat-seltext_m = 'Validity Area'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'NOAUTHCH'.
wa_fieldcat-seltext_m = 'No Authorization Check'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'SIGN'.
wa_fieldcat-seltext_m = 'Sign'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'DYNPFLD'.
wa_fieldcat-seltext_m = 'Dynamically Field'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'F4AVAILABL'.
wa_fieldcat-seltext_m = 'F4 Help Availability'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'COMPTYPE'.
wa_fieldcat-seltext_m = 'Component Type'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'LFIELDNAME'.
wa_fieldcat-seltext_m = 'Long Field Name'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'LTRFLDDIS'.
wa_fieldcat-seltext_m = 'Long Field Description'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'BIDICTRLC'.
wa_fieldcat-seltext_m = 'Bidirectional Control'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'OUTPUTSTYLE'.
wa_fieldcat-seltext_m = 'Output Style'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'NOHISTORY'.
wa_fieldcat-seltext_m = 'No History'.
APPEND wa_fieldcat TO it_fieldcat.

wa_fieldcat-fieldname = 'AMPMFORMAT'.
wa_fieldcat-seltext_m = 'AM/PM Format'.
APPEND wa_fieldcat TO it_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = it_fieldcat
TABLES
t_outtab = OUTTAB
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.


Thanks and Regards,

Harsha.

1 ACCEPTED SOLUTION

jens_michaelsen
Participant
DATA: o_salv TYPE REF TO cl_salv_table.
DATA: outtab TYPE TABLE OF dfies.
* Fields for saving dialogue
DATA: lv_action TYPE i.
DATA: lv_filename TYPE string.
DATA: lv_fullpath TYPE string.
DATA: lv_path TYPE string.
PARAMETERS: p_tname TYPE tname. "name of table entered by user.
PARAMETERS: p_disp AS CHECKBOX, "option for display the result
p_down AS CHECKBOX. "option for save the result in xls
START-OF-SELECTION.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = p_tname
TABLES
dfies_tab = outtab.

cl_salv_table=>factory( IMPORTING
r_salv_table = o_salv
CHANGING
t_table = outtab ).


IF p_disp = abap_true.
o_salv->display( ).
ENDIF.
IF p_down = abap_true.
TRY.
DATA(lv_bin_data) = o_salv->to_xml( xml_type = if_salv_bs_xml=>c_type_xlsx ).

* Dialog for saving the file
cl_gui_frontend_services=>file_save_dialog( EXPORTING
default_file_name = 'Excel.xlsx'
default_extension = 'xlsx'
file_filter = |Excel-Datei (*.xlsx)\|*.xlsx\|{ cl_gui_frontend_services=>filetype_all }|
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
user_action = lv_action ).

IF lv_action EQ cl_gui_frontend_services=>action_ok.
* convert XSTRING -> SOLIX (RAW)
DATA(it_raw_data) = cl_bcs_convert=>xstring_to_solix( EXPORTING iv_xstring = lv_bin_data ).

* Save the file
cl_gui_frontend_services=>gui_download( EXPORTING
filename = lv_fullpath
filetype = 'BIN'
bin_filesize = xstrlen( lv_bin_data )
CHANGING
data_tab = it_raw_data ).
ENDIF.
CATCH cx_root INTO DATA(e_text).
MESSAGE e_text->get_text( ) TYPE 'I'.
ENDTRY.
ENDIF.

You can use a SALV to display and download your internal table.





2 REPLIES 2

jens_michaelsen
Participant
DATA: o_salv TYPE REF TO cl_salv_table.
DATA: outtab TYPE TABLE OF dfies.
* Fields for saving dialogue
DATA: lv_action TYPE i.
DATA: lv_filename TYPE string.
DATA: lv_fullpath TYPE string.
DATA: lv_path TYPE string.
PARAMETERS: p_tname TYPE tname. "name of table entered by user.
PARAMETERS: p_disp AS CHECKBOX, "option for display the result
p_down AS CHECKBOX. "option for save the result in xls
START-OF-SELECTION.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = p_tname
TABLES
dfies_tab = outtab.

cl_salv_table=>factory( IMPORTING
r_salv_table = o_salv
CHANGING
t_table = outtab ).


IF p_disp = abap_true.
o_salv->display( ).
ENDIF.
IF p_down = abap_true.
TRY.
DATA(lv_bin_data) = o_salv->to_xml( xml_type = if_salv_bs_xml=>c_type_xlsx ).

* Dialog for saving the file
cl_gui_frontend_services=>file_save_dialog( EXPORTING
default_file_name = 'Excel.xlsx'
default_extension = 'xlsx'
file_filter = |Excel-Datei (*.xlsx)\|*.xlsx\|{ cl_gui_frontend_services=>filetype_all }|
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath
user_action = lv_action ).

IF lv_action EQ cl_gui_frontend_services=>action_ok.
* convert XSTRING -> SOLIX (RAW)
DATA(it_raw_data) = cl_bcs_convert=>xstring_to_solix( EXPORTING iv_xstring = lv_bin_data ).

* Save the file
cl_gui_frontend_services=>gui_download( EXPORTING
filename = lv_fullpath
filetype = 'BIN'
bin_filesize = xstrlen( lv_bin_data )
CHANGING
data_tab = it_raw_data ).
ENDIF.
CATCH cx_root INTO DATA(e_text).
MESSAGE e_text->get_text( ) TYPE 'I'.
ENDTRY.
ENDIF.

You can use a SALV to display and download your internal table.





Sandra_Rossi
Active Contributor

You are asking "Is there any more effective way to do that or any standard functionality?"

YES THERE IS !

As you can in ALL latest answers, please stop using this obsolete REUSE_ALV_GRID_DISPLAY function module.

With CL_SALV_TABLE, you can get rid of all the lines of code about field catalog.

NB: I don't see the relationship between your code and your question.