2022 Dec 06 10:33 AM
Hi All,
I have written code to convert and download an internal table to excel.
It works 100% in our dev system, but when the exact same code is executed in our quality system, the full internal table is not converted and downloaded into excel, only the header section (like header and footer) is downloaded (not column headers).
I am using the FM 'SCMS_XSTRING_TO_BINARY' to convert to binary, then download.
After debugging in the qa system, I see that the 'output_length' and the 'binary_table' variables does not change, even if the data is different each time. In dev, depending on the data...'output_length' and the 'binary_table' variables changes accordingly.
I am not sure why this would work in one system and not another.
Please can you assist me in resolving this.
Thanks in Advance.
*...Convert the output to interal XML format
lv_xml_type = if_salv_bs_xml=>c_type_mhtml.
lv_xml = gt_output->to_xml( xml_type = lv_xml_type ).
*...SCMS Conversion for Excel
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xml
IMPORTING
output_length = lv_length
TABLES
binary_tab = lt_bintab.
IF lt_bintab IS NOT INITIAL.
*...Display save dialog window
##NO_TEXT
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = 'Save File'
default_extension = 'XLSX'
default_file_name = 'Title'
initial_directory = 'C:\Temp\'
CHANGING
filename = lv_filename
path = lv_path
fullpath = lv_fullpath.
*...Download File
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = lv_length
filename = lv_fullpath
filetype = 'BIN'
CHANGING
data_tab = lt_bintab
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
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24.
IF sy-subrc <> 0.
*Error Handling
ENDIF.
ENDIF.
2022 Dec 06 1:29 PM
Could you format again the code please? Currently it looks awful with lots of BR tags instead of line breaks.
When you paste code, I found out that it's sometimes better to use Ctrl+Shift+V rather than Ctrl+V.
2022 Dec 08 2:01 PM
Hi, see the following Blog.
https://blogs.sap.com/2022/07/05/how-to-download-data-from-internal-table-to-an-excel-file/