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 to check if a file is already open

Former Member
0 Likes
4,045

Hi All,

Could any one of you tell me a function module which checks whether a given file on the application server is currently being open or not.

Regards

Amit Mishra

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,697

Amit,

Try GET DATASET.

Basic form

GET DATASET dsn.

Extras:

1. ... POSITION pos

2. ... ATTRIBUTES attr

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. For details, see File Interface.

Effect

Used to get the properties of a file already open.

You can use this statement without additions to determine whether the file is open.

If the file is not open, an exception of the type CX_SY_FILE_OPEN_MODE is triggered.

Regards,

Rao A

Message was edited by: Rao Arimilli

Hi All,

Could any one of you tell me a function module which checks whether a given file on the application server is currently being open or not.

Regards

Amit Mishra

11 REPLIES 11
Read only

Former Member
0 Likes
2,697

Try to open the dataset in write mode.

If it fails, that means it is already open.

catch the Catchable Exception

CX_SY_FILE_OPEN

after the open dataset statement

Cause: File is already open (only in Unicode programs)

Read only

0 Likes
2,697

Hi Ravi,

Actually the scenario is something like this.

If the file is open in read mode then anybody can open it in write mode, in that case it won't give any error.

All I need to check is, if the file is open at all. Mode is not important in my situation.

Regards

Amit Mishra

Read only

Former Member
0 Likes
2,697

Hi Amit Mishra,

1. There is no such FM/facility

by which we can know such thing.

2. However,

when we open the file in program,

the sy-subrc returned

tells that some error has occured,

and based on the value,

we can know, if its already opened!

regards,

amit m.

Read only

Former Member
0 Likes
2,697

Hi,

try to open the dataset it will fail to open and throw this CX_SY_FILE_OPEN .

the check the documentation..

Applying OPEN DATASET to a file already opened - in the same internal mode - triggers an exception of the type CX_SY_FILE_OPEN.

check the documentation on open dataset..

Read only

hymavathi_oruganti
Active Contributor
0 Likes
2,697

if with open data set, sy-subrc = 4, then file is already open

Read only

Former Member
0 Likes
2,697

use the FM FILE_OPEN

Read only

Former Member
0 Likes
2,697

hi amit,

when we use open dataset....instruction you can make use of the exception CX_SY_FILE_OPEN to see if the file open provided it is opened in unicode mode.

Read only

0 Likes
2,697

Hi,

you can try FM <b>EPS_OPEN_INPUT_FILE</b> and check .

or FM's <b>RZL_READ_FILE_LOCAL</b>

check the sy-subrc and decide

regards

vijay

Read only

Former Member
0 Likes
2,698

Amit,

Try GET DATASET.

Basic form

GET DATASET dsn.

Extras:

1. ... POSITION pos

2. ... ATTRIBUTES attr

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. For details, see File Interface.

Effect

Used to get the properties of a file already open.

You can use this statement without additions to determine whether the file is open.

If the file is not open, an exception of the type CX_SY_FILE_OPEN_MODE is triggered.

Regards,

Rao A

Message was edited by: Rao Arimilli

Read only

Former Member
0 Likes
2,697

Hi Arimilli,

Thanks. It's working fine for my scenario.

Regards

Amit Mishra

Read only

0 Likes
2,697

Hi Amit,

I have a same problem which you had earlier.

Could you please tell me how to solve the problem

Thanks and regards,

Mallareddy rayapureddy