cancel
Showing results for 
Search instead for 
Did you mean: 

Whether the file is present or not??

Former Member
0 Kudos

Hi,

I am trying to upload data from a file on application server.

How can i validate if the file is exiting or not.

It would be helpful if I can find whether the file exists or not before the statement "OPEN DATASET".

<b>NOTE: This is a SAP 3.1i version requirement.</b>

Accepted Solutions (0)

Answers (7)

Answers (7)

former_member188685
Active Contributor
0 Kudos

Hi,

you can use GET DATASET <b>attr</b>

TYPE-POOLS: dset.

data: attr type dset_attributes.

GET DATASET file ATTRIBUTES attr.

if the file is not there then it will raise the exception

<b>CX_SY_FILE_OPEN_MODE</b>

Regards

vijay

Former Member
0 Kudos

HI

1 Use the FM <b>'TMP_GUI_BROWSE_FOR_FOLDER'</b> to chose which folder U want to check.

2 U will be getting hte path of selected dir.

3 Pass this path to FM <b>'TMP_GUI_DIRECTORY_LIST_FILES'</b>.

4 U will e getting 2 tables one for files and nother for Dirs.

5 If U want to check the files the directory table simply loop over that with 'TMP_GUI_DIRECTORY_LIST_FILES'

OR U can use <b>TMP_GUI_GET_FILE_EXIST</b> (also checks directories)

IF THESE WORKS OUT FOR U PLEASE REWARD POINTS

REGARDS

ANOOP

Former Member
0 Kudos

for checking the file....in debugging mode check the sy-subrc value...

<b>Return Value</b>

<b>sy-subrc</b> <b>Description</b>

0 File was opened.

8 Operating system could not open file.

Message was edited by: Ashok Kumar Prithiviraj

Former Member
0 Kudos

Hi vinod,

1. before the statement "OPEN DATASET".

Before - it could be either a FM

or some abap statement to check

file existence !!!

2. In this case,

we can still use open dataset

(before the actual open dataset,

just to check the existence)

3. using this abap command,

we use MSG addition

and detect the error (file not found)

4. (just copy paste in new program)

report abc.

DATA: dsn(20) VALUE '/usr/test.dat',

msg(100).

OPEN DATASET dsn FOR INPUT MESSAGE msg

IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.

WRITE / msg.

STOP.

ENDIF.

regards,

amit m.

hymavathi_oruganti
Active Contributor
0 Kudos

Call the function PFL_CHECK_OS_FILE_EXISTENCE.

CALL FUNCTION 'PFL_CHECK_OS_FILE_EXISTENCE'

EXPORTING

FULLY_QUALIFIED_FILENAME = file

IMPORTING

FILE_EXISTS = file_exits

.

OPEN DATASET file FOR INPUT.

IF SY-SUBRC EQ 0.

FILE_EXISTS = 'X'.

CLOSE DATASET file.

ELSE.

CLEAR FILE_EXISTS.

ENDIF.

ENDFUNCTION.

u can also check in tcode AL11.

Message was edited by: Hymavathi Oruganti

Former Member
0 Kudos

u can using the fm DX_FILE_EXISTENCE_CHECK

Former Member
0 Kudos

Hai vinod,

Just go for F4 help and it displays all the files which you need.I have a code which does this.........

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

AT SELECTION-SCREEN ON VALUE-REQUEST FOR DATASET.

CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG'

EXPORTING

WINDOW_TITLE = 'select a file '

DEFAULT_EXTENSION = 'TXT'

DEFAULT_FILENAME = 'ASSIGN5.TXT'

  • FILE_FILTER =

  • INIT_DIRECTORY =

  • MULTISELECTION =

  • IMPORTING

  • RC =

TABLES

FILE_TABLE = ITAB

EXCEPTIONS

CNTL_ERROR = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

READ TABLE ITAB INDEX 1.

DATASET = ITAB-FILENAME.

WRITE DATASET.

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

START-OF-SELECTION.

*perform open_dataset using dataset.

*perform open_group.

DATA T TYPE STRING.

T = DATASET.

IF T EQ ' '.

MESSAGE E110(ZX).

ENDIF.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = T

  • FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = RECORD

  • EXCEPTIONS

  • FILE_OPEN_ERROR = 1

  • FILE_READ_ERROR = 2

  • NO_BATCH = 3

  • GUI_REFUSE_FILETRANSFER = 4

  • INVALID_TYPE = 5

  • NO_AUTHORITY = 6

  • UNKNOWN_ERROR = 7

  • BAD_DATA_FORMAT = 8

  • HEADER_NOT_ALLOWED = 9

  • SEPARATOR_NOT_ALLOWED = 10

  • HEADER_TOO_LONG = 11

  • UNKNOWN_DP_ERROR = 12

  • ACCESS_DENIED = 13

  • DP_OUT_OF_MEMORY = 14

  • DISK_FULL = 15

  • DP_TIMEOUT = 16

  • OTHERS = 17

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

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

When this code is executed it opens a window which allows you to select a file.......Hope this may work for you.

Regards,

Srikanth.

Please reward points if this is useful to you.thanks in advance

Former Member
0 Kudos

HI vinod

are you using GUI_UPLOAD to upload the file. then you can use the exceptions.

regards

kishore