Created by Jerry Wang on May 26, 2014
1. 创建一个新的class,实现interface IF_HTTP_EXTENSION:
2. tcode SICF,在sap node下面创建一个新的ICF node. 将step1创建的class 指定成handler class:
激活class:
3. handler class的方法实现如下:
METHOD if_http_extension~handle_request. DATA: lt_fields TYPE tihttpnvp, ls_io TYPE skwf_io, lt_file_access_info TYPE sdokfilacis, lv_content TYPE xstring. server->request->if_http_entity~get_form_fields( CHANGING fields = lt_fields ). READ TABLE lt_fields ASSIGNING FIELD-SYMBOL(<id>) WITH KEY name = 'id'. CHECK sy-subrc = 0. ls_io-objtype = 'P'. ls_io-objid = <id>-value. ls_io-class = 'BDS_POC22'. CALL FUNCTION 'CRM_KW_DOC_GET_DOCUMENT' EXPORTING io = ls_io IMPORTING file_access_info = lt_file_access_info content_bin = lv_content. READ TABLE lt_file_access_info ASSIGNING FIELD-SYMBOL(<mime>) INDEX 1. CHECK sy-subrc = 0. server->response->set_header_field( name = 'Content-Type' "#EC NOTEXT value = CONV #( <mime>-mimetype ) ). server->response->set_data( data = lv_content ). ENDMETHOD.
4. 在浏览器里输入如下url,如果attachment guid对应的attachment是word格式,则弹出如下dialog:
如果是text file,则直接用浏览器打开: