ABAP Create Excel Download button at Selection Screen
ABAP Tips No Comments »If you want to create Excel download button at selection screen, you can check below method.
TABLES: sscrfields.
INITIALIZATION.
PERFORM init_data.
PERFORM file_download.
*&———————————————————————*
*& Form INIT_DATA
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM INIT_DATA .
sscrfields-functxt_01 = text-f01.
ENDFORM. ” INIT_DATA
*&———————————————————————*
*& Form FILE_DOWNLOAD
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM FILE_DOWNLOAD .
DATA : t_dfname TYPE rlgrap-filename VALUE ‘C:\’,
t_filename TYPE string.
* download file name
CALL FUNCTION ‘F4_FILENAME’
EXPORTING
program_name = sy-repid
dynpro_number = sy-dynnr
IMPORTING
file_name = t_dfname.
* file name
t_filename = t_dfname.
IF t_filename IS INITIAL OR
t_filename = ‘C:\’.
MESSAGE ‘파일 경로를 입력해 주세요.’ TYPE ‘I’.
STOP.
ENDIF.
* download template
CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
filename = t_filename
filetype = ‘DAT’
TABLES
data_tab = <gt_table>.
CALL FUNCTION ‘MS_EXCEL_OLE_STANDARD_DAT’
EXPORTING
file_name = t_dfname
TABLES
data_tab = <gt_table>
fieldnames = it_head
EXCEPTIONS
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_pivot_fields = 6
download_problem = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ‘Excel Open Error’ TYPE ‘I’. “#EC NOTEXT
STOP.
ENDIF.
ENDFORM. ” FILE_DOWNLOAD
Recent Comments