on 2022 Nov 17 9:46 AM
Hi,
I have an extract program in SAP used to extract data for e.g. demergers.
The file exports work perfectly for text, PDF, etc, but not for Excel files, and I can't see why.
When the Excel files are downloaded to my temp folder, they end up corrupted - see screenshot. I include some code below.
Process and problems:
Once I have a FI relevant document, I read the attachment into SAP using FM SO_DOCUMENT_READ_API1. This is working absolutely fine.
Then I write this file to the local drive using FM
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = lv_binsize
FILENAME = lv_binfilename
FILETYPE = lv_filetype
TABLES
DATA_TAB = lt_solixtab
Now, I have 2 versions in the code that allow me to call the gui_download with either the lt_obj_cont table or the lt_solixtab data from the read FM in debug mode to try to get something to work.
They differ as the solix table is hex.
The binsize is not correct for a BIN file type, but I make it 0 in debugger and it doesn’t dump.
The filetype is normally BIN, DAT, ASC (it will default to XLS and this will dump, I just change it in debug).
The problem I have is that the file will download to my local drive as an .xls, but is totally corrupted.
I have tried every filetype and nothing works.
Is there a need to convert this table from SO_DOCUMENT_READ_API1 (either lt_obj_cont table or the lt_solixtab ) into another format before saving it?CODE:
*"PDF Finance Attachments Exports
If rb_fiatt = 'X'.
DATA: lv_filelength type i.
Select * from bkpf
where bkpf~gjahr in @sgjahr
and bkpf~belnr in @sbelnr
and bkpf~cpudt in @serdat
and bkpf~bukrs = @sbukrs
into @ls_bkpf.
Append ls_bkpf to lt_bkpf.
Endselect.
Loop at lt_bkpf into ls_bkpf.
Concatenate ls_bkpf-bukrs ls_bkpf-belnr ls_bkpf-gjahr into lv_instid_a.
Select single instid_b
into lv_instid_b
from srgbtbrel
where reltype = 'ATTA'
and instid_a = lv_instid_a.
IF sy-subrc = 0. "attachment exists
"read attachment
Move lv_instid_b to lv_document_id.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = lv_document_id
IMPORTING
document_data = ls_document_data
TABLES
object_header = lt_obj_head
object_content = lt_obj_cont
contents_hex = lt_solixtab
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
"convert data
If rb_local = 'X'.
"get filetype
" Move lv_binlength to lv_binsize.
concatenate 'c:/temp/' lv_instid_a '.' ls_document_data-obj_type into lv_binfilename.
lv_filetype = ls_document_data-obj_type.
move ls_document_data-doc_size to lv_filelength.
move ls_document_data-doc_size to lv_binsize.
If lv_filetype = 'XLS'.
" Use hex.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = lv_binsize
FILENAME = lv_binfilename
FILETYPE = lv_filetype
TABLES
DATA_TAB = lt_solixtab
.
Else.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = lv_binsize
FILENAME = lv_binfilename
FILETYPE = lv_filetype
TABLES
DATA_TAB = lt_obj_cont
.
Endif.
If sy-subrc NE 0.
"error handling
Endif.
Endif."local
Endif. "attachment
ENDLOOP. "lt_bkpf
Endif. "rb_fiatt
"/PDF Finance ttachments Exports
"**********************************************************************
Request clarification before answering.
Hi,
I just tried it on my system and it worked ok, file opens in Excel no problems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
120 | |
9 | |
8 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.