系统里存了很多以前写的代码,好长时间不看都忘了,还是想存到本地,挨个复制粘贴太麻烦了,有好多程序写的很正式,有很多include,复制起来就更麻烦了。
所以想着写个程序把程序名一输,自动下载所有代码。
*&---------------------------------------------------------------------**& REPORT YZ_TEST*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT YZ_TEST NO STANDARD PAGE HEADING MESSAGE-ID YTEST.TYPES :BEGIN OF TYP_DATA, DATA(200) TYPE C, END OF TYP_DATA.DATA GT_ALLCODE TYPE STANDARD TABLE OF TYP_DATA WITH HEADER LINE.DATA GT_TEMPCODE TYPE STANDARD TABLE OF TYP_DATA WITH HEADER LINE.DATA GT_INCLUDE TYPE STANDARD TABLE OF TYP_DATA WITH HEADER LINE.DATA LV_LENG TYPE I.DATA LV_PROGLEN TYPE I.DATA LV_FPATH TYPE STRING.DATA GV_MARK TYPE C.CONSTANTS: LC_POINT TYPE C VALUE '.'.CONSTANTS: LC_INCLUDE TYPE C LENGTH 7 VALUE 'INCLUDE'.PARAMETERS:P_REPORT TYPE RSRD1-OBJNAME OBLIGATORY DEFAULT 'YZTEST'.PARAMETERS: P_PATH TYPE IBIPPARMS-PATH OBLIGATORY DEFAULT 'C:\Users\xabap01\Desktop\test.xls' .AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PATH. PERFORM F_F4_PATH CHANGING P_PATH.START-OF-SELECTION. LV_PROGLEN = STRLEN( P_REPORT ) + 3. READ REPORT P_REPORT INTO GT_ALLCODE. LOOP AT GT_ALLCODE. SEARCH GT_ALLCODE-DATA FOR 'INCLUDE'. IF SY-SUBRC EQ 0. GV_MARK = 'X'. LV_LENG = STRLEN( GT_ALLCODE-DATA ). SHIFT GT_ALLCODE-DATA UP TO LC_INCLUDE LEFT. GT_ALLCODE-DATA = GT_ALLCODE-DATA+8(LV_PROGLEN). GT_INCLUDE-DATA = GT_ALLCODE-DATA. APPEND GT_INCLUDE. CLEAR: GT_INCLUDE,GT_ALLCODE. ENDIF. ENDLOOP. IF GV_MARK EQ 'x'. LOOP AT GT_INCLUDE. READ REPORT GT_INCLUDE-DATA INTO GT_TEMPCODE. IF SY-SUBRC EQ 0. APPEND LINES OF GT_TEMPCODE TO GT_ALLCODE. CLEAR:GT_TEMPCODE,GT_TEMPCODE[]. ENDIF. ENDLOOP. CLEAR GV_MARK. ENDIF. LV_FPATH = P_PATH. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING FILENAME = LV_FPATH FILETYPE = 'ASC' WRITE_FIELD_SEPARATOR = 'X' TABLES DATA_TAB = GT_ALLCODE EXCEPTIONS FILE_WRITE_ERROR = 1 NO_BATCH = 2 GUI_REFUSE_FILETRANSFER = 3 INVALID_TYPE = 4 NO_AUTHORITY = 5 UNKNOWN_ERROR = 6 HEADER_NOT_ALLOWED = 7 SEPARATOR_NOT_ALLOWED = 8 FILESIZE_NOT_ALLOWED = 9 HEADER_TOO_LONG = 10 DP_ERROR_CREATE = 11 DP_ERROR_SEND = 12 DP_ERROR_WRITE = 13 UNKNOWN_DP_ERROR = 14 ACCESS_DENIED = 15 DP_OUT_OF_MEMORY = 16 DISK_FULL = 17 DP_TIMEOUT = 18 FILE_NOT_FOUND = 19 DATAPROVIDER_EXCEPTION = 20 CONTROL_FLUSH_ERROR = 21 OTHERS = 22. IF SY-SUBRC <> 0. MESSAGE E000 WITH 'download failed !' . RETURN. ENDIF.*&---------------------------------------------------------------------**& Form F_F4_PATH*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** <--P_P_PATH text*----------------------------------------------------------------------*FORM F_F4_PATH CHANGING P_PATH. DATA: LV_EXTEN TYPE STRING, LV_FILTER TYPE STRING, LV_DIREC TYPE STRING, LV_FP TYPE STRING, LV_RC TYPE I, LT_FT TYPE FILETABLE, LS_FT LIKE LINE OF LT_FT. CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG EXPORTING DEFAULT_EXTENSION = LV_EXTEN FILE_FILTER = LV_FILTER INITIAL_DIRECTORY = LV_DIREC CHANGING FILE_TABLE = LT_FT RC = LV_RC EXCEPTIONS FILE_OPEN_DIALOG_FAILED = 1 CNTL_ERROR = 2 ERROR_NO_GUI = 3 NOT_SUPPORTED_BY_GUI = 4 OTHERS = 5. READ TABLE LT_FT INTO LS_FT INDEX 1. LV_FP = LS_FT. P_PATH = LV_FP.ENDFORM. " F_F4_PATH
写完以后给同事看,结果人家给了一个更好的代码:
http://blog.163.com/fuwa_beijing/blog/static/50467514201041135032400/
功能看起来很多,下载程序代码同时还能把程序中用到的表结构下载成html文件。最终还是用这个代码备份了所有程序。