Application Development 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: 

how to check whether a file exists in the system while uploading

Former Member
0 Kudos

Hi guys,

I m trying to upload a excel from presentation server.I m using F4 help for the field to find the location of the file in the presentation server.If i give some file name which doesn't exist in the file path and select execute it is going to dump.So i need to find whether the given file name exists or not in the system.

I have to search whether the give file name in the file path exists in the system or not.How can I do that.Any suggestions please.

Thank you.

9 REPLIES 9

Former Member
0 Kudos

Hi DP ,

I assume that you are using FM to give the F4 help for the file , in that FM are you handelling the exceptions.

If you do not handle the execptions then the program will Dump.

So please check in your code if the exceptions are commented , if they are the plase uncomment it , and handle the exception by giving some message.

Regards

Arun

Former Member
0 Kudos

Hi

May be if you handle the exception for the F4 help FM you may not get the dump itself. Or else you can use the class method cl_gui_frontend_services-FILE_EXIST

to check if the file is present or not in presentation server.

~Ranganath

Reward points for all useful answer !!

rainer_hbenthal
Active Contributor
0 Kudos

check class cl_gui_front_endservices, method FILE_EXIST

varma_narayana
Active Contributor
0 Kudos

Hi..

You can call the method:

<b>CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST</b>

This method returns whether file exists on Not.

<b>REWARD IF HELPFUL</b>

Former Member
0 Kudos

Hi guys,

Thanks for the replies.

I too found the found the method.But I m having problem with the parameters.I m exporting the filename to the funtion module,but i don't find a parameter in the function exporting the result.but there is a parameter resulting.Can anyone tell me what are the parameters should i give for this method.

Thanks.

0 Kudos

Hi ,

If you are using the method FILE_EXIST , then it is exporting a parameter called RESULT .

If the method return the value of this parameter as <b>X</b> it means that the file exist and if it is blank the the file does not exist.

Regards

Arun

0 Kudos

Hi

Use the returning arguement to check the result whether file exitst or not ... And pass the file name for the importing arguement FILE to this method.

~Ranganath

0 Kudos

Hi,

chek the below code

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST

EXPORTING

FILE = W_FILENAME

RECEIVING

RESULT = W_RESULT

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

WRONG_PARAMETER = 3

NOT_SUPPORTED_BY_GUI = 4

others = 5.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-* MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF W_RESULT IS INITIAL.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXIST

EXPORTING

DIRECTORY = W_FILENAME

RECEIVING

RESULT = W_RESULT

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

WRONG_PARAMETER = 3

NOT_SUPPORTED_BY_GUI = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

ENDIF.

ENDIF.

IF W_RESULT = 'X'.

RC = '1'.

ELSE.

RC = '0'.

ENDIF.

reward if helpful.

Regards,

nagaraj

0 Kudos

Hi nagraj,

The answer u gave is helpful.I assigned points to u.But i still have a problem.When i gave a filename which doesn't exist (to test the method), it is still returning the result as 'X'.The prog is going for dump.Actually i have to upload only csv file everytime.Does the extension of the filename make any difference to this method.Any suggestions.

Thanks.