【原创】ABAP根据文件路径获取文件所在目录

 1 *&---------------------------------------------------------------------*
 2 *&      Form  frm_get_path
 3 *&---------------------------------------------------------------------*
 4 *       获取文件所在目录
 5 *----------------------------------------------------------------------*
 6 *      -->IV_FULLPATH  文件全路径
 7 *      -->CV_PATH      文件所在目录
 8 *----------------------------------------------------------------------*
 9 FORM frm_get_path USING     iv_fullpath TYPE string
10                   CHANGING  cv_path     TYPE string.
11   DATA: lv_length       TYPE i,
12         lv_index        TYPE i,
13         lv_total_lines  TYPE i,
14         lt_split_table  TYPE TABLE OF string.
15 
16   FIELD-SYMBOLS: <ls_split_table> LIKE LINE OF lt_split_table.
17 
18 * 检查文件全路径参数是否为空
19   lv_length = strlen( iv_fullpath ) - 1.
20   CHECK lv_length GE 0.
21 
22 * 检查文件全路径参数是否是文件目录格式
23   IF iv_fullpath+lv_length(*) = '\'.
24     cv_path = iv_fullpath.
25     EXIT.
26   ENDIF.
27 
28 * 获取文件所在目录
29   SPLIT iv_fullpath AT '\' INTO TABLE lt_split_table.
30   DESCRIBE TABLE lt_split_table LINES lv_total_lines.
31   LOOP AT lt_split_table ASSIGNING <ls_split_table>.
32     lv_index = lv_index + 1.
33     IF lv_index = 1.
34       CONCATENATE <ls_split_table> '\' INTO cv_path.
35     ELSEIF lv_index = lv_total_lines.
36       CONTINUE.
37     ELSE.
38       CONCATENATE cv_path <ls_split_table> '\' INTO cv_path.
39     ENDIF.
40   ENDLOOP.
41 
42 ENDFORM.                    "frm_get_path

  结果如下图:

 

【原创博文,欢迎大家批评指正!如需转载请注明出处 http://www.cnblogs.com/shelwin/p/3253171.html 】

posted @ 2013-08-12 16:50  Shelwin的世界  阅读(2627)  评论(0编辑  收藏  举报