Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
Thank you,
The SAP Community team.
The SAP Community wiki will be closed to new content submissions from December 7 6:00 p.m. CET to December 11 6:00 p.m. CET.
All content created during this period will not be available/restorable after December 11.
We apologize for the inconvenience, but we need to take this action to improve and maintain the SAP Community wiki performance.
Please plan your tasks accordingly.
Skip to end of metadata
Go to start of metadata

Link to Content's target Space :

Applies to:

CRM 6.0/7.0


Uploading documents as attachments using cl_crm_documents class and displaying images in web ui screen.


Created on:   May'15 2010
Author(s) Bio
Arun Kumar is a CRM developer working with Accenture.

General description:

This wiki explains how to upload documents & images  using cl_crm_documents class and display images in web ui screen. The standard attachments tab lists the uploaded documents & images as individual links and the images are opened in a new window. This wiki also covers how to populate images in the standard web ui screen.


Create a component in transaction BSP_WD_CMPWB and add a view with view type 'Form View' or 'Empty View'. In this wiki its just an empty view without any context nodes.

The view  layout is enhanced with a fileupload tag to upload images and an image tag to display images.

The upload event triggers the server event EH_ONUPLOAD in controller class.


The method gets triggered when user selects the file path and clicks Upload button.

The importing parameter htmlb_event_ex has reference to thtmlb:fileUpload tag. Assign htmlb_event_ex to reference variable lr_file of type ref to cl_htmlb_fileupload.

Extract filename and file extension from file path using function module 'CRM_KW_SPLIT_FILENAME'

Assign business object so that the file can be accessed from the specified business object location. Since the business object type is USER and instance identifier is sy-uname, the uploaded document can be accessed via transaction crm_kw.

The entire file content is stored as an xstring in lr_file->file_content. Since we use method create_with_table of cl_crm_documents class, the content is split into 1022 characters and inserted into an internal table.

Now, is the final step. Upload the document to the system using CREATE_WITH_TABLE method from class CL_CRM_DOCUMENTS.The method returns the logical and physical id's of the document location.

Now, the image is uploaded to the system. But in order to display the image we need to get the document location as a URL. It can be done by passing the logical and physical id's of the document to method GET_WITH_URL of class CL_CRM_DOCUMENTS.

The URL is assigned to public static variable gv_url.

In the layout the image location is passed through this variable <%= controller->gv_url. %>.



Layout Coding:


Useful Information

Uploading documents and displaying images in web ui using CL_CRM_DOCUMENTS class.


Thanks & Regards,  Arun Kumar


  1. Guest

    Thank you very much for this posting, it's very helpful.

    I need to display a number of images (almost like very large buttons) that I can click on and have code executed accordingly. Can I ask what method I could use to achieve ths kind of functionality?. I can't use ordinary buttons as the images are square in shape, and I don't think you can add an image to standard buttons in this way.


  2. Hi Jason,

    If you are adding buttons in prepare_toolbar method, then you can only use the images available in path 


    In case are creating the buttons directly in the layout page using thtmlb tags, then you can upload the images to the MIME repository of the same component & pass it to <thtmlb:button> tag parameter iconSrc,

    <thtmlb:button iconSrc="competitor.gif" tooltip="Competitor"  />



  3. Guest

    Hello Arun,

    I have followed the above explained procedure to upload an image to the Web UI. But the image is not getting displayed. It is just showing the portion as coded in .htm page.


    DNR Varma

  4. Hello Arun,

    The way you provided the procedure was nice. I have followed the steps provided here and I am not getting the image in the view, but I am getting the success message as image was uploaded successfully. Is there any thing missed to display the image, please let me know.

    Thanks in advance.



  5. Hi Darwin,

    Check whether the correct URL passed to the image tag in layout page,



  6. Hi Darwin,

    Check whether the correct URL passed to the image tag in layout page,



  7. Hi Arun,

    Thanks for your response. The URL passed by me is

    <thtmlb:image src    = "<%= CONTROLLER->GV_URL %>"
                      width  = "175"
                      height = "175" />

    In debugging I found that, In event handler method eh_onupload, we are using a class

    CALL METHOD cl_crm_documents=>get_with_url
            loio     = ls_loio
            phio     = ls_phio
            url_type = '2'
            error    = ls_error
            url      = lv_url.

    from this class we should get

    lv_url value na, but it is not getting. could u can say me why it is not getting.

    Thanks and Regards,


  8. Hi Darwin,


    Plz declare the GV_URL as an global attribute in your View(IMPL class). Then only U can call that in .htm page.