Skip to Content
Author's profile photo Rashmi BR

SAP NetWeaver Gateway Service Builder: How to Read Photo – Code Snippets

Code snippet to be copy-pasted in the DEFINE method of Extended Model Provider class.

super->DEFINE( ).

DATA:
lo_entity  
type REF TO /IWBEP/IF_MGW_ODATA_ENTITY_TYP,
lo_property
type REF TO /IWBEP/IF_MGW_ODATA_PROPERTY.

lo_entity = model->GET_ENTITY_TYPE( IV_ENTITY_NAME = ‘EmployeePhoto’ ).

IF lo_entity is BOUND.

  lo_property = lo_entity->GET_PROPERTY( IV_PROPERTY_NAME = ‘ContentType’ ).

  lo_property->SET_AS_CONTENT_TYPE( ).
ENDIF.

Code snippet to be copy-pasted in the

/IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM method of the Extended Data Provider class.

DATA: ls_stream    TYPE         ty_s_media_resource
     
,lo_api    TYPE REF TO  if_mr_api
     
,lv_entity_name TYPE  /IWBEP/MGW_TECH_NAME
     
,er_entity type REF TO DATA
     
,lr_entity TYPE REF TO DATA
     
,employeephotoset_get_entity TYPE ZCL_ZMEDIALNK_SB_MPC=>TS_EMPLOYEEPHOTO
     
,ls_content type table of TBL1024 initial size 0
     
,ls_xstring type xstring
     
,lt_messg type table of BAPIRET2 initial SIZE 0
     
,lv_pernr(8) TYPE n
     
,t_photo type table of TBL1024
     
,l_photo type XSTRING
     
,l_line type string
     
,l_photo1 type string
     
,ls_ret type BAPIRET2
     
,ls_photo type TBL1024
     
,t_msg type table of BAPIRET2.

lv_entity_name = io_tech_request_context->GET_ENTITY_TYPE_NAME( ).

CASE lv_entity_name.
    

      WHEN ‘EmployeeData’.
     
WHEN ‘EmployeePhoto’.
     

     employeephotoset_get_entity(
          
EXPORTING iv_entity_name     = iv_entity_name
                     iv_entity_set_name
= iv_entity_set_name
                     iv_source_name    
= iv_source_name
                     it_key_tab        
= it_key_tab
                     it_navigation_path
= it_navigation_path
                     io_tech_request_context
= io_tech_request_context
          
IMPORTING er_entity          = employeephotoset_get_entity
                                
).
     
          
IF employeephotoset_get_entity IS NOT INITIAL.
          
*     Send specific entity data to the caller interface
           copy_data_to_ref
(
                    
EXPORTING
                     is_data
= employeephotoset_get_entity
                    
CHANGING
                     cr_data
= er_entity
                         
).
          
ELSE.
          
*         In case of initial values – unbind the entity reference
           er_entity
= lr_entity.
          
ENDIF.

           lv_pernr = employeephotoset_get_entityEmpID.

           CALL FUNCTION ‘PAD_PHOTO_UPDATE_GET_DETAIL’
          
EXPORTING
                IV_EMPLOYEE_NUMBER        
= lv_pernr
      

          
TABLES
                T_PHOTO_ARCHIVE_OUT       
= t_photo
                T_MESSAGES_OUT            
= t_msg
               
.

           LOOP AT t_photo into ls_photo.
                l_line
= ls_photoline.
               
concatenate l_photo1 l_line into l_photo1.
          
ENDLOOP.

               ls_streamvalue = l_photo = l_photo1.
               ls_stream
mime_type = ‘image/jpeg’.

               copy_data_to_ref( EXPORTING is_data = ls_stream
                                
CHANGING  cr_data = er_stream ).

      WHEN OTHERS.

ENDCASE.



Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Thanks Rashmi. Very userful document.