CM: 使用ICF node实现对附件的读取

Created by Jerry Wang on May 26, 2014

1. 创建一个新的class,实现interface IF_HTTP_EXTENSION:

 

CM: 使用ICF node实现对附件的读取

 

 

2. tcode SICF,在sap node下面创建一个新的ICF node. 将step1创建的class 指定成handler class:

CM: 使用ICF node实现对附件的读取

 

 

激活class:

CM: 使用ICF node实现对附件的读取

 

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:

CM: 使用ICF node实现对附件的读取

 

如果是text file,则直接用浏览器打开:

CM: 使用ICF node实现对附件的读取

上一篇:CM: webservice 元数据在word template中的存储


下一篇:在C和C++中struct与typedef struct的区别详细介绍