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: 

Upload large text file into internal table of 232 characters each

Former Member
0 Kudos
627

Hi Experts,

I have a large txt file with no fix length of indvidual line. I want it in an internal table of 232 characters each. the structure of table is :-

data: begin of itab occurs 0,

row(232) type c,

end of itab.

pl help me. I tried with gui_upload but it takes only first row.

Regards,

Nirmal

21 REPLIES 21

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
176

In the text file, is the data all in one line?

Regards,

Rich Heilman

Former Member
0 Kudos
176

Hi

If you are using GUI_UPLOAD

mark the parameter filetype = 'ASC'.

In the text file also check whether there is a line end indicator. If the text file is one continuous line then you may face this problem of only one record being picked up by the function module.

Former Member
0 Kudos
176

hi

Make read_by_line import parameter of GUI_UPLOAD as ' '. It is marked 'X' by default.

This will solve the problem even if all the data is in one line.

Hope this solves the issue.

Regards,

Richa

0 Kudos
176

hi,

have you checked with <b>making read_by_line import parameter of GUI_UPLOAD as ' '</b>. It is marked 'X' by default. This will solve the problem even if all the data is in one line. this should solve your issue

the following code is working fine...

data :  lv_file         type string.
types : begin of ty_final,
             str(10) type c,         
        end of ty_final.
        
data : t_res_final type standard table of ty_final.       
data : x_res_final type ty_final.

start-of-selection.

lv_file = 'c:abbb.txt'.

      call function 'GUI_UPLOAD'
           exporting
                filename                = lv_file
                filetype                = 'ASC'
                <b>read_by_line = ' '</b> 
          tables
                data_tab                = t_res_final
           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.
       write : 'eee'.
      endif.
      if not t_res_final[] is initial.
      loop at t_res_final into x_res_final.
       write 😕 x_res_final-str.
      endloop.
      endif.

Regards,

Richa

0 Kudos
176

If you file doesn't have a field separator, then don't use that parameter, comment it out and try again.



has_field_separator = 'X'

Regards,

Rich Heilman

Former Member
0 Kudos
176

No the file is not just a single line.

And i used the 'ASC' in FM 'gui_upload'. still there is a problem.

0 Kudos
176

Can you please post your code.

Regards,

Rich Heilman

0 Kudos
176

could you increase the length of your internal table to char3000 or some large value

and see how much of the row is being populated .

If there is more data than a single line in your file , then your file must be a single line.

Former Member
0 Kudos
176

data: begin of it_datatab occurs 0,

row(500) type c,

end of it_datatab.

call function 'GUI_UPLOAD'

exporting

filename = 'c:\file.txt'

filetype = 'ASC'

has_field_separator = 'X'

tables

data_tab = it_datatab

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

.

0 Kudos
176

hi Nirmal,

Comment this statement i.,e <b>*has_field_separator = 'X'</b> and give a try

0 Kudos
176

I stil doubt if your file is indeed multiline?

May be your notepad has a word wrap setting which shows the data in multiline but actually it is a single line.

0 Kudos
176

I was thinking the same.

Regards,

Rich Heilman

0 Kudos
176

Yes Rich,

I think it would be better if we ask him to post the file contents instead of the code..:D..

Former Member
0 Kudos
176

no i have check it. there is no problem with word wrap.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
176

Nirmal, how about you send me the file as well as the code to my email address(on my business card).

Regards,

Rich Heilman

0 Kudos
176

It should really be as easy as this.




report zrich_0001.

data: itab type table of string.
data: xtab type string.

call function 'GUI_UPLOAD'
     exporting
          filename = 'c:text.txt'
     tables
          data_tab = itab.


loop at itab into xtab.
  write:/ xtab.
endloop.


Regards,

Rich Heilman

Former Member
0 Kudos
176

hi Nirmal,

Is making <b>read_by_line = ' '</b> not solving the problem? Please let me know if that is the case.

Regards,

Richa

Former Member
0 Kudos
176

thanks a lot for your help.

Rich i tried your code but still i displays just one line. I can mail the file as it is a bit confidential.but still it is a plain file generated by a transaction of sap. I used to perform this breaking using Unix's 'fold' command previously.

i wont be reply to your ques now as i have to leave. but would surely appreciate the responses.

thanks

Nirmal

0 Kudos
176

Its gotta be the file then.

Regards,

Rich Heilman

Former Member
0 Kudos
176

Yes richa. read_by_line didnt solved the problem. pl try if it is working.

Former Member
0 Kudos
176

hi Nirmal.

if the file is single-line then,

 call function 'GUI_UPLOAD'
           exporting
                filename                = lv_file
                read_by_line = ' '
           tables
                data_tab                = t_res_final.

if the file is multi-line then,

 call function 'GUI_UPLOAD'
           exporting
                filename                = lv_file
           tables
                data_tab                = t_res_final.

These work fine ....

i think if you can provide the file(if not the same file...then some similar file), we will be able to provide some solution.

Regards,

Richa