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

Directory existence check (Application server)

Peter_Inotai
Active Contributor
0 Likes
4,398

Hi,

What is the best way to check directory existence in the application server?

'OPEN DATASET gv_dir.' seems to work in HP-UNIX, however as far as I know OPEN DATASET is for files.

I checked FM 'EPS_GET_DIRECTORY_LISTING' it calls kernel to check dir existence, which is not s good idea to use it in customer programs:

  CALL 'C_DIR_READ_START'
        ID 'DIR'    FIELD DIR_NAME
        ID 'FILE'   FIELD FILE_MASK
        ID 'ERRNO'  FIELD FILE-ERRNO
        ID 'ERRMSG' FIELD FILE-ERRMSG.
  IF SY-SUBRC <> 0.
    RAISE READ_DIRECTORY_FAILED.
  ENDIF.

Any idea?

Thanks in advance,

Peter

1 ACCEPTED SOLUTION
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
2,236

Hi Peter

Although it uses kernel function call, you can use it if otherwise is not stated in official documentation. Because the call is wrapped by a usual function module, its availability is somehow guaranteed I think.

Moreover, I guess there are lots of ABAP developers who directly use kernel function calls although it is not so recommended.

*--Serdar

Hi,

What is the best way to check directory existence in the application server?

'OPEN DATASET gv_dir.' seems to work in HP-UNIX, however as far as I know OPEN DATASET is for files.

I checked FM 'EPS_GET_DIRECTORY_LISTING' it calls kernel to check dir existence, which is not s good idea to use it in customer programs:

  CALL 'C_DIR_READ_START'
        ID 'DIR'    FIELD DIR_NAME
        ID 'FILE'   FIELD FILE_MASK
        ID 'ERRNO'  FIELD FILE-ERRNO
        ID 'ERRMSG' FIELD FILE-ERRMSG.
  IF SY-SUBRC <> 0.
    RAISE READ_DIRECTORY_FAILED.
  ENDIF.

Any idea?

Thanks in advance,

Peter

5 REPLIES 5
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
2,237

Hi Peter

Although it uses kernel function call, you can use it if otherwise is not stated in official documentation. Because the call is wrapped by a usual function module, its availability is somehow guaranteed I think.

Moreover, I guess there are lots of ABAP developers who directly use kernel function calls although it is not so recommended.

*--Serdar

Read only

nablan_umar
Product and Topic Expert
Product and Topic Expert
0 Likes
2,236

OPEN DATASET FOR OUTPUT should work since it will give an error if the file you tried to create in a server directory can't be created because of invalid directory/path. You can use dummy filename.

Read only

Former Member
0 Likes
2,236

Hi,

You can check the directory in the application server using the transaction AL11.

Also as said by one of the friend it gives a short dump 'DATASET_CANT_OPEN' if there is no such directory in the application server (while using OPEN DATASET).

I hope this helps.

Read only

Former Member
0 Likes
2,236

You can use OPen dataset,but if you want to validate at At selection-screen then we need to use diffrent logic,i have written the code as below for one of my program.

Below is the code to get all the files falling in the directory...... .

data: begin of t_tabl occurs 0,

line(132),

end of t_tabl,

data: lc_command(100) type c.

  • Get all the file name falling under specified directory...

lc_command(3) = 'ls '.

lc_command+3(45) = p_dir. " Directory of file path

call 'SYSTEM' id 'COMMAND' field lc_command

id 'TAB' field t_tabl-sys.

  • Check any files exits in the directory.......................

if t_tabl[] is initial.

message e006 with 'No files exist in the specified directory ' p_dir.

endif.

Above step will give you the all the fiels falling under the directory specified. But you have to loop through the internal table t_tabl to find the required files for eg: if you know the start few letters of the file name which are going to be constant always....like CWD_CNF*..

To delete the files.

loop at t_tabl.

lc_command(3) = 'rm'.

lc_command+3(45) = t_tabl-line.

call 'SYSTEM' id 'COMMAND' field lc_command

id 'TAB' field t_tabl-sys.

endloop.

Thanks

Seshu

Read only

former_member189059
Active Contributor
0 Likes
2,236

Hello Peter,

This function module is the best !

PFL_CHECK_DIRECTORY