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

split

Former Member
0 Likes
1,096

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.

1 ACCEPTED SOLUTION
Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
1,038

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.

10 REPLIES 10
Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
1,039

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.

Read only

Former Member
0 Likes
1,038

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

Read only

Former Member
0 Likes
1,038

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

Read only

Former Member
0 Likes
1,038

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

Read only

abdulazeez12
Active Contributor
0 Likes
1,038

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

Read only

Former Member
0 Likes
1,038

Something like split filename at '/' into table itab. and take the last row.

Rob

Read only

Former Member
0 Likes
1,038

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

Read only

Former Member
0 Likes
1,038

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

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,038

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

Read only

Former Member
0 Likes
1,038

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.