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

Cut\Replace String ?

Former Member
0 Likes
899

Given a String : 'c:\corp\dir\filename.pdf' .

I need to remove or replace with ' ' anything that comes after the last '\'.

The Replace has 'All occurences of ' or 'first occurence of' but not anything like last occurence .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
857

Hi,

YOu can use the fm:

SO_SPLIT_FILE_AND_PATH

sample usage:

CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = fname

IMPORTING

stripped_name = short_fname

file_path = fpath

EXCEPTIONS

x_error = 1

OTHERS = 2.

Regards,

ravi

6 REPLIES 6
Read only

Former Member
0 Likes
858

Hi,

YOu can use the fm:

SO_SPLIT_FILE_AND_PATH

sample usage:

CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = fname

IMPORTING

stripped_name = short_fname

file_path = fpath

EXCEPTIONS

x_error = 1

OTHERS = 2.

Regards,

ravi

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
857

Please see this sample program.




REPORT ZRICH_0005 .

data: FULLNAME TYPE RLGRAP-FILENAME value 'C:tempfoldertext.txt' .

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


CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
  EXPORTING
    FULL_NAME           = FULLNAME
 IMPORTING
   STRIPPED_NAME       = filename
   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.

write:/ fullname.
write:/ file_path.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
857

Translate String using '/ '.

Read only

Former Member
0 Likes
857

Hi,

lv_data
lv_len

lv_len = strlen(lv_data).

n = lv_len
do n times.

  if lv_data+lv_len(1) = ''.
     lv_data = lv_data+0(lv_len).  
  else.
    lv_len = lv_len - 1.
  endif.
  
endo.

Reward points & mark Helpful Answers

Read only

Former Member
0 Likes
857

Another way

split filename at '/' into table itab.

describe table itab lines v_lines.

loop at itab

if sy-tabix <> v_lines.

concatenate lv_filename itab-data into lv_filename separated by '/'.

endloop.

endloop.

lv_filename = lv_filename+1.

Read only

Former Member
0 Likes
857

hi,

data: fname  LIKE rlgrap-filename,
      short_fname    LIKE rlgrap-filename,
      fpath          LIKE rlgrap-filename.
fname = 'c:corpdirfilename.pdf'.
  CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
    EXPORTING
      full_name     = fname
    IMPORTING
      stripped_name = short_fname
      file_path     = fpath
    EXCEPTIONS
      x_error       = 1
      OTHERS        = 2.

regards

vijay