We have moved our domain from sapnuts.com to zapnuts.com, please bookmark and share.

SAP ABAP Split Filename from Path

Author | Last Updated| | 0 Comments Facebook Share Twitter Share Google Plus Share A+ A-

Split filename from application server or presentation server file path using SAP ABAP

Below is the SAP ABAP code to split filename from file path, this logic will work for both application server path and presentation server path.

    DATA: it_parts TYPE string_table,
          lv_split TYPE c,
          lv_lines TYPE i.
    DATA: lv_path type STRING,
          lv_file type STRING.
    lv_path = 'C:\Users\sapnuts\Desktop\sapnuts.xlsx'.
    IF lv_path IS INITIAL.
      RETURN. "Return if path is initial
    IF lv_path CS '/'.
      lv_split = '/'.
    ELSEIF lv_path CS '\'.
      lv_split = '\'.
      lv_file = lv_path. "no path separator is found, then the path must be the filename
    SPLIT lv_path AT lv_split INTO TABLE it_parts . "Split path at "/\" into string table
    DESCRIBE TABLE it_parts LINES lv_lines.
    READ TABLE it_parts INTO lv_file INDEX lv_lines. "Return last part

Other alternatives for getting file name from file path, Function Modules CH_SPLIT_FILENAME and RSDS_SPLIT_PATH_TO_FILENAME

Tutorial Comments

Total Comments: Add your Comment

Leave a Comment

Enter Comment Text