讀取SAP應用服務器路徑中的文件名稱

先定義一個結構類型:服務器

 types: BEGIN OF TP_FILE_ATTR, PATH TYPE ESEFTAPPL, NAME TYPE ESEFTAPPL, TARGET_PATH TYPE ESEFTAPPL, TYPE(10) TYPE C, FSIZE TYPE P LENGTH 4 DECIMALS 0, OWNER(8) TYPE C, FMODE(9) TYPE C, MTIME TYPE P LENGTH 6 DECIMALS 0, ERRNO(3) TYPE C, ERRMSG(40) TYPE C, END OF TP_FILE_ATTR . types: TP_FILE_ATTR_TAB TYPE TABLE OF TP_FILE_ATTR .

方法:spa

METHOD GET_FILE_LIST. DATA: WA_FILE_ATTR TYPE TP_FILE_ATTR. DATA: UNIX_PATH TYPE ESEFTAPPL. DATA: TARGET_UNIX_PATH TYPE ESEFTAPPL. DATA: LW_FILE_PATH TYPE ZRCAFILEPATH. SELECT SINGLE * INTO CORRESPONDING FIELDS OF LW_FILE_PATH "這邊是讀取路徑FROM ZRCAFILEPATH WHERE  INTID  = INT_ID AND    BUKRS  = BUKRS AND    WERKS  = WERKS AND    EKORG  = EKORG AND    VKORG  = VKORG. IF SY-SUBRC EQ 0. CONDENSE LW_FILE_PATH-FILEPATH. TRANSLATE LW_FILE_PATH-FILEPATH to LOWER CASE. CONCATENATE '/connectdirect/cdfiles/interface/' LW_FILE_PATH-FILEPATH INTO UNIX_PATH. "拼接路徑 CONCATENATE '/connectdirect/cdfiles/archive/' LW_FILE_PATH-FILEPATH INTO TARGET_UNIX_PATH. "這個能夠忽略 REFRESH: FILE_LIST. CALL 'C_DIR_READ_FINISH' 
        ID 'ERRNO'  FIELD WA_FILE_ATTR-ERRNO ID 'ERRMSG' FIELD WA_FILE_ATTR-ERRMSG. CALL 'C_DIR_READ_START' ID 'DIR'    FIELD UNIX_PATH "打開SAP應用服務器路徑 ID 'FILE'   FIELD '*'
                            ID 'ERRNO'  FIELD WA_FILE_ATTR-ERRNO ID 'ERRMSG' FIELD WA_FILE_ATTR-ERRMSG. IF SY-SUBRC NE 0. MESSAGE I208(00) WITH 'Cannot Open Specified Directory!'. EXIT. ENDIF. DO. CLEAR: WA_FILE_ATTR. 循環讀取該路徑下的文件 CALL 'C_DIR_READ_NEXT'
        ID 'TYPE'   FIELD WA_FILE_ATTR-TYPE
        ID 'NAME'   FIELD WA_FILE_ATTR-NAME ID 'LEN'    FIELD WA_FILE_ATTR-FSIZE ID 'OWNER'  FIELD WA_FILE_ATTR-OWNER ID 'MTIME'  FIELD WA_FILE_ATTR-MTIME ID 'MODE'   FIELD WA_FILE_ATTR-FMODE ID 'ERRNO'  FIELD WA_FILE_ATTR-ERRNO ID 'ERRMSG' FIELD WA_FILE_ATTR-ERRMSG. IF SY-SUBRC NE 0 AND WA_FILE_ATTR-NAME IS INITIAL. EXIT. ENDIF. CHECK: WA_FILE_ATTR-NAME IS NOT INITIAL. CHECK: WA_FILE_ATTR-TYPE NE 'directory'. "判斷目錄名稱 * CHECK: WA_FILE_ATTR-NAME CS '.txt' OR WA_FILE_ATTR-NAME CS '.dat' OR * WA_FILE_ATTR-NAME CS '.TXT' OR WA_FILE_.
      CHECK: WA_FILE_ATTR-NAME NS '.done' AND WA_FILE_ATTR-NAME NS '.DONE'. "檢查文件名稱中不能包含.DONE 和.done MOVE UNIX_PATH TO WA_FILE_ATTR-PATH. MOVE TARGET_UNIX_PATH TO WA_FILE_ATTR-TARGET_PATH. APPEND WA_FILE_ATTR TO FILE_LIST. 」把讀取得文件添加到內表中 ENDDO. CALL 'C_DIR_READ_FINISH'
        ID 'ERRNO'  FIELD WA_FILE_ATTR-ERRNO ID 'ERRMSG' FIELD WA_FILE_ATTR-ERRMSG. ELSE. MESSAGE E001 WITH INT_ID. " (No path maintained in table ZRCAFILEPATH for interface &1.)
  ENDIF. ENDMETHOD.
相關文章
相關標籤/搜索