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 Dataset into string stopping at end of the first line (#)

former_member949653
Discoverer
0 Kudos

Hello,

I'm trying to read the data of a .csv file located in the Application Server (AL11) into an internal table. I have done so as it follows:

OPEN DATASET lv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.
READ DATASET lv_filename INTO lv_data.
CLOSE DATASET lv_filename.

The .csv I'm using is the following:

Objetos;Error;Adv.;Infos;objeto

;1865;1812;760;C31

;;;;C30

..Grupo de funciones ZACT_VERFAB;1315;1006;498;C61

....Verif.sintaxis/Generación;1303;52;72;C60

......Verif.programas ampliada;1303;52;72;C71

........Error;1303;;;C70

..........Cód.mensaje 2500;1303;;;C50

However, whenever I execute my program, lv_data stores only the first line of the .csv, like this:

Objetos;Error;Adv.;Infos;objeto#

I have to add that lv_data has been defined as TYPE string, so its size has to be dynamical, so the problem is not there.

Thank you in advance,

Álvaro

1 ACCEPTED SOLUTION

ArthurParisius
Contributor

That's because if you want to read multiple lines of e text file, which csv basically is, you need to do the read dataset in a loop until sy-subrc gives a value other than 0.

3 REPLIES 3

moshenaveh
Community Manager
Community Manager
0 Kudos
Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members. For example, you can outline what steps you took to find answers (and why they weren't helpful) and share screenshots of what you've seen/done. The more details you provide, the more likely it is that members will be able to assist you. You should also make sure you're using all the appropriate tags, so the right experts can find your question.
Should you wish, you can revise your question by selecting Actions, then Edit.
Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

ArthurParisius
Contributor

That's because if you want to read multiple lines of e text file, which csv basically is, you need to do the read dataset in a loop until sy-subrc gives a value other than 0.

Sandra_Rossi
Active Contributor

Is there something you don't understand in the ABAP documentation?

  • If the file was opened as a text file or as a legacy text file, the data is normally read from the current position of the file pointer to the next end-of-line marker,

NB: please do NOT declare internal tables with header lines, it's been obsolete for 20 years because it's error prone and it brings confusion.