《abap中对上传文件和下载文件的一般检查》由会员分享,可在线阅读,更多相关《abap中对上传文件和下载文件的一般检查(23页珍藏版)》请在金锄头文库上搜索。
1、ABAP中对上传文件和下载文件的一般检查 文件检查的一般方法。实用。设计一些通用模块,和使用方法。1, 首先对要上传的文件进行存在检查。(在AT SELECTION-SCREEN事件下完成)CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXISTEXPORTINGFILE = LW_FILERECEIVINGRESULT = LW_RESULTEXCEPTIONSCNTL_ERROR = 1ERROR_NO_GUI = 2WRONG_PARAMETER = 3NOT_SUPPORTED_BY_GUI = 4OTHERS = 5.IF SY-SUBR
2、C <> 0.SET CURSOR FIELD 'P_UPFILE'. "*- 出力MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.*- 結果判定IF LW_RESULT <> CNS_TRUE. "存在SET CURSOR FIELD 'P_UPFILE'. "*- MSG: &1 存在MESSAGE E116(ZNKCC1) WITH P_UPFIL
3、E.ENDIF.2, 对于指定下载到本地的文件,首先,将屏幕上输入的路径和文件名分隔开来,(在AT SELECTION-SCREEN事件下完成)*- CALL 汎用CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'EXPORTINGFULL_NAME = P_ERFILEIMPORTINGSTRIPPED_NAME = W_FILEFILE_PATH = P_O_PATHEXCEPTIONSX_ERROR = 1OTHERS = 2.IF SY-SUBRC <> 0.SET CURSOR FIELD 'P_ERFILE'.
4、"*- 出力MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.其次,检查分隔得到的文件路径(路径是否存在)。(在AT SELECTION-SCREEN事件下完成)CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXISTEXPORTINGDIRECTORY = LW_PATHRECEIVINGRESULT = LW_RESULTEXCEPTIONSCNTL_ERROR = 1ERROR
5、_NO_GUI = 2WRONG_PARAMETER = 3NOT_SUPPORTED_BY_GUI = 4OTHERS = 5.IF SY-SUBRC <> 0.SET CURSOR FIELD 'P_ERFILE'. "MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.3, 实现对上传文件的检索帮助。(在AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_UPFILE.事件
6、下完成)CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOGEXPORTINGWINDOW_TITLE = LW_TITLE "選択CHANGINGFILE_TABLE = LTD_FILERC = LW_RETURN "値USER_ACTION = LW_ACTION "動作結果EXCEPTIONSFILE_OPEN_DIALOG_FAILED = 1CNTL_ERROR = 2ERROR_NO_GUI = 3NOT_SUPPORTED_BY_GUI = 4OTHERS = 5.*- 判定IF SY-
7、SUBRC <> 0. "失敗時SET CURSOR FIELD 'P_UPFILE'. "*- 出力MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.RETURN.ENDIF.*- 結果情報判定IF LW_RETURN < 0.RETURN. "選択画面戻ENDIF.*- 結果情報判定IF LW_ACTION = 0 .*- 選択1件目名設定READ TABLE LTD_FILE INTO LT
8、H_FILE INDEX 1.*- 判定IF SY-SUBRC = 0.P_UPFILE = LTH_FILE-FILENAME.ENDIF.ENDIF.4, 对下载的文件的检索帮助的实现同3。5, 对下载的文件是保存帮助处理。CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOGEXPORTINGWINDOW_TITLE = LW_TITLE "出力選択CHANGINGFILENAME = LW_FILENAME "名PATH = LW_PATH "名FULLPATH = LW_FULLPATH &qu
9、ot;名USER_ACTION = LW_ACTION "動作結果EXCEPTIONSCNTL_ERROR = 1ERROR_NO_GUI = 2NOT_SUPPORTED_BY_GUI = 3OTHERS = 4.*- 判定IF SY-SUBRC <> 0. "CALL 失敗時SET CURSOR FIELD 'P_ERFILE'. "*- 出力MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.RET
10、URN. "選択画面戻ENDIF.*- 結果情報判定IF LW_ACTION = 0.*- 名選択画面-名設定P_ERFILE = LW_FULLPATH.ENDIF.6另外的情况,屏幕上输入下载文件指定路径和文件名后,先检查该文件是否存在,如果存在,则需要弹出对话框,提醒用户是否覆盖原文件。(在AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_DOFILE.事件下完成)*- 存在CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXISTEXPORTINGFILE = LW_FILE "RECE
11、IVINGRESULT = LW_RESULT "結果EXCEPTIONSCNTL_ERROR = 1ERROR_NO_GUI = 2WRONG_PARAMETER = 3NOT_SUPPORTED_BY_GUI = 4OTHERS = 5.*- 判定IF SY-SUBRC <> 0. "CALL 失敗時SET CURSOR FIELD 'P_ERFILE'. "*- 出力MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3
12、 SY-MSGV4.ENDIF.提示是否覆盖原文件:*- CALL 汎用CALL FUNCTION 'POPUP_TO_CONFIRM'EXPORTINGTITLEBAR = TEXT-006 "確認TEXT_QUESTION = TEXT-007 "質問TEXT_BUTTON_1 = TEXT-008 "TEXT_BUTTON_2 = TEXT-009 "DEFAULT_BUTTON = '1' "位置DISPLAY_CANCEL_BUTTON = 'X' "取消押START_COLUMN = 25 "POPUP 開始列START_ROW = 6 "POPUP 開始行IMPORTINGANSWER = LW_ANSWER "EXCEPTIONSTEXT_NOT_FOUND = 1OTHERS = 2.*- 判定IF SY-SUBRC <> 0. "CALL失敗時*- 出力MESSAGE ID SY-MSGID TYPE 'S' NUM