此博客为原创博客,都是个人工作经历所得,转载请注明出处

SAP文件夹的判断与创建

【转自 http://blog.csdn.net/saphome/article/details/6956918】

 

SAP文件夹存在的判断与创建

2010-08-29 20:15

相关函数:WS_QUERY:判断文件夹路径是否存在。GUI_CREATE_DIRECTORY:创建文件夹。

检查指定的文件夹是否存在,若不存在则创建新文件夹。

REPORT Z_EXAMPLE_01                            .

parameter: l_file type localfile.
data: status type c.

"保存文件夹的路径
data: begin of folder occurs 0,
dire type localfile,
end of folder.

"保存文件夹路径识别符号。
data: begin of sign occurs 0,
sig type c,
end of sign.

start-of-selection.
clear: folder[],sign[],status.
"新增文件夹路径识别符号,如果没有相关的符号则为无效路径
sign-sig = '/'.
append sign.
sign-sig = '\'.
append sign.
search l_file for sign.
"判断文件夹路径字符串是否有效,无效退出
if sy-subrc <> 0 .
    message e005(zmess) with 'not valuable directory!'.
    exit.
else.
    "检查该文件夹是否已经存在
    perform checkdir using l_file changing status.
    if status = 1.
      message e005(zmess) with 'the directory is exit!'.
      exit.
    endif.
endif.

split l_file at sign into table folder.
read table folder index 1.
l_file = folder-dire."内表的第一行为盘符
loop at folder.
    "循环读取文件夹字符,检查该路径是否存在,不在则创建
    if sy-tabix > 1.
      concatenate l_file '\' folder-dire into l_file.
      perform checkdir using l_file changing status.

      if status = 0.
        perform createrdir using l_file .

      endif.
    endif.
endloop.
*---------------------------------------------------------
*-检查路径是否存在,存在则函数返回1,不存在返回 0 --------
*---------------------------------------------------------
form checkdir using dir type localfile changing ret type c.
CALL FUNCTION 'WS_QUERY'
    EXPORTING
*   ENVIRONMENT          =
     FILENAME             = DIR
      QUERY                = 'DE'
*   WINID                =
   IMPORTING
     RETURN               = RET
   EXCEPTIONS
     INV_QUERY            = 1
     NO_BATCH             = 2
     FRONTEND_ERROR       = 3
     OTHERS               = 4.
ENDFORM.                    "checkdir
*---------------------------------------------------------
*-----根据路径创建文件夹----------------------------------
*---------------------------------------------------------
FORM CREATERDIR USING DIR TYPE LOCALFILE.
CALL FUNCTION 'GUI_CREATE_DIRECTORY'
    EXPORTING
      DIRNAME = DIR
    EXCEPTIONS
      FAILED = 1
      OTHERS = 2.
WRITE: / 'CREATE DIRECTOR SUCCESS,PATH:',DIR.
ENDFORM.                    "CREATERDIR

posted @ 2014-12-03 21:03  Rainystuday  阅读(508)  评论(0编辑  收藏  举报