Image processing in ABAP Web Dynpro using custom table

...Previous

Double click on method “LOAD_IMAGE” paste following code.

METHOD load_image.
  
DATAlo_nd_img_table     TYPE REF TO   if_wd_context_node,
        lt_img_table        
TYPE          wd_this->elements_img_table,
        ls_img_table        
TYPE          wd_this->element_img_table,
        cached_response     
TYPE REF TO   if_http_response,
        lv_file_content     
TYPE          xstring,
        lv_guid             
TYPE          guid_32,
        lv_host             
TYPE          string,
        lv_port             
TYPE          string,
        lv_protocol         
TYPE          string,
        lv_url              
TYPE          string,
        lt_img              
TYPE TABLE OF ztable_image,
        ls_img              
TYPE          ztable_image
        
.

  
SELECT INTO TABLE lt_img FROM ztable_image ORDER BY id.
  
IF sy-subrc 0.
* navigate from <CONTEXT> to <IMG_TABLE> via lead selection
    lo_nd_img_table 
wd_context->get_child_nodename wd_this->wdctx_img_table ).
    
LOOP AT lt_img INTO ls_img.
      ls_img_table
-id ls_img-id.
      
CREATE OBJECT cached_response
        
TYPE
        cl_http_response
        
EXPORTING
          add_c_msg 
1.
      lv_file_content 
ls_img-image_data.
      cached_response
->set_datalv_file_content ).
      cached_response
->set_header_fieldname  if_http_header_fields=>content_type
                                         
value 'image/jpeg' ).
* Create a unique URL for the object
      
CALL FUNCTION 'GUID_CREATE'
        
IMPORTING
          ev_guid_32 
lv_guid.
*

***Set the Response Status
      cached_response
->set_statuscode 200 reason 'OK' ).

***Set the Cache Timeout - 60 seconds - we only need this in the cache
***long enough to build the page and allow the IFrame on the Client to request it.
      cached_response
->server_cache_expire_relexpires_rel 360 ).

      
CALL METHOD cl_http_server=>get_location
        
EXPORTING
          server       
cl_wdr_task=>server
        
IMPORTING
          host         
lv_host
          port         
lv_port
          out_protocol 
lv_protocol.

      
CONCATENATE
        lv_protocol 
'://' lv_host ':' lv_port '/sap/bc/webdynpro/sap/'
        lv_guid 
'.JPG'
        
INTO lv_url.

      cl_http_server
=>server_cache_uploadurl      lv_url
                                           response 
cached_response ).
      ls_img_table
-url lv_url.
      
APPEND ls_img_table TO lt_img_table.
      
CLEAR lv_file_content.
    
ENDLOOP.
    wd_this
->gv_last_id ls_img_table-id 1.
    lo_nd_img_table
->bind_tablenew_items lt_img_table set_initial_elements abap_true ).
  
ELSE.
    wd_this
->gv_last_id 1.
  
ENDIF.

ENDMETHOD.

Create web dynpro application “zwa_image_process”. Save and test it

Initial view

After saving a Image


 

After saving multiple images

Summary. In this application, I am loading image from a custom table. This custom table stores image contents in the form of RAWSTRING.  It also provides facility to upload image and save it into custom table. Internally, It is using interface “if_http_response  and class “cl_http_response  for loading image and “FileUpload” wd screen element provide support for converting file into xstring.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image