2023 Nov 28 4:05 AM
Hello,
Not sure if I am using the wrong way to get the binary value from AL11.
In my test, I tried to get the binary value from jpg file stored in AL11 directly using below statement, which return lc_len = 7650 with 30 rows in the lc_bin
DATA: z_file TYPE string VALUE 'smallLogo2.jpg',
z_len TYPE i,
wa_bin LIKE LINE OF lc_bin.
OPEN DATASET z_file FOR INPUT IN BINARY MODE .
IF sy-subrc IS INITIAL.
DO.
READ DATASET z_file INTO wa_bin ACTUAL LENGTH z_len.
IF sy-subrc IS INITIAL.
ADD z_len TO lc_len.
APPEND wa_bin TO lc_bin.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET z_file.
However, when I compare the length of binary content from AL11 with the one from my local file which I get using below, the length is different ( the local one length is 6937 with 28 rows in lc_bin)
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = 'D:\Library\Desktop\img 2.jpg'
filetype = 'BIN'
IMPORTING
filelength = lc_len
CHANGING
data_tab = lc_bin
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
Which then, I proceed convert the binary to xstring as below for both code above
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lc_len
IMPORTING
buffer = lc_content
TABLES
binary_tab = lc_bin
EXCEPTIONS
failed = 1
OTHERS = 2.
I am using the same file, so shouldn't the length and rows of binary content be the same? Or did I misunderstand in some part?
I am trying to use the xstring value on abap2xlsx set_media method, the content from local file is displayed correctly, but not displaying for the AL11 one.
Regards,
Sis
2023 Nov 28 5:56 PM
It's much more simple: to read binary, you don't need to loop, instead you do one read into an XSTRING variable, and that's it. No need of converting a table too.
2023 Nov 29 2:23 AM
Hi sandra.rossi,
Per suggestion, I modified the code into this without conversion to xstring (since IN TEXT MODE, I can't pass into lc_content); but still, the excel file output is unable to display the image.
DATA: z_file TYPE string VALUE 'smallLogo.bmp'.
"FILE FROM AL11
OPEN DATASET z_file FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
READ DATASET z_file INTO lc_content.
CLOSE DATASET z_file.
ENDIF.
I'm setting the image using this same method
o_zdrawing->set_media( ip_media = lc_content
ip_media_type = zcl_excel_drawing=>c_media_type_bmp
ip_width = 83 ip_height = 160 ).
2023 Nov 29 8:19 AM
As your code was only about reading a file in binary mode, I focused on that point.
For the rest, I see 2 left points in your question:
2023 Nov 30 1:29 AM
sandra.rossi,
well regarding point 1, I'm uploading the image using program CACS_FILE_COPY from local to server, which then I use the same program to copy the same image from server to local again with different name (at this point, the image look the same but the length in server is different with local size, I think the 17987 is the byte?)
I do take a look at how program CACS_FILE_COPY work, from which then I add converting string to xstring, but same result.
as for point 2, so far the demo is about local file, mime, or smw0, but I'll keep looking further.
2023 Nov 30 7:20 AM
For upload/download I use tx CG3Z / CG3Y in binary mode, never had an issue.
2023 Nov 30 8:32 AM
If the file on your lapttop is 9729 bytes, it should be exactly 9729 bytes on the server too...
I would never trust something I don't know, and I don't know CACS_FILE_COPY.
You're a developer, do the program to upload the file. Ask your company which official tool they use to upload and download files.