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

Function module help

Former Member
0 Likes
996

Hi abapers,

I have 3 queries

1) I hv a parameter Filename.When i press f4 help the path of the application server should be displayed. Is there any function module?

2) When i manually enter the path say E:\usr\sap\file1.txt then it should check whether the path E:\usr\sap\ exist or not in the application server irrespective of the file name.

Also is there any function module where i can separate the directory and file name?

3) Suppose if i enter any any special characters say * or / or : etc it should also give an error message tht special characters are not allowed. is there any way for that?

thanks in advance,

Regards

Salish

7 REPLIES 7
Read only

Former Member
0 Likes
910

Hi,

1.Use FILE_GET_NAME function module. U can get the application server path. Pass client = sy-mandt, logical filename, operating system = sy-opsys.

2.You can use SPLIT command to separate the path .

Ex: SPLIT filename at '/' into gwa_input-var1 gwa_input-var2.... This way, the last variable will give u the filename.

3.The above functional module will automatically give u the physical location of the file. So, no need for this validation.

Hope this helps.

Regards,

Ramya

Read only

Former Member
0 Likes
910

Hi

Point 1:

Here you can use F4_FILENAME_SERVER function module

2) When i manually enter the path say E:\usr\sap\file1.txt then it should check whether the path E:\usr\sap exist or not in the application server irrespective of the file name.

Also is there any function module where i can separate the directory and file name?

Point 3:

Here you can perform the following syntax:

IF v_filename CA '*/%'.

MESSAGE e002(sy) with 'Filename contains special characters'.

ENDIF.

Read only

Former Member
0 Likes
910

Hi,

1) To provide F4 help for the application server, you can use the FM 'F4_DXFILENAME_TOPRECURSION'.

Ex:

v_l_path = '/TECHDATA/INTERFACES/IN/FIN/'.

  • In case Unix Server Radio button is checked

CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'

EXPORTING

i_location_flag = 'A'

i_server = ' '

i_path = v_l_path

filemask = '*'

  • FILEOPERATION = 'R'

IMPORTING

  • O_LOCATION_FLAG =

  • O_SERVER =

o_path = v_l_file

  • ABEND_FLAG =

EXCEPTIONS

rfc_error = 1

error_with_gui = 2

OTHERS = 3.

2) You can use following code for validation.

OPEN DATASET <File Path> FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

        • Message

ENDIF.

3) you can use SEARCH FOR command to check for the special characters in the path.

Regards,

Jallu

Read only

Former Member
0 Likes
910

Hi

Solution 1:

Use F4_FILENAME_SERVER function module or yppu can also use FM FILE_GET_NAME

Solution 2:

Taking into account the filename provided by you as E:\usr\sap\file1.txt.

Split Filename at '\' into var1,

var2,

var3.

* To get the Directory Name

Concatenate var1 var2 into v_directory

var3 contains your Filename.

Solution 3:

IF filename CA '*/%'.

Message for Invalid Filename.

ENDIF.

Reward Points if you find it useful.

Read only

0 Likes
910

Hi

Thanks for all of ur replies.

But the directory can be many u cannot use split.

Is there any fonction module tht can separate the filename and the directory name.

Thanks

Regards

Salish

Read only

0 Likes
910

Hi Salish,

Use the function module BC_TOOLS_PATH_FILE_SPLIT

Cheers.

Read only

Former Member
0 Likes
910

Hi ,

For the third solution.

You neeed to check for special characters in the Filename only.

after splitting, catch the filename in a variable v_filename.

IF v_filename CA '/%'.*

Message for Invalid Filename.

ENDIF.