BSP自開發檔案下載的一個demo
阿新 • • 發佈:2019-02-09
* event handler for data retrieval DATA lv_string TYPE string. DATA lv_xstring TYPE xstring. DATA lv_xlength TYPE i. DATA lv_name TYPE string . DATA lv_value TYPE string . lv_string = '測試資料'. CALL FUNCTION 'SCMS_STRING_TO_XSTRING'"文字變二進位制流 EXPORTING text = lv_string * MIMETYPE = ' ' * ENCODING = IMPORTING buffer = lv_xstring * EXCEPTIONS * FAILED = 1 * OTHERS = 2 . response->set_header_field( name = 'cache-control' value = 'max-age=0' ). response->set_header_field( name = 'content-type' value = 'text/html; charset=utf-8' ). lv_name = 'XXXXXXXXXX匯入模板'. ***UrlEnCode編碼 CALL METHOD cl_http_utility=>escape_url EXPORTING unescaped = lv_name RECEIVING escaped = lv_name. CONCATENATE 'attachment;filename=' lv_name '.xml' INTO lv_value . response->set_header_field( name = 'content-disposition' value = lv_value ). lv_xlength = xstrlen( lv_xstring ). response->set_data( data = lv_xstring length = lv_xlength ). navigation->response_complete( ).
cl_http_utility是個很有用的函式,我們這裡用到了他的url編碼,不用的話這個地方中文檔名出不來。其他還有一些方法,大家可以參照其描述明白其功能。