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: 

read from flat file --> internal table please help.

Former Member
0 Kudos

Hello ABAP Experts,

I have a requirement to read a text file containing three fields and read them into the internal table. Could you show me a sample code.

Any help is highly appreciated.

Any docs or code mail to mgmswsol@gmail.com

Thanks,

BWer

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello,

Just create an internal table with your 3 fields

data: begin of ti_data occurs 0,

fld1 type c,

fld2 type c,

fld3 type c,

end of ti_data.

To read the file just call this FM:

ALL FUNCTION 'TB_LIMIT_WS_UPLOAD'

EXPORTING

filename = Root to your file

filetype = 'ASC'

IMPORTING

filelength = length

TABLES

data_tab = ti_data.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Hope this helps

Gabriel

8 REPLIES 8

former_member181962
Active Contributor
0 Kudos

Hi,

use the function gui_upload to do the same.

data:begin of i_data occurs 0,

uomcode(2),

uomvalue(30),

end of i_data.

call function 'GUI_UPLOAD'

exporting

filename = 'C:\test.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = '#'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = i_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

.

Former Member
0 Kudos

to upload the file

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_file

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = i_flatfile

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.

where i_flatfile has the starusture comprising of the 3 fields you are talking of.

Then directly assign the fields i_flatfile-field1 , field2 etc...

Former Member
0 Kudos

Is the file on the PC or the app server?

Rob

0 Kudos

Rob,

what would be difference in the code to read the file from the pc against the application server.. ?

Thanks,

BWer

0 Kudos

hi BWer,

if u want to read the file from application server u use <b>open dataset for input</b> else if u want to read it from presentation then you use <b>GUI_DOWNLOAD</b>...

Regards,

Santosh

0 Kudos

Entirely different situation. GUI_UPLOAD won't work from the app server. You would ahve to use open dataset and transfer in that case.

So, is it on the app server?

Rob

Former Member
0 Kudos

Hello,

Just create an internal table with your 3 fields

data: begin of ti_data occurs 0,

fld1 type c,

fld2 type c,

fld3 type c,

end of ti_data.

To read the file just call this FM:

ALL FUNCTION 'TB_LIMIT_WS_UPLOAD'

EXPORTING

filename = Root to your file

filetype = 'ASC'

IMPORTING

filelength = length

TABLES

data_tab = ti_data.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Hope this helps

Gabriel