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: 

Reading a text file with GUI_UPLOAD

Former Member
0 Kudos
2,844

Hello,

I'm trying to read a text file into an internal table of text lines using GUI_UPLOAD. The problem is that I can only read a maximum of 255 characters from each line. So for example, if the first line in the text file contains 260 characters, I lose the last 5 characters of that line.

Any ideas on how to read the ENTIRE contents of a text file into an internal table of text lines? I'd really appreciate any help!

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = 'c:\example.txt'

  • FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = SPACE

  • HEADER_LENGTH = 0

  • DAT_MODE = SPACE

  • CODEPAGE = SPACE

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • READ_BY_LINE = 'X'

  • IMPORTING

  • FILELENGTH =

  • HEADER =

CHANGING

data_tab = int_textline

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.

  • error handling

ENDIF.

thanks,

Ahmad

1 ACCEPTED SOLUTION

athavanraja
Active Contributor
0 Kudos
356

modify your int_textline definition to something like below.

data: begin of int_textline occurs 0,

int_txt(500) type c,

end of int_tab1.

Regards

Raja

7 REPLIES 7

athavanraja
Active Contributor
0 Kudos
357

modify your int_textline definition to something like below.

data: begin of int_textline occurs 0,

int_txt(500) type c,

end of int_tab1.

Regards

Raja

0 Kudos
356

Hi Raja,

As you suggested, I used:

DATA: BEGIN OF fs_textline OCCURS 0,

text(500) TYPE c,

END OF fs_textline.

DATA: int_textline LIKE TABLE OF fs_textline.

But that doesn't solve the problem. If I'm not mistaken, the issue is that you can't store more than 255 char per variable/field.

Best Regards,

Ahmad

0 Kudos
356

No. you can store more than 255 chars.

if you change the internal table as per the declaration i have given , while uploading you wont miss any characters.

<i><b>the issue is that you can't store more than 255 char per variable/field</b></i>.

No you can store. there is a variable type STRING where you can store large value also you can simply declare a variable like data: abc(3000).

What is the exact problem you are facing?

Regards

Raja

0 Kudos
356

Hi Ahmad,

The function module can take more that 255 characters. Just follow the declaration Raja suggested. It is working for me.

DATA: BEGIN OF it_datatab OCCURS 0,

row(500) TYPE c,

END OF it_datatab.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'c:\test.txt'

filetype = 'ASC'

TABLES

data_tab = it_datatab

EXCEPTIONS

file_open_error = 1

OTHERS = 2.

Thanks

Vinod

0 Kudos
356

You shouldn't have any problems about the lenght of file line. You can upload files with longer lines than 255 chars.

Perhaps is your problem how writing (read?) a file in abap list?

In this case you have a limit of 255 chars.

0 Kudos
356

The 255 char output limit was causing my confusion. Thanks to Raja and the rest for helping me out.

Best Regards,

Ahmad

0 Kudos
356

Hi Raja,

I am also faceing the same EXCEL issue while loading data using BODS. It only fetches 255 characters from excel.

I have your solution for this.

Can you please help me out how to use the above script/Code in BODS with detailed explanation for e.g. declaring variables etc, So that I can Implement the same in my JOB.

Thanks for your support in Advance.

Regards,

Sagar