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: 

OPEN DATASET for CSV files

Former Member
0 Kudos

Hi all!

I'm using OPEN DATASET to read CSV files (created using Excel 2007), that contain multiple lines, the problem is when I use READ DATASET it transfers the hole content of the CSV file into the variable instead of transfering line by line.

The source code is the following:


data: lv_lines type string.

open dataset x_file for input
  in text mode
  encoding default.
if sy-subrc eq 0.
  do.
    clear lv_lines.
    read dataset x_file into lv_lines.
    if sy-subrc eq 0.
      append lv_lines to y_outtab.
    else.
      exit.
    endif.
  enddo.
else.
  message e001(ztim_fi)
    with x_file
    raising general_fault.
endif.

close dataset x_file.

Can anyone help me with this?

Kind regards,

Mário Espinheira

9 REPLIES 9

Former Member
0 Kudos

Hello,

I hope y outtab is the internal table you are using.

If not append to an internal table.

Try this

data: lv_lines type string.

open dataset x_file for input

in text mode

encoding default.

if sy-subrc eq 0.

do.

clear lv_lines.

read dataset x_file into lv_lines.

if sy-subrc eq 0.

append lv_lines to t_outtab. // t_outtab is internal table

else.

exit.

endif.

enddo.

else.

message e001(ztim_fi)

with x_file

raising general_fault.

endif.

close dataset x_file.

Hope this helps.

Regards,

pallavi

Former Member
0 Kudos

Hi

It depends on how that file was created, u make sure the sign of end of record is set at the end of every line

Max

0 Kudos

That's what I think, because if I create the file using Notepad it works fine. When I use the Excel generated files it doesn't work.

By the way, Y_OUTTAB is an Internal Table of type String.

Regards,

Mário Espinheira

0 Kudos

Determine what is the end of line character, and you may indicate it in the OPEN DATASET statement (check [abap doc for open dataset end of line character|http://help.sap.com/abapdocu_70/en/ABAPOPEN_DATASET_LINEFEED.htm])

0 Kudos

Hello!

I've already tried all four possibilities and none of them worked.

Regards,

Mário Espinheira

0 Kudos

Hi Mario,

use this link

Hope this will help you to solve your problem.

Regards,

Vijay

0 Kudos

could you tell us what end of line character it is? did you determine it?

0 Kudos

Hi!

In debug, when I see the content of LV_LINES (that has all the data in the file) the Linefeed is #.

Regards,

Mário Espinheira

0 Kudos
  1. is usually the replacement character when the character cannot be displayed. Could you switch to hexadecimal view and tell us the code?