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: 

hi i want to exit the program if no file found by FM call file_get name

Former Member
0 Kudos
369

HI

I am calling a function module which is picking up a file from utility server

presently its giving error message that if no file found it propts for error msg no file found or file could not be opened i suppose its coming by the FM only

now i want to write a code that if there is no file then the program should exit and not execute further but with no error mesage

pls suggest a code for this

regards

Arora

8 REPLIES 8

Former Member
0 Kudos
73

Hi,

Give these codes after the FM file_get:

IF fname = ' '.

leave to screen 0.

endif.

or if u want to com back to the selection screen then

if fname = ' '.

sy-ucomm = 'back'.

endif.

Thanks,

Arunprasad.P

Reward if useful.

0 Kudos
73

i suppoese ud dinnt got my point

the fnam is alrady been inputed in the screen and the function module is returning 0 sy-subrc = 0 already

only when open dataset is done the error message is being prompted when we do open dataset to read the file

1st q

the file does not exists in the server and path as givend in selection screen

but then why the FM call file_get_name

is returning zero it should return 8 rather????

2) then open dataset is coded

and there sy-subrc = 8 now

can i code leave program here????in case of sy-subrc <>0

is it right way to code and what other options are there??

basically i want to schedule a job which if there is no file should not fail hnce want to remove this msg from the program.

regards

arora

Former Member
0 Kudos
73

Hi nishant,

The function module call usually returns a value..for example if function module fails to fetch the file name as you said then it would return a non-zero value ..write your code in the sy-subrc check..

Eg:

Call function 'File_get'

exporting =

importing = ..etc

if sy-subrc NE 0.

*you can write any of the following

(1) Leave to screen 0. "returns to previous screen

(2) Leave Program "Goes out o session manager

(3) Leave to transaction XXX."where XXX is the transaction code of the program screen where user wants to be given

endif.

if it is already returning zero then you can write the codes

wherever the sy-subrc check fails, before throwing the error message to exit the program.........

(1) Leave to screen 0. "returns to previous screen

(2) Leave Program "Goes out o session manager

(3) Leave to transaction XXX."where XXX is the transaction code of the program screen where user wants to be given

Also check if the function module is giving you the correct values by indpendently executing the fxn module in se37 and passing the correct parameters.Maybe the correct parameters are not being passed and hence it is returning a different sy-subrc..if the function module after testing independently does not suit your purpose we need to search for an alternative solution

Pls check and revert

Reward if helpful

Regards

Byju

Edited by: Byju Edamana on Mar 20, 2008 3:47 AM

0 Kudos
73

hi Byju

i suppose i am not makingmyself vey clear i have stated my requirment in the earlier reply

the FM is returning Sy-subrc = 0

as in selection screen user is entering the name of file

hence its retruning zero but if i code as u suggested in

if sy-subrc = 0 then code leave program

sy-subrc is zero even if ehre is not file at the path as specified in teh FM and even if there is a file so always the program will terminate

i want to know as i made myself cleare

whey the FM is returning Zero when there is not file exists in teh utilty server of path as passed to the FM

secondly i have identified the place ehre the msg is coming and ie open dataset

here sy-subrc =8 so here i am coding leave program

is it write way to code?

or any otehr code exists

my requirement is just want to schedule a job with this progam and dont wat th job to fail whe ehter is no file in the server

regards

arora

0 Kudos
73

Hi nishant,

You can write the code at sy-subrc = 8 at the dataset ...since your requirement is to just stop the scheduling if file is not found or data cannot be processed

As suggested please run the function module independently in se37 and see if it works correctly for a file that exists....if so you need not worry at all since it is working correctly..otherwise you are using the function module in a wrong manner by not passing the correct parameters or wrongly passing the parameters...one way is to see if there is a function module documentation...as in se37 -> fxn module-> display -> if documentation existe..the "documentation" tab will be enabled...

fianlly check if the syntax and statements used to open dataset is correct..there is also such a possibility

pls check and revert....

reward if helpful

Regards

Byju

0 Kudos
73

hi

----


form open_a_file using p_infile_name

changing p_infile

*Tab delimeter

this is how using FM where var_file is the parameter name which is the file name as given in selection screen

concatenate p_file '.TXT' into var_file.

call function 'FILE_GET_NAME'

exporting

  • CLIENT = SY-MANDT

logical_filename = 'Z_USER_HOME_DATA' "'ZFILE'

operating_system = sy-opsys

parameter_1 = 'MM'

parameter_2 = 'PROCESS

parameter_3 = var_file

  • USE_PRESENTATION_SERVER = ' '

  • WITH_FILE_EXTENSION = ' '

  • USE_BUFFER = ' '

importing

emergency_flag = flag

file_format = format

file_name = p_infile.

*

  • EXCEPTIONS

  • FILE_NOT_FOUND = 1.

  • OTHERS = 2

if sy-subrc = 0.

why always the FM returns the sy-subrc = 0

even if no file exists in teh paths as specified

regarda

arora

0 Kudos
73

Hi Nishant,

Try to do as indicated in the following code below

*

FORM validate_app_file USING fp_file TYPE FILENAME-FILEINTERN.

data : l_fname(60).

CALL FUNCTION 'FILE_GET_NAME'

EXPORTING

LOGICAL_FILENAME = P_FILE

OPERATING_SYSTEM = SY-OPSYS

IMPORTING

FILE_NAME = L_FNAME

EXCEPTIONS

FILE_NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC = '0'.

OPEN DATASET L_FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE s007 DISPLAY LIKE c_e.

ELSE.

CLOSE DATASET l_fname.

ENDIF.

ENDIF.

Also find below the parameters for the function module and thier use

*************************************************************************

Interface of function module FILE_GET_NAME

IMPORT parameter

Function

CLIENT

Logical file names can be client-specific. Here you can specify the client to be used. The current client as stored in the system field SY-MANDT is used as default.

LOGICAL_FILENAME

Here you specify the logical filename. (Uppercase letters must be used!)

OPERATING_SYSTEM

Here you can specify the operating system for which to generate the appropriate file name. The application server's operating system as stored in the system field SY-OPSYS is used as default.

PARAMETER_1

PARAMETER_2

Here you can specify values that substitute the placeholders <PARAM_1> and <PARAM_2> in physical file names and paths.

USE_PRESENTATION

_SERVER

Specifies that the presentation server's operating system be used as the basis for generating a platform-specific file name.

WITH_FILE_EXTENSION

Specifies that the logical file name's data format be used as filename extension.

USE_BUFFER

Specifies that the customizing tables for converting platform-independent file names be buffered in main memory.

EXPORT parameter

Function

EMERGENCY_FLAG

If the returned value is not SPACE, then no physical path has been found for the logical filename under the current operating system. In this case the path specified in the profile parameter DIR_GLOBAL will be used as physical path.

FILE_FORMAT

Returns the data format defined for the logical file name. You can use this parameter to decide in which mode to open the file. It is also required as a parameter for DOWNLOAD of files to the presentation server.

FILE_NAME

Returns the fully instantiated platform-specific file name and path.

Exceptions

Function

FILE_NOT_FOUND

Raised if logical file name is not defined.

OTHERS

Raised if other errors occur.

***************************

Analyse your problem

***************************

If the function module cannot find a physical path for the current operating system (see parameter EMERGENCY_FLAG), this may have various causes:

the operating system is not defined in the customizing tables

the operating system is not assigned to a syntax group

no physical path is assigned to the logical path for the relevant syntax group

no logical path is assigned to the logical file name.

Please check and revert

Also Reward points for all helps.it encorages others to help u more

Regards

Byju

Edited by: Byju Edamana on Mar 20, 2008 11:06 AM

Former Member
0 Kudos
73

Try the below code.


TRY
   CALL... <<call FM>>

 CATCH <exception_name>
  <<Write your message here>>
ENDTRY.

Hope this helps.

Thanks,

Balaji