Application Development 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: 

How to split path and filename (file is on application server)

Former Member
0 Kudos

Searching this forum I found a couple of FM's that apparently only worked for PC files. Is there a parser function for files w/ the Unix naming convention?

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Steve

I have found the fm DSVAS_DOC_FILENAME_SPLIT also very useful.

Regards

Uwe

7 REPLIES 7

Former Member
0 Kudos

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/f4%2bfor%2bfiles%2bon%2bpresentation%2bo...

Check FM '/SAPDMC/LSM_F4_FRONTEND_FILE' and F4_dxfilename_toprecursion

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You could parse it yourself...

DATA: filepath TYPE char255 VALUE '/usr/<sys_id>/sap/tmp/filename.txt'.
DATA: path TYPE char255.
DATA: file TYPE char255.

DEFINE macro_reverse_string.

  call function 'STRING_REVERSE'
    exporting
      string  = &1
      lang    = sy-langu
    importing
      rstring = &1.

END-OF-DEFINITION.

macro_reverse_string filepath.
SPLIT filepath AT '/' INTO file path.
macro_reverse_string filepath.
macro_reverse_string file.
shift path right by 1 places. path(1) = '/'.
macro_reverse_string path.

WRITE:/ filepath.
WRITE:/ path.
WRITE:/ file.

Regards,

Rich Heilman

ThomasZloch
Active Contributor

yet another approach:

DATA: filepath TYPE char255 VALUE '/usr/<sys_id>/sap/tmp/filename.txt'.
DATA: path TYPE char255.
DATA: file TYPE char255.
DATA: dummy TYPE string.

CHECK filepath CA '/'.
dummy = filepath.
DO.
  SHIFT dummy RIGHT CIRCULAR.
  IF dummy(1) = '/'.
    SHIFT dummy LEFT CIRCULAR.
    SPLIT dummy AT '/' INTO file path.
    CONCATENATE '/' path INTO path.
    EXIT.
  ENDIF.
ENDDO.

WRITE:/ filepath.
WRITE:/ path.
WRITE:/ file.

Former Member

steve,

Use the fm TRINT_SPLIT_FILE_AND_PATH........ it will work.

uwe_schieferstein
Active Contributor
0 Kudos

Hello Steve

I have found the fm DSVAS_DOC_FILENAME_SPLIT also very useful.

Regards

Uwe

0 Kudos

Hi Guys,

you can also use FM 'SO_SPLIT_FILE_AND_PATH' and it works.

Cheers

Elmer

0 Kudos

Don't use FM 'SO_SPLIT_FILE_AND_PATH'... it seems to be not working correctly!