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,048

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

8 REPLIES 8
Read only

Former Member
0 Likes
986

Hi,

READ DATASET is used to read data from the application server.

If you want to read data from presentation server then use the FM GUI_UPLOAD.

pls elaborate ur reuirement

Regards,

Rahul

Read only

Former Member
0 Likes
986

hello bhaskaran,

you have not written your code.

rgrds,

Shweta

Read only

Former Member
0 Likes
986

I dont have idea about read dataset to read a file either..

try gui_upload

Regards,

Sumit.

DATA P_FILET  TYPE STRING.

CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                = P_FILET
      FILETYPE                = 'DAT'
    TABLES
      DATA_TAB                = IT_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
      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.

Read only

Sandra_Rossi
Active Contributor
0 Likes
986

WHAT PROBLEM DO YOU HAVE ? (we won't spend time to read your code and find all the eventual bugs)

Read only

Former Member
0 Likes
986

Hi,

This code may be of some help..

chk out:

*Open the flat file present in the given location to read the data in

*text mode

OPEN DATASET LV_FILENAME FOR INPUT IN TEXT MODE.

*Throw an error when the file is unavailable

IF SY-SUBRC <> 0.

MESSAGE E127(SY) WITH LV_FILENAME.

ENDIF.

DO.

*Read the file from Unix and move the data to the work area

READ DATASET LV_FILENAME INTO WA_DATAFILE.

*Check for the existance of data

IF SY-SUBRC NE 0.

EXIT.

ENDIF.

*Close the flat file after the data is copied to the internal table

CLOSE DATASET LV_FILENAME.

Read only

Former Member
0 Likes
986

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
986

if you want to read a flat file you need to use gui_upload

try this example for more info

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

Read only

Former Member
0 Likes
986

ee