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 to read data set from flat file

Former Member
0 Likes
1,026

Hi Friends,

I'm getting problem in reading data from the flat file using the READ DATASET statement.

I have include coding below

With Regards,

Baskaran

DATA: X_INPUT_REC,

REC_TYPE(4) TYPE C.

DATA: BEGIN OF ITAB OCCURS 0,

LEN(6),

WED(6),

END OF ITAB.

DATA: G_INREC(80) .

data: FILEN TYPE I.

DATA: L_EOF(50) VALUE 'C_FALSE'.

PARAMETERS: FILENAME(80) DEFAULT 'C:\Documents and Settings\Administrator.ACERMATELP1\Desktop\sample.txt' .

CONCATENATE FILEN INTO FILENAME NO-GAP.

OPEN DATASET FILENAME FOR INPUT IN TEXT MODE." MESSAGE L_MSG.

WHILE L_EOF NE C_TRUE.

READ DATASET FILENAME INTO G_INREC.

CONCATENATE G_INREC INTO G_INREC NO GAP.

IF SY-SUBRC = 0.

MOVE G_INREC TO ITAB.

  • ENDCASE.

ELSE.

L_EOF = C_TRUE.

CONTINUE.

ENDIF.

ENDWHILE.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
993

Hi,

READ DATASET is used to read file from Application server.

U r trying to read data from presentation server i.e. from PC for this u have to use FM GUI_UPLOAD.

Regards,

Rahul Wagh

9 REPLIES 9
Read only

Former Member
0 Likes
994

Hi,

READ DATASET is used to read file from Application server.

U r trying to read data from presentation server i.e. from PC for this u have to use FM GUI_UPLOAD.

Regards,

Rahul Wagh

Read only

Former Member
0 Likes
993

HI:

Read dataset is being used if you read data directly from Application server.

Here you are reading data from presentation server so Read dataset would not work.

Use the function module GUI_UPLOAD for it.

Regards

Shashi

Read only

Former Member
0 Likes
993

hi,

i dont think read data set will work for out side flat file, it only reads the data in application server. if need to get data from flat file u should use ws_upload etc function modules, get f1 help at the open dataset and read data set statements.

thanq,

rajesh.k

Read only

Former Member
0 Likes
993

hi

use gui_upload instead of read dataset

try this link

http://saplab.blogspot.com/2007/10/sample-abap-program-to-upload-table.html

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
993

This message was moderated.

Read only

Former Member
0 Likes
993

Hello Baskaran

You should not use the READ DATASET statement to read from presentation server. It should be used only for reading data from files on application server.

In your case you should use the following code:

DATA: lt_data TYPE STANDARD TABLE OF char80.

CALL METHOD cl_gui_frontend_services=>gui_upload
  EXPORTING
    filename                = 'C:\Documents and Settings\Administrator.ACERMATELP1\Desktop\sample.txt'
  CHANGING
    data_tab                = lt_data
  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
    not_supported_by_gui    = 17
    error_no_gui            = 18
    OTHERS                  = 19.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

lt_data contains the entire data of file in it. You can then process it further as you wish.

Thanks and best regards

Anand.

Read only

Former Member
0 Likes
993

Read dataset statement is use to read the file from application server, to read the frile file from presentation server use FM GUI_Upload. In this FM you need to pass full file name (i.e. c:\text.txt) and you can get the contents of file into a internal table as output.

Read only

Former Member
0 Likes
993

Hi,

To read the data from application server:

DATA: lv_app_server_file TYPE string.

lv_app_server_file = pa_afile.

  • To read file from Application server

OPEN DATASET lv_app_server_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET lv_app_server_file INTO wa_file_data.

IF sy-subrc = 0.

APPEND wa_file_data TO gi_file_data.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET lv_app_server_file.

To upload the data from text file from machine:

lv_filetype = 'ASC'.

lv_gui_sep = 'X'.

lv_file_name = pa_dfile.

  • FM call to upload file

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file_name

filetype = lv_filetype

has_field_separator = lv_gui_sep

TABLES

data_tab = gi_zhralcon_file.

Regards,

Rajesh Kumar

Read only

Former Member
0 Likes
993

Question was answered