cancel
Showing results for 
Search instead for 
Did you mean: 

display photo

Former Member
0 Kudos

hi all,

in my program, the first screen is to display list of employee, when user select an employee, the next screen should display his/her photo with discription. so i have to import mime object dynamically, and pass the name of the mime object to source of image element.

so my question is

where SAP store photo of employee, and can we import mime object from there. how?

is SAP store jpg/etc image object in sap table, then in which table?

is there any other way to display employee photo,

please need some expert advise.

Bala

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can display employee photo, plese check below code:


  DATA: it_toav0 TYPE TABLE OF toav0,
        wa_toav0 TYPE toav0,
        p_exists TYPE c.

  DATA: ex_length   TYPE int4,
        ex_document TYPE TABLE OF tbl1024,
        ex_message  TYPE bapiret2,
        img         TYPE xstring,
        url         TYPE string,
        pernr       TYPE persno VALUE `1006786`.

  DATA: cached_response TYPE REF TO if_http_response,
        guid TYPE guid_32.

* check employee image
  CALL FUNCTION 'HR_IMAGE_EXISTS'
    EXPORTING
      p_pernr        = pernr
      p_tclas        = 'A'
    IMPORTING
      p_exists       = p_exists
      p_connect_info = wa_toav0.

  IF p_exists = 1.
*   get image data 
    CALL FUNCTION 'ALINK_RFC_TABLE_GET'
      EXPORTING
        im_docid    = wa_toav0-arc_doc_id
        im_crepid   = wa_toav0-archiv_id
      IMPORTING
        ex_length   = ex_length
        ex_message  = ex_message
      TABLES
        ex_document = ex_document.

*   convert to xstring
    CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
      EXPORTING
        input_length = ex_length
      IMPORTING
        buffer       = img
      TABLES
        binary_tab   = ex_document.

    CREATE OBJECT cached_response
      TYPE
        cl_http_response
      EXPORTING
        add_c_msg        = 1.

*   set image to mime
    cached_response->set_data( img ).
    cached_response->set_header_field(
                     name  = if_http_header_fields=>content_type
                     value = 'image/pjpeg'  ).
    cached_response->set_status( code = 200 reason = 'OK' ).
    cached_response->server_cache_expire_rel( expires_rel = 180 ).

    CALL FUNCTION 'GUID_CREATE'
      IMPORTING
        ev_guid_32 = guid.

    cl_wd_utilities=>construct_wd_url(
                     EXPORTING application_name = 'Z_JR05'
                     IMPORTING out_local_url    = url     ).

    CONCATENATE url '/' guid sy-uzeit INTO url.
    cl_http_server=>server_cache_upload(
                    url      = url
                    response = cached_response ).

*   set photo 
    DATA:
     node_photo           TYPE REF TO if_wd_context_node,
     elem_photo           TYPE REF To if_wd_context_element,
     stru_photo           TYPE wd_this->element_photo.

    node_photo = wd_context->get_child_node( 
                name = wd_this->wdctx_photo ).

    elem_photo = node_photo->get_element(  ).
    
    elem_photo->set_attribute(
      EXPORTING
        name =  `PHOTO`
        value = url ).
  ENDIF.

Notes:

  • Pernr is my employee number.

  • Photo is my node

  • Photo is my attribute under photo node with data type: string

  • Set your image source to photo attribute

  • Z_JR05 is my WDApplication name

Regards,

$=====$

Are you newbie? Check this out: [Rules of Engagement|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/rulesofEngagement]

Answers (2)

Answers (2)

pranav_nagpal2
Contributor
0 Kudos

Hi,

there is a UI element Image..... you can insert that Ui element and you have to just give the path of the image in source property of image Ui element.....

regards

Pranav

Former Member
0 Kudos

Bala,

there is a component already available to display photo.

check hrasr_profilefoto

Thanks

Bala Duvvuri