SAP Flow

Anything can be done, it's just a matter of time and money…

How to get a path and extension from a file

When getting files from customer DMS we found a problem with extensions. If the file extension is not saved in DMS properties, there is no way how to pinpoint program associated in MS Windows with the ad hoc extension.
There is a way though to determine an extension explicitly from a file.

In SE37 you can find a function module called “CH_SPLIT_FILENAME”, that does the very thing.

CALL FUNCTION 'CH_SPLIT_FILENAME'
EXPORTING
complete_filename = lv_filename
* CHECK_DOS_FORMAT =
IMPORTING
* DRIVE =
extension = lv_doc_type
* NAME =
* NAME_WITH_EXT =
* PATH =
EXCEPTIONS
invalid_drive = 1
invalid_path = 2
OTHERS = 3.


Tagged as + Categorized as SAP, ABAP tips, SAP

1 Comments

  1. Unfortunately it’s not the perfect way how to parse file name.
    For example for the file “test.01.xml” it returns extension 01.xml and it’s not correct.

    What’s about something like this?

    DATA: lt_split TYPE string OCCURS 0 WITH HEADER LINE,
    l_file(100) TYPE c VALUE ‘test.01.xml’.

    SPLIT l_file AT ‘.’ INTO TABLE lt_split.

    LOOP AT lt_split.
    ENDLOOP.

    WRITE: / ‘Extension:’, lt_split.

    It should be better.

Leave a Reply