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: 

Open dataset jpg file from AL11 is not usable on abap2xlsx set_media

xiswanto
Active Participant
0 Kudos

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

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos

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.

xiswanto
Active Participant
0 Kudos

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 ).

Sandra_Rossi
Active Contributor

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:

  1. The difference between the two images stored on server versus frontend (respectively 7650 bytes versus 6937), it means that either it's a different image or it was uploaded to the backend incorrectly.
  2. Concerning abap2xlsx, you have demos which work fine. I see these programs below which use SET_MEDIA.

    zdemo_excel16
    zdemo_excel39
    zdemo_excel38
    zdemo_calendar

xiswanto
Active Participant
0 Kudos

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.

abo
Active Contributor
0 Kudos

For upload/download I use tx CG3Z / CG3Y in binary mode, never had an issue.

Sandra_Rossi
Active Contributor

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.