‎2006 Dec 14 5:43 AM
Dear Abapers.
I have long text like folder path with file name.
My problem is I want to get file name from that text.
Please let me know how I can do this.
‎2006 Dec 14 5:46 AM
TRY WITH THIS
ZFNAME = 'D:\TEST1\TEST2\TEST3\TESTFILE.XLS'
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = ZFNAME
LANG = SY-LANGU
IMPORTING
RSTRING = ZFNAME
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ ZFNAME.
ELSE.
WRITE:/ 'ERROR REVERSING STRING'.
ENDIF.
*
SPLIT ZFNAME AT '\' INTO : ZFNAME1 ZFNAME2 .
*
ZFNAME = pr_file.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = ZFNAME1
LANG = SY-LANGU
IMPORTING
RSTRING = ZFNAME1
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ ZFNAME.
ELSE.
WRITE:/ 'ERROR REVERSING STRING'.
ENDIF.
‎2006 Dec 14 5:46 AM
TRY WITH THIS
ZFNAME = 'D:\TEST1\TEST2\TEST3\TESTFILE.XLS'
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = ZFNAME
LANG = SY-LANGU
IMPORTING
RSTRING = ZFNAME
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ ZFNAME.
ELSE.
WRITE:/ 'ERROR REVERSING STRING'.
ENDIF.
*
SPLIT ZFNAME AT '\' INTO : ZFNAME1 ZFNAME2 .
*
ZFNAME = pr_file.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = ZFNAME1
LANG = SY-LANGU
IMPORTING
RSTRING = ZFNAME1
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ ZFNAME.
ELSE.
WRITE:/ 'ERROR REVERSING STRING'.
ENDIF.
‎2006 Dec 14 5:51 AM
RY WITH THIS
ZFNAME = 'D:\TEST1\TEST2\TEST3\TESTFILE.XLS'
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = ZFNAME
LANG = SY-LANGU
IMPORTING
RSTRING = ZFNAME
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ ZFNAME.
ELSE.
WRITE:/ 'ERROR REVERSING STRING'.
ENDIF.
*
SPLIT ZFNAME AT '\' INTO : ZFNAME1 ZFNAME2 .
*
ZFNAME = pr_file.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = ZFNAME1
LANG = SY-LANGU
IMPORTING
RSTRING = ZFNAME1
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ ZFNAME.
ELSE.
WRITE:/ 'ERROR REVERSING STRING'.
ENDIF.
‎2006 Dec 14 5:57 AM
‎2006 Dec 14 5:54 AM
Hi,
If u have the text in the format c_path = D:\sap\abap\text.txt then if u want to get the only file name then u can write as c_path+13(8) but it works only in case there is fixed length of folder and also the file name.
‎2006 Dec 14 6:00 AM
hi,
try this code
data fname(30) type c.
FNAME = 'D:\TEST1\TEST2\TEST3\TESTFILE.XLS'
<b>perform filename.</b>
form filename.
data flag type x value 'x'.
data fname1(30) type c.
data index type i value 1.
data len type i.
WHILE flag = 'x'.
len = strlen( fname ).
if index = len.
write: / fname.
only file name will be available in fname.
flag = ''.
exit.
else.
if fname+index(1) = '\'.
fname1 = fname+index.
fname = fname1.
index = 1.
else.
index = index + 1.
endif.
endif.
ENDWHILE.
endform.
i think this will help u
‎2006 Dec 14 6:06 AM
Hi Gokul,
You can use <b>SPLIT </b>for this purpose.
<b>Logic:</b>
I am writing the code below. here i am using Split to split the string at character '\' and the splitted substrings will be polpulated into the internal table ZFNAME2[].
So the last entry of internal table will contain the filename.
<b>
Here is the code:</b>
<b>
DATA: </b>ZFNAME(60) type c,
ZFNAME2 like table of ZFNAME with header line,
NLINES TYPE I.
ZFNAME = 'D:\TEST1\TEST2\TEST3\TESTFILE.XLS'.
<b>SPLIT</b> zfname at '\' into table zfname2 .
<b>DESCRIBE TABLE</b> ZFNAME2 LINES NLINES.
<b>READ TABLE</b> ZFNAME2 INDEX NLINES.
<b>WRITE:</b> zfname2.
This will definitely solve your purpose,
Prgaya