标签:sap 下载 ep web dynpro 文件下载
调用RFC把文件下载下来,然后EP远程调用把文件传递过去这种思想是不可取的,至于为什么我就不太清楚,知道的请告诉我,谢谢。
function zewm_rfc_dms_download2. *"---------------------------------------------------------------------- *"*"Local interface: *" IMPORTING *" VALUE(IP_DOCUMENTNUMBER) LIKE BAPI_DOC_AUX-DOCNUMBER OPTIONAL *" VALUE(IP_OPER) TYPE CHAR1 *" VALUE(IP_FILE_ID) TYPE SDOK_PHID OPTIONAL *" VALUE(IP_STORAGECATEGORY) TYPE CV_STORAGE_CAT OPTIONAL *" EXPORTING *" VALUE(EP_RETURN) TYPE BAPIRET2 *" VALUE(EP_FIELNAME) TYPE SDOK_FILNM *" VALUE(EP_CONTENT) TYPE XSTRING *" TABLES *" TB_REPORT STRUCTURE ZDMS_FILE_INFO2 *"---------------------------------------------------------------------- data: lt_documentfiles type table of bapi_doc_files2 with header line, lt_bapi_doc_structure type table of bapi_doc_structure with header line, ls_bapi_doc_files2 type bapi_doc_files2, l_filename type bapi_doc_aux-filename, l_rfilename type rlgrap-filename. data: lv_fullname type filep, lv_dokna type filep, lv_dokpa type filep. data: lv_docnumber type bapi_doc_aux-docnumber. data: rc type i, l_cfilename type string, l_result type abap_bool, l_directory type string. data: lt_ftable type standard table of file_info, ls_ftable type file_info, l_count type i, lv_i type i. *--------------------------------------------------------------------* data: lw_zdms_file_info type zdms_file_info2. data: lt_files2 type standard table of bapi_doc_files2, ls_files2 type bapi_doc_files2, ls_return type bapiret2, lt_bin type standard table of sdokcntbin, lt_inf type standard table of scms_acinf, ls_inf type scms_acinf. data: contentx type xstring. data: filename type sdok_filnm. data: docnum type vttk-add03. data: begin of lt_add03 occurs 0, add03 type vttk-add03, end of lt_add03. data:doctype type bapi_doc_aux-doctype value ‘Z23‘, docpart type bapi_doc_aux-docpart value ‘000‘, docversion type bapi_doc_aux-docversion value ‘00‘. case ip_oper. when ‘1‘."搜索相关文档的文件类型 * DATA docnumber TYPE bapi_doc_aux-docnumber. * DATA zero TYPE C LENGTH 15 VALUE ‘000000000000000‘. * CONCATENATE zero ip_documentnumber INTO docnumber. call function ‘BAPI_DOCUMENT_GETDETAIL2‘ "得到文档的元件列表documentfiles exporting documenttype = doctype documentnumber = ip_documentnumber documentpart = docpart documentversion = docversion getdocfiles = ‘X‘ importing return = ls_return tables documentfiles = lt_files2. if sy-subrc <> 0. ls_return-type = ‘E‘. ls_return-message = ‘can not get file‘. endif. if lt_files2[] is not initial. loop at lt_files2 into ls_files2. clear lw_zdms_file_info. move-corresponding ls_files2 to lw_zdms_file_info. * lw_zdms_file_info-storagecategory = ‘DMS_C1_ST‘. perform frm_split_path_file using ls_files2-docfile changing lw_zdms_file_info-filename "文档名称 lv_dokpa."文档路径 condense lw_zdms_file_info-filename. lv_i = strlen( lw_zdms_file_info-filename ) - 3. lw_zdms_file_info-filetype = lw_zdms_file_info-filename+lv_i(3). append lw_zdms_file_info to tb_report. endloop. endif. when ‘2‘."得到文件 call function ‘SCMS_DOC_READ‘ exporting stor_cat = ip_storagecategory doc_id = ip_file_id tables access_info = lt_inf content_bin = lt_bin[]."得到文件的数据 if sy-subrc <> 0. ls_return-type = ‘E‘. ls_return-message = ‘NO_FILE_INFO‘. endif. read table lt_inf into ls_inf index 1. if sy-subrc ne 0. ls_return-type = ‘E‘. ls_return-message = ‘NO_FILE_INFO‘. else. call function ‘SCMS_BINARY_TO_XSTRING‘ exporting input_length = ls_inf-comp_size * FIRST_LINE = 0 * LAST_LINE = 0 importing buffer = contentx tables binary_tab = lt_bin exceptions failed = 1 others = 2. if sy-subrc <> 0. ls_return-type = ‘E‘. ls_return-message = ‘BINARY_CONVERSION_ERROR‘. else. filename = ls_inf-comp_id. endif. endif. clear ep_return. ep_return = ls_return. ep_content = contentx. ep_fielname = filename. endcase. endfunction.
form frm_split_path_file using uv_fullname
changing cv_filename
cv_pathname.
data: lt_match type match_result_tab,
ls_match like line of lt_match.
find all occurrences of ‘\‘ in uv_fullname
in character mode results lt_match.
if not lt_match is initial.
loop at lt_match into ls_match.
endloop.
add 1 to ls_match-offset.
cv_pathname = uv_fullname(ls_match-offset).
cv_filename = uv_fullname+ls_match-offset.
endif.
endform.
YsdCompView:
//点击下载按钮时实现的方法,调用WindowsController的方法showPrintDMSWin创建Windows,把相关信息封装到selectList上 public void onActionDownload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin onActionDownload(ServerEvent) IPrivateYsdCompView.IQueryResultListNode node = wdContext.nodeQueryResultList(); List selectList = new ArrayList(); for (int i = 0; i < node.size(); i++) { IPrivateYsdCompView.IQueryResultListElement ele = node.getQueryResultListElementAt(i); if (ele.getCheck()) { selectList.add(ele); } } if (selectList.isEmpty()) { wdComponentAPI.getMessageManager().reportException("请先选中行项!", false); return; } else { if (1 == selectList.size()) { wdThis.wdGetWindowsControllerController().showPrintDMSWin(selectList); }else { wdComponentAPI.getMessageManager().reportException("只能选一项!",false); } } //@@end }
WindowsController的方法showPrintDMSWin:
public void showPrintDMSWin( java.util.List selectList ) { //@@begin showPrintDMSWin() IWDWindow window = wdContext.currentPrintDMSViewElement().getWinref(); IWDWindowInfo windowInfo=null; if (window == null) { /*Getter for element with given name in 1:n aggregation Windows. */ windowInfo = wdComponentAPI.getComponentInfo().findInWindows("PrintDMSWin"); window = wdComponentAPI.getWindowManager().createModalWindow(windowInfo); window.setTitle("查看签收单"); window.setWindowSize(50,50); window.setWindowPosition(WDWindowPos.CENTER); wdContext.currentPrintDMSViewElement().setWinref(window); } window.show(); //清空查询结果 wdContext.nodeFiles().invalidate(); //设置传入参数 wdContext.currentPrintDMSViewElement().setSelectList(selectList); wdThis.wdGetYsdCompController().queryDMS(selectList, wdContext.nodeFiles()); //@@end }
Component Controller:用于远程调用RFC的oper1,输入参数通过selectList传递。
//@@begin javadoc:queryDMS() /** 查询DMS获取凭证文件的二进制数据. */ //@@end public void queryDMS( java.util.List selectlist, com.sap.tc.webdynpro.progmodel.api.IWDNode node ) { //@@begin queryDMS() Zewm_Rfc_Dms_Download2_Input input = new Zewm_Rfc_Dms_Download2_Input(); for (int i = 0; i < selectlist.size(); i++) { IPrivateYsdCompView.IQueryResultListElement element = (IPrivateYsdCompView.IQueryResultListElement)selectlist.get(0); input.setIp_Oper("1"); input.setIp_Documentnumber("000000000000000"+element.getSignid()); } Zewm_Rfc_Dms_Download2_Output output = wdThis.wdGetRfcControllerController().excute_ZTM_RFC_DMS_DOWNLOAD2(input); if (output != null && wdThis.wdGetRfcControllerController().handleBapiret(output.getEp_Return())) { List reports = output.getTb_Report(); int size = reports.size(); if (size > 0) { for (int i = 0; i < size; i++) { Zdms_File_Info2 obj = (Zdms_File_Info2)reports.get(i); IWDNodeElement newEle = node.createElement(); WDCopyService.copyCorresponding(obj, newEle); node.addElement(newEle); } } } //@@end }
YsdCompView://点击查看文件则将调用了printDMSView的方法:onActionseeFile
public void onActionseeFile(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) { //@@begin onActionseeFile(ServerEvent) List itemList = new ArrayList(); IWDNodeElement ele = wdContext.nodeFiles().getCurrentElement(); if (null == ele) { wdComponentAPI.getMessageManager().reportWarning("没有文件"); } else { wdComponentAPI.getMessageManager().reportSuccess("start download!"); itemList.add(ele); if (ele.getAttributeAsText("Storagecategory").equals("")) { wdComponentAPI.getMessageManager().reportWarning("没有文件"); }else{ InputStream inputStream = wdThis.wdGetYsdCompController().getDMS(itemList); //调用getDMS方法实际上是远程调用了RFC操作2,把操作1得到的信息变成操作流,从而实现下载 if(inputStream == null){ wdComponentAPI.getMessageManager().reportWarning("没有文件"); }else{ String fileName = wdContext.currentFilesElement().getFilename(); String fileType = wdContext.currentFilesElement().getFiletype(); wdThis.wdGetCOMP_EXCELInterface().showDMSFileWin(inputStream,fileName,fileType);//执行下载 } } } //@@end }
Component Controller:
//@@begin javadoc:getDMS() /** 根据凭证文件的二进制文件获取DMS的IO流. */ //@@end public java.io.InputStream getDMS( java.util.List selectlist ) { //@@begin getDMS() InputStream inputStream = null; Zewm_Rfc_Dms_Download2_Input input = new Zewm_Rfc_Dms_Download2_Input(); for (int i = 0; i < selectlist.size(); i++) { IPrivatePrintDMSView.IFilesElement element = (IPrivatePrintDMSView.IFilesElement)selectlist.get(i); input.setIp_Oper("2"); input.setIp_Storagecategory(element.getStoragecategory()); input.setIp_File_Id(element.getFile_Id()); } Zewm_Rfc_Dms_Download2_Output output = wdThis.wdGetRfcControllerController().excute_ZTM_RFC_DMS_DOWNLOAD2(input); if (output != null && wdThis.wdGetRfcControllerController().handleBapiret(output.getEp_Return())) { byte[] bytes = output.getEp_Content(); try { inputStream = new ByteArrayInputStream(bytes); } catch(Exception e){ e.printStackTrace(); } wdComponentAPI.getMessageManager().reportSuccess(inputStream.toString()); return inputStream; }else { return null; } //@@end }
COMP_EXCEL:
//@@begin javadoc:showExportExcelWin() /** 下载指定模版 */ //@@end public void showExportExcelWin( com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource excelInput, java.lang.String filename ) { //@@begin showExportExcelWin() wdContext.currentContextElement().setExportexcelresource(excelInput); wdContext.currentContextElement().setExportexcelfilename(filename); IWDWindowInfo exportExcelWinInfo = wdComponentAPI.getComponentInfo().findInWindows("ExportExcelWin"); IWDWindow exportExcelWin = wdComponentAPI.getWindowManager().createModalWindow(exportExcelWinInfo); exportExcelWin.setTitle("下载"); exportExcelWin.setWindowSize(150, 80); exportExcelWin.setWindowPosition(WDWindowPos.CENTER); wdContext.currentContextElement().setExportexcelwinref(exportExcelWin); exportExcelWin.show(); //@@end }
//@@begin javadoc:showDMSFileWin() /** Declared method. */ //@@end public void showDMSFileWin( java.io.InputStream input, java.lang.String fileName, java.lang.String fileType ) { //@@begin showDMSFileWin() WDWebResourceType type=null; if("jpg".equals(fileType)) { type = WDWebResourceType.JPG_IMAGE; }else if("xls".equals(fileType)) { type= WDWebResourceType.XLS; }else if("lsx".equals(fileType)) { type= WDWebResourceType.XLS; }else if("pdf".equals(fileType)) { type= WDWebResourceType.PDF; }else if("png".equals(fileType)) { type= WDWebResourceType.PNG; }else if("gif".equals(fileType)) { type= WDWebResourceType.GIF_IMAGE; }else if("doc".equals(fileType)) { type= WDWebResourceType.DOC; }else if("ocx".equals(fileType)) { type= WDWebResourceType.DOC; }else if("ppt".equals(fileType)) { type= WDWebResourceType.PPT; }else if("txt".equals(fileType)) { type= WDWebResourceType.TXT; }else if("xml".equals(fileType)) { type= WDWebResourceType.XML; }else { type= WDWebResourceType.TXT; } if(null==type) { }else { IWDResource pdfresource = WDResourceFactory.createCachedResource(input, fileName, type, false); showExportExcelWin(pdfresource, fileName); } //@@end }
标签:sap 下载 ep web dynpro 文件下载
原文地址:http://blog.csdn.net/imlanbin/article/details/43704023