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: 

How to Upload Text file

Former Member
0 Kudos
619

Hi Group,

Any body can please suggest me how to upload text file.

In my text file I am having the header text on the first row,in my case I need the data to upload excluding the Header.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
233

hi pra,

if u use the process of lsmw to upload the data then there is once option in the step ''specify file'' in that option if u add the file then there is one option in the popup ask weather do u have filed names at the start of file then by not checking that option u can eliminate those filed name i think

and one more way u can try also try to convet that file into excel file then copy ur required records then paste thos records in new excel file and save again it as a txt file

i thinks this info is helpful for u

Thanks in advanse

naveen

9 REPLIES 9

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
233

From PC? If so, use function module GUI_UPLOAD. This will upload into internal table, then all you need to do is skip the first row in your loop.


report zrich_0001.


data: begin of itab occurs 0,
      rec(1000) type c,
      end of itab.

start-of-selection.


  call function 'GUI_UPLOAD'
    exporting
      filename = 'C:test.txt'
    tables
      data_tab = itab.


  loop at itab.

    check sy-tabix > 1.      " Skip first record


  endloop.

Regards,

RIch Heilman

0 Kudos
233

Yah, from PC I am uploading the tab delimeted text file.

Earlier I used the FM KCD_EXCEL_OLE_TO_INT_CONVERT ro Upload the Excel file from row 2(because first row is my header),If I use GUI_UPLOAD FM how to skip the first row,can you please suggest

naimesh_patel
Active Contributor
0 Kudos
233

Hello,

Use FM WS_upload, and file type as <b>ASC</b>

After FM,

delete itab index 1. " to delte header line.

regards,

Naimesh.

LucianoBentiveg
Active Contributor
0 Kudos
233

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = filename

filetype = 'ASC'

  • has_field_separator = 'X'

TABLES

data_tab = auxitab

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.

Then

DELETE auxitab index 1.

Former Member
0 Kudos
234

hi pra,

if u use the process of lsmw to upload the data then there is once option in the step ''specify file'' in that option if u add the file then there is one option in the popup ask weather do u have filed names at the start of file then by not checking that option u can eliminate those filed name i think

and one more way u can try also try to convet that file into excel file then copy ur required records then paste thos records in new excel file and save again it as a txt file

i thinks this info is helpful for u

Thanks in advanse

naveen

0 Kudos
233

You can just delete the first row, or skip over it when processing.

delete itab index 1.

or

  loop at itab. 
   check sy-tabix > 1.      " Skip first record  
  endloop.

Regards,

Rich Heilman

0 Kudos
233

Hi Rich,

In my case I am giving the tab delimeted file (with space),when I am using GUI_UPLOAD its not reading rows

correctly can you please suggest

0 Kudos
233

Hi,

Try changing the file type to DAT. Also make sure HAS_FIELD_SEPARATOR parameter is checked.

Regards,

Ravi

Former Member
0 Kudos
233

Hi,

Use the function module gui_upload.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = P_FILE

FILETYPE = 'ASC'

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = RECORD

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

OTHERS = 6.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

After getting the uploaded text into the internal table.You can make a new internal table appending the rows of first table to second internal table excluding the first row.

Loop at RECORD.

if sy-tabix > 1.

MOve RECORD to RECORD1.

Append record1.

endif.

endloop.

Record1 will not have the data of header which you can use for further processing.

Thanks

Mayank

PS:If you find it useful.Please reward points.