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

Splitting a filepath(along with filename) into two fields inside program

Former Member
0 Likes
1,096

Hi,

I need an urgent help here.

I have a selection screen parameter that has filepath+filename together (e.g.

C:\Documents and Settings\xyz\Desktop\test1.txt). So, I want to split it into 2 parts inside my program 1st for the filepath (i.e. 'C:\Documents and Settings\xyz\Desktop\') and 2nd for the filename (i.e. 'test1.txt').

Please help how to do it dynamically. I think we need to use string operators for it.

Regards,

Sanj.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
708

use the fm SO_SPLIT_FILE_AND_PATH

REPORT Zsplit_filename .

PARAMETERS: FILENAME TYPE RLGRAP-FILENAME .

DATA: STRIPPED TYPE RLGRAP-FILENAME.
DATA: FILE_PATH TYPE RLGRAP-FILENAME.


CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
FULL_NAME = FILENAME
IMPORTING
STRIPPED_NAME = STRIPPED
FILE_PATH = FILE_PATH
* EXCEPTIONS
* X_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

3 REPLIES 3
Read only

Former Member
0 Likes
709

use the fm SO_SPLIT_FILE_AND_PATH

REPORT Zsplit_filename .

PARAMETERS: FILENAME TYPE RLGRAP-FILENAME .

DATA: STRIPPED TYPE RLGRAP-FILENAME.
DATA: FILE_PATH TYPE RLGRAP-FILENAME.


CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
FULL_NAME = FILENAME
IMPORTING
STRIPPED_NAME = STRIPPED
FILE_PATH = FILE_PATH
* EXCEPTIONS
* X_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Read only

0 Likes
708

Hi Mohammed,

Thanks very much.. You solved my issue.

Regards,

Sanj.

Read only

Former Member
0 Likes
708

Hi,

Reverse the whole file path first.

Take sub string upto '\'.

Again reverse the substring.

Regards,

Aparna Gaikwad