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: 

FM for uploading Image to SAP

Former Member
0 Kudos

I have a requirement to upload a image file (JPEG) from local PC to SAP. Are there any Function modules for uploading images to SAP? I searched the forum but couldnt find any.

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate

It depends on where you want to store the image. Do you want to store it in the MIME Repository?

Regards,

Rich Heilman

15 REPLIES 15

RichHeilman
Developer Advocate
Developer Advocate

It depends on where you want to store the image. Do you want to store it in the MIME Repository?

Regards,

Rich Heilman

0 Kudos

Thank you for replying. Well, my requirement here is to import a image file into SAP and store it. From another custom transaction when a user clicks on a button this uploaded graphic must be displayed. Is it possible to do by storing in the MIME repository?

0 Kudos

Yes, you can then retrieve it and then use it in a screen, I believe you can put it in a picture contol.

Here is how to save it in the MIME.

REPORT  zrich_0001.

DATA: lr_mime_rep TYPE REF TO if_mr_api.

DATA: lv_filename TYPE string.
DATA: lv_path     TYPE string.
DATA: lv_fullpath TYPE string.
DATA: lv_content  TYPE xstring.
DATA: lv_length   TYPE i.
DATA: lv_rc TYPE sy-subrc.

DATA: lt_file TYPE filetable.
DATA: ls_file LIKE LINE OF lt_file.


DATA: lt_data TYPE STANDARD TABLE OF x255.

PARAMETERS: p_path TYPE string
             DEFAULT 'SAP/PUBLIC/Test.jpg'.   "<<-- Mime path, save to path


cl_gui_frontend_services=>file_open_dialog(
  CHANGING
    file_table              =  lt_file  " Table Holding Selected Files
    rc                      =  lv_rc  ). " Return Code, Number of Files or -1 If Error Occurred
READ TABLE lt_file INTO ls_file INDEX 1.
IF sy-subrc = 0.
  lv_filename = ls_file-filename.
ENDIF.

cl_gui_frontend_services=>gui_upload(
  EXPORTING
    filename                = lv_filename    " Name of file
    filetype                = 'BIN'
  IMPORTING
    filelength              =  lv_length   " File length
  CHANGING
    data_tab                = lt_data    " Transfer table for file contents
  EXCEPTIONS
    OTHERS                  = 19 ).

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    input_length = lv_length
*    first_line   = 0
*    last_line    = 0
  IMPORTING
    buffer       = lv_content
  TABLES
    binary_tab   = lt_data
  EXCEPTIONS
    failed       = 1
    OTHERS       = 2.

lr_mime_rep = cl_mime_repository_api=>if_mr_api~get_api( ).

lr_mime_rep->put(
  EXPORTING
    i_url                     = p_path
    i_content                 = lv_content
  EXCEPTIONS
    parameter_missing         = 1
    error_occured             = 2
    cancelled                 = 3
    permission_failure        = 4
    data_inconsistency        = 5
    new_loio_already_exists   = 6
    is_folder                 = 7
    OTHERS                    = 8 ).

Regards,

Rich Heilman

0 Kudos

You of course can simply upload the images to the MIME in SE80 as well, you don't have to do it programmatically if not required. Go to SE80, click on the button at the top for MIME Repository, then navigate to a folder in the tree below, you can of course create a new folder to hold your images, and right-click on the folder and choose "Import Mime OBject", choose the file from the dialog, and click open.

Regards,

Rich Heilman

0 Kudos

Thank you very much Rich. This is really helpful. Actually, I am supposed to upload the image programmatically. Thanks again for suggesting this approach. Never tried MIME before.

0 Kudos

And when you are ready to show the image in a picture control on a screen. You can do something like this. This uses a docking container so that you don't have to create a screen, but it works the same way with a customer container.

REPORT  zrich_0001.

DATA: lr_mime_rep TYPE REF TO if_mr_api.

DATA: lv_url TYPE char255.
DATA: lv_content  TYPE xstring.
DATA: lv_repid TYPE sy-repid.

DATA: lt_data TYPE STANDARD TABLE OF x255.

DATA: lo_docking TYPE REF TO cl_gui_docking_container.
DATA: lo_picture TYPE REF TO cl_gui_picture.

DATA: p_path TYPE string VALUE 'SAP/PUBLIC/Test.jpg'.

PARAMETERS: p_check.

AT SELECTION-SCREEN OUTPUT.

* Create controls
  CREATE OBJECT lo_docking
    EXPORTING
      repid     = lv_repid
      dynnr     = sy-dynnr
      side      = lo_docking->dock_at_left
      extension = 200.

  CREATE OBJECT lo_picture
    EXPORTING
      parent = lo_docking.

  lr_mime_rep = cl_mime_repository_api=>if_mr_api~get_api( ).

  lr_mime_rep->get(
             EXPORTING
                  i_url      = p_path
             IMPORTING
                   e_content = lv_content
             EXCEPTIONS
                   not_found = 3 ).

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = lv_content
    TABLES
      binary_tab = lt_data.

  CALL FUNCTION 'DP_CREATE_URL'
    EXPORTING
      type    = 'IMAGE'
      subtype = 'JPG'
    TABLES
      data    = lt_data
    CHANGING
      url     = lv_url.

  lo_picture->load_picture_from_url_async( lv_url ).

Regards,

Rich Heilman

0 Kudos

Thanks again Rich.

0 Kudos

It helped me too.... thanks

0 Kudos

hi,

can we take MIME object to smartforms?? , if yes then kindly explain

thanx,

hasan

0 Kudos

Hi,

is it possible to get the MIME images into smartforms? Do let us know..

Regards,

Simmi

0 Kudos

Hi Rich,

I am completeley new to MIME. As such, I need a little more understanding of the concept used here.

The API cl_gui_frontend_services=>file_open_dialog has two changing parameters. How does the table lt_file get data?

As per the code in the report, I believe the image can directly be stored in the MIME repository, and the following APIs will then convert it into binary format.

Please confirm the understanding.

Thanks and regards,

Romil.

Edited by: romilgoel on Jun 9, 2011 6:09 AM

Edited by: romilgoel on Jun 15, 2011 9:03 AM

0 Kudos

   Hi Rich,

I want to store image in Application server and get the image from Application server through program.

I need to store into SE78 because i have to display Employee photo in Payslip.

Please replyme

Thanks&Regards,

Srinivas.

0 Kudos

Hi Rich,

I have a similar situation, is there an RFC or any FM with which I can upload / change the logo of SAP Easy access in the production system.
Please let me know the steps to follow.

Thank you!


0 Kudos

Hey Rich,

U r the man. cheers

0 Kudos

Hi Samir.

whatever you sent is useful for upload photo into database table..but i should not displayed on SELECTION SCREEN BLOCK  with specified size like KB,etc.

Actually my requirement is...

1)  i need photo Container  with size of 200 X 200 on Selection screen block B1

2) Then i want one push button i.e UPLOAD push button...when click on upload push button,it should go for F4 help for selection of PHOTO. and at the same it should be displayed in the Smartform.