Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Word Reverse

Former Member
0 Likes
931

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
800

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.

6 REPLIES 6
Read only

Former Member
0 Likes
801

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.

Read only

0 Likes
800

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.

Read only

0 Likes
800

Thanks Nelson

Read only

Former Member
0 Likes
800

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.

Read only

Former Member
0 Likes
800

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

Read only

Former Member
0 Likes
800

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