09-27-2007 3:07 PM
Hi experts,
I have a file path like this: /usr/sap/KLD/DVEBMGS10/data/test.txt.This i want to split /usr/sap/KLD/DVEBMGS10/data/ into one variable and test.txt into another variable.How can we do it with out using any FM? But this path will come dynamically
Regards
Ravi.
09-27-2007 3:11 PM
Hi,
First u get the length of the path and then u can move ur filename(28) to one varaiable and remaining text to another variable .
It will be ok ..
Cheers,
Simha.
09-27-2007 3:11 PM
Hi,
First u get the length of the path and then u can move ur filename(28) to one varaiable and remaining text to another variable .
It will be ok ..
Cheers,
Simha.
09-27-2007 3:16 PM
Hi ,
Thanks.But can i find the last occurance of '/' in that string and read the left part of the string into one variable?
Regards
09-27-2007 3:23 PM
Do it the way I suggested and it doesn't matter how long the filename is or how many '/'s are in it. Just take the last entry in the internal table.
Rob
Message was edited by:
Rob Burbank
09-27-2007 3:29 PM
Like:
REPORT ztest MESSAGE-ID 00.
DATA: file_name TYPE string VALUE
'/usr/sap/KLD/DVEBMGS10/data/test.txt',
no_lines TYPE i.
DATA itab TYPE TABLE OF string WITH HEADER LINE.
SPLIT file_name AT '/' INTO TABLE itab.
DESCRIBE TABLE itab LINES no_lines.
READ TABLE itab INDEX no_lines.
WRITE: /001 itab.
Rob
09-27-2007 3:13 PM
Split the whole thing at dot first '.'.
data:
gv_path(100) type c value '/usr/sap/KLD/DVEBMGS10/data/test.txt',
gv_first(50) type c,
gv_next(50) type c.
split gv_path at '.' into gv_first gv_next.
then split gv_first at '/' into 6 differnet parts..finally take the last part here and concatenate with gv_next..
Hope this may be helpful
09-27-2007 3:15 PM
Something like split filename at '/' into table itab. and take the last row.
Rob
09-27-2007 3:17 PM
Hi,
Use this code.
PERFORM split_dir USING gv_unproc.
FORM split_dir USING iv_fullpath TYPE string.
DATA:
lv_temp type I.
lv_temp = strlen( iv_fullpath ) - 1.
if lv_temp <= 0.
message text-e01 type 'E'.
endif.
while ( iv_fullpath+lv_temp(1) NE '\' ).
subtract 1 from lv_temp.
if lv_temp <= 0.
message text-e01 type 'E'.
endif.
endwhile.
add 1 to lv_temp.
lv_len = strlen( iv_fullpath ) - lv_temp.
gv_path = iv_fullpath(lv_temp).
Sri
09-27-2007 3:21 PM
Hi Ravi,
if the path is fixed except the filename then you can do it.
just count number of characters before test.txt...
and put this code (suppose number of chars is 30 of /usr/sap/KLD/DVEBMGS10/data/):
move: ws_path+0(30) to ws_fixedpath,
ws_path+30 to ws_file.
Hope it will solve the problem.
Regards
Krishnendu
09-27-2007 3:23 PM
Use this function module.
report zrich_0001 .
data: fullname like rlgrap-filename.
data: stripped_name like rlgrap-filename.
data: file_path like rlgrap-filename.
fullname = '/usr/sap/KLD/DVEBMGS10/data/test.txt'.
call function 'SO_SPLIT_FILE_AND_PATH'
exporting
full_name = fullname
importing
stripped_name = stripped_name
file_path = file_path.
write:/ file_path.
write:/ stripped_name.
Regards,
Rich Heilman
09-27-2007 6:35 PM
Try: -
data: v_string type string value '/usr/sap/KLD/DVEBMGS10/data/test.txt',
v_path(72) type c,
v_file(72) type c.
data: begin of i_split occurs 0,
sp(72) type c,
end of i_split.
split v_string at '/' into table i_split.
delete i_split where sp = ' '.
loop at i_split.
if i_split-sp cp '.'.
v_file = i_split-sp.
else.
concatenate v_path i_split-sp into v_path separated by '/'.
endif.
endloop.
write:/ v_path, v_file.