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

Unix read statement

Former Member
0 Likes
1,510

Hi all ,

I want to read a filename from server .can any one reply me how to write unix read statement?

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,488

Hi all ,

I want to read a filename from server .can any one reply me how to write unix read statement?

Thanks

12 REPLIES 12
Read only

Former Member
0 Likes
1,488

data: YourFile(50).

data: TheStr(200).

YourFile = '/somedir/filename.txt'.

open dataset YourFile for input in text mode encoding default.

do.

read dataset YourFile into TheStr.

if sy-subrc <> 0.

exit.

endif.

  • do some business logic here

enddo.

close dataset YourFile.

Read only

0 Likes
1,488

Jhon ,

I dont want to open my file .I just want to read the server whether that file exisit or not .I just want read the server for a file name.

Thanks

Read only

0 Likes
1,488

Or call Func Mod - SCMS_FILE_CHECK_EXISTENCE

Read only

0 Likes
1,488

If the file exists, sy-subrc will be 0 (zero) upon returning from the FM call.

And don't forget points for helpful answers.

Read only

0 Likes
1,488

To prove it to yourself, find a file in a certain path on your UNIX and run the FM against it. SY-SUBRC will be ZERO.

Then delete (or move) the file and run again. SY-SUBRC will NOT be zero now.

Read only

Former Member
0 Likes
1,489
Read only

0 Likes
1,488

Naveen,

I dont want to upload data from unix file . i just want to check the directory for file existitance.

Thanks

Read only

0 Likes
1,488

Re: Unix read statement

Posted: Aug 14, 2006 11:36 AM Reply E-mail this post

data: YourFile(50).

data: TheStr(200).

YourFile = '/somedir/filename.txt'.

open dataset YourFile for input in text mode encoding default.

IF SY-SUBRC <> 0.

  • File does not exist

ENDIF.

Read only

Former Member
0 Likes
1,488

Priya,

Has your issue been resolved?

If so, please reward points accordingly and close the thread.

If not, please provide more details of the issue.

Thanks in advance.

Read only

0 Likes
1,488

Jhon ,

I think this f.m is only for frontend.

Read only

0 Likes
1,488

Priya,

It will handle frontend or your backend filesystem.

You must place an "X" into FRONTEND to search your client PC. You must leave FRONTEND as a blank to search your system's core filesystem.

Note the code of the Func Mod:

IF FRONTEND = 'X'.

  • handle frontend

s_filename = filename.

call method cl_gui_frontend_services=>file_exist

exporting

file = s_filename

receiving

result = result

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

WRONG_PARAMETER = 3

NOT_SUPPORTED_BY_GUI = 4

others = 5

.

if sy-subrc <> 0 or result <> 'X'.

raise not_found.

endif.

ELSE.

  • handle backend <<< Priya - here it looks to core filesystem

A_FILENAME = FILENAME.

CALL FUNCTION 'AUTHORITY_CHECK_DATASET'

EXPORTING

PROGRAM = 'ZDATASET'

ACTIVITY = SABC_ACT_READ

FILENAME = A_FILENAME

EXCEPTIONS

NO_AUTHORITY = 1

ACTIVITY_UNKNOWN = 2.

CHECK SY-SUBRC = 0.

OPEN DATASET FILENAME FOR INPUT IN BINARY MODE.

IF SY-SUBRC = 0.

CLOSE DATASET FILENAME.

ENDIF.

ENDIF.

IF SY-SUBRC <> 0.

RAISE NOT_FOUND.

ENDIF.

ENDFUNCTION.

And note that it actually performs a simple OPEN DATASET as I cited above to verify IF the file exists.

Read only

0 Likes
1,488

In most of the function modules SAP uses OPEN DATASET to check for file existance. That's the prefered method.

If ur app server is unix, you can try this:

data: v_cmd type rlgrap-filename,

v_fnam type rlgrap-filename.

data: begin of t_cmd occurs 0,

line(200),

end of t_cmd.

v_fnam = <full file name with path>

concatenate ls v_fnam into v_cmd separated by space.

call 'SYSTEM' id 'COMMAND' field v_cmd

id 'TAB' field t_cmd-sys.

if not t_cmd[] is initial.

write:/ v_fnam 'Exist'.

endif.

Regards

Sridhar