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

Problem in open data set

Former Member
0 Likes
4,500

HI All ,

I have file which i can read from GUI_UPLOAD but we need to read it

on OPEN DATASET for that i use the following code but i get in mess

No such file or directory

What i miss here since when i try to open it from start->run it's work and

also in GUI_UPLAOD but not in open data set

OPEN DATASET lv_path_file FOR INPUT IGNORING CONVERSION ERRORS

IN TEXT MODE ENCODING DEFAULT MESSAGE mess .

Regards

Alex

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,729

HI,

There is a basic difference between GUI upload and OPEN Dataset.

GUI uploads uploads file from presentation server into SAP. But Open dataset uploads from application server.

U seem to be trying to use open dataset for a file on ur desktop.

hope it helps,

Raj

28 REPLIES 28
Read only

Former Member
0 Likes
3,729

Hello,

FOR INPUT is to read a already existing file in the application server. You will have to use FOR OUTPUT if you are creating the file


OPEN DATASET lv_path_file FOR OUTPUT IGNORING CONVERSION ERRORS
IN TEXT MODE ENCODING DEFAULT MESSAGE mess .

Vikranth

Read only

0 Likes
3,729

HI Vikranth ReddY ,

the file is already exist so any idea ?

Regards

Alex

Read only

0 Likes
3,729

Hello Alex,

I thought you were trying to create a file after using GUI_UPLOAD.

If the file already exists, make sure you are passing the correct file path from AL11 also check if you are able to view the file through AL11. Also what is the value of SY_SUBRC after the open dataset?

Vikranth

Read only

0 Likes
3,729

HI Vikranth ,

I Create file in transction FILE and i use 'FILE_GET_NAME' FM

to read the file from the location but now the problem is that the read

dataset i getting subrc 4 and the file contain data so what can be the reason

in this case ?

OPEN DATASET lv_path_file FOR INPUT IGNORING CONVERSION ERRORS
  IN text  MODE ENCODING DEFAULT MESSAGE mess .

   DO.
      READ DATASET lv_path_file INTO ls_file.
      IF sy-subrc = 0.
        APPEND ls_file TO  lt_file .
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.

Thanks

Alex

Read only

0 Likes
3,729

Check whether the FM is returing logical file name or physical file name.

For OPEN DATASET, you need to specify the complete path.

Read only

0 Likes
3,729

Hi Alex,

What does the FM- FILE_GET_NAME return ?

Cross check before running the program using the file-name returned in earlier step by going to transaction AL11 (logical file paths for application server) and see if a file actually exists.

Plus the statement - OPEN DATASET <file> , needs not only the file directory path, but the complete file name,

i.e. say eg;- directory is TMP, in that a file by name "test.txt".

then ur filename value for OPEN DATASET should be "/tmp/test.txt".

Please try again this time.

Regards

Dedeepya C

Read only

0 Likes
3,729

HI dedeepya ,

it return the file path ( the full file path)

Regards

Alex

Read only

Former Member
0 Likes
3,730

HI,

There is a basic difference between GUI upload and OPEN Dataset.

GUI uploads uploads file from presentation server into SAP. But Open dataset uploads from application server.

U seem to be trying to use open dataset for a file on ur desktop.

hope it helps,

Raj

Read only

0 Likes
3,729

HI Rajat ,

i drop it to server ,

when the file was on the desktop i use gui upload and it work fine .

Regards

Alex

Edited by: Alex Dean on Mar 23, 2010 10:25 AM

Read only

0 Likes
3,729

Did you check authority (SU53 or SE16 on table SPTH) - Are you able to see the data from AL11, not only the file name in the list ?

SY-SUBRC = 4 is an EOF condition, check the linefeed default value in parameter abap/NTfmode (or add a [linefeed |http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_LINEFEED.htm]option to the OPEN DATASET)

Regards,

Raymond

Read only

0 Likes
3,729

HI Raymond

I am not see the file in AL11 ,

now i get sy-subrc = 0 after open data set but

the problem is that when i do read it's not opening (sy-subrc = 4 like below ) .any idea want could be the reason ?

READ DATASET lv_path_file INTO ls_file.
      IF sy-subrc = 0.

Regards

Alex

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,729

>

> I am not see the file in AL11 ,

> now i get sy-subrc = 0 after open data set but

> the problem is that when i do read it's not opening (sy-subrc = 4 like below ) .any idea want could be the reason ?

>

>

READ DATASET lv_path_file INTO ls_file.
>       IF sy-subrc = 0.

If you cannot see the file in the app server directory how do you expect to READ it

Read only

0 Likes
3,729

HI Suhas ,

the file is in server and i create entry in TR . file

when I do open data set i get subrc = 0,

i guess if it dont find the file the i get subrc 8 .

bu the read is not work well do you have any idea ?

p.s.

do you say that if the file is not exist in AL11 i cant read it so i need to create entry there

and dont use TR.FILE

Regards

Alex

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,729

What you are doing in FILE is basically creating logical filename & filepath. When you do so you donot create a physical file with its contents in the app server.

SY-SUBRC = 4 for READ DATASET implies that End Of File is reached & there are no contents in the file left to be read.

[http://help.sap.com/abapdocu_70/en/ABAPREAD_DATASET.htm|http://help.sap.com/abapdocu_70/en/ABAPREAD_DATASET.htm]

I think you have uploaded an empty file in the app server.

BR,

Suhas

PS: Try uploading the file to the app server using CG3Z trxn or CACS_FILE_COPY trxn & check if the READ DATASET stmt is failing.

Edited by: Suhas Saha on Mar 23, 2010 11:51 PM

Read only

0 Likes
3,729

If you don't see the file via AL11, you wont be able to read data with OPEN/READ DATASET. You must be able to see the filename in AL11 with an 'X' indicating that you are allowed to use it, and you must be able to display data when double-clicking on it.

On which OS do you operate, is there a text in the mess field after OPEN DATASET ?

Regards,

Raymond

Read only

0 Likes
3,729

Hi Raymond ,

What i want actually is that the user will define the file path VIA transaction file

and read it from my program

are you sure that this is not possible ? since when i do that i gui upload its works

but with open data set i don't get any data after the read data set as i mentioned in

my previos post .

Thanks

Alex

lc_lo_fname TYPE fileintern VALUE 'MY_FILE_NAME',

CALL FUNCTION 'FILE_GET_NAME'
    EXPORTING
      logical_filename = lc_lo_fname
      operating_system = sy-opsys
*     PARAMETER_1      = '01'
    IMPORTING
      emergency_flag   = lv_flag
      file_format      = lv_format
      file_name        = lv_file_name
    EXCEPTIONS
      file_not_found   = 1.

** Reading the contents of the physical file
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = lv_file_name
    IMPORTING
      filelength              = lv_file_length
    TABLES
      data_tab                = lt_file_tab
    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.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,729

How have you defined your logical file 'MY_FILE_NAME' ?

I think you have given a presentation server file (file is present on your PC hard disk) because of which GUI_UPLOAD is working.

BR,

Suhas

Read only

0 Likes
3,729

HI ,

I give the file path define term for my file under logical file path than double click

on assignments of Physical path ,

in put my system and the Physical path like
vms025\shared\<FILENAME>

and in the physical file i put the file like user.csv

data format ASC

application area BC

ETC

How can i drop the file in AL11 ?

Regards

ALex

Edited by: Alex Dean on Mar 24, 2010 10:35 AM

Read only

0 Likes
3,729

If the file is defined on application server use OPEN DATASET, on operation system use GUI_UPLOAD. You may add a radiobuttion on selection-screen (PC/Appl) and use this flag in

- FILE_GET_NAME (filling OPERATING_SYSTEM parameter from the selected option)

- Main program read data form with a IF/OPEN DATASET/ELSE/GUI_UPLOAD/ENDIF

Regards,

Raymond

Read only

0 Likes
3,729

HI Raymond ,

You say in your previos post that the file need to be in application in order to use it

i.e. AL11 if not i cant use it in open data set ,so how i can put the file fin AL11 ?

Regards

Alex

Read only

0 Likes
3,729

You can copy from/to application/presentation server via transactions like CG3Y and CG3Z or via tools on the application server (out of SAP)

If you want the file to be on presentation server you can use a CALL METHOD cl_gui_frontend_services=>file_open_dialog

Regards,

Raymond

Read only

RaymondGiuseppi
Active Contributor
0 Likes
3,729

- GUI_UPLOAD load a file from presentation server (PC, windows, eg: C:\)

- OPEN DATASET load a file from application server (see transactions AL11, FILE, platform dependant)

Where is your file stored ?

Regards,

Raymond

Read only

0 Likes
3,729

HI Raymond ,

I Create file in transaction file and i use 'FILE_GET_NAME' FM

to read the file from the location but now the problem is that the read

dataset I getting subrc 4 and the file contain data so what can be the reason

in this case ?

OPEN DATASET lv_path_file FOR INPUT IGNORING CONVERSION ERRORS
  IN text  MODE ENCODING DEFAULT MESSAGE mess .

   DO.
      READ DATASET lv_path_file INTO ls_file.
      IF sy-subrc = 0.
        APPEND ls_file TO  lt_file .
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.

Thanks

Alex

Read only

MariaJooRocha
Contributor
0 Likes
3,729

Hi,

Did you check autohorizations? For server application SAP uses other than your username.

Best regards,

Maria João Rocha

Read only

0 Likes
3,729

HI ,

I dont think that this relate to authorisation since it's not fail in open data set ,

i get subrc = 0 .

Regards

Alex

Read only

0 Likes
3,729

How is your ls_file declared, try changing it into a variable of type string or use a field symbol and try.

Read only

Former Member
0 Likes
3,729

If u UPLOAD FILE Then u can not use OPEN DATASET lv_path_file FOR INPUT but u can use

OPEN DATASET iv_path FOR OUTPUT insted of input u use output

Example :-


htab = cl_abap_char_utilities=>horizontal_tab.

  OPEN DATASET filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

Read only

Former Member
0 Likes
3,729

Hey Alex,

If you want user to enter the file path ( on application server ), please use FM /SAPDMC/LSM_F4_SERVER_FILE instead of FILE_GET_NAME.

If you are not able to see your folder or file with this FM, please check for authorization with your BASIS team.

Hope it helps,

Raj