Using SAP ABAP, how can I read content of CSV files in a directory to an internal table?

SAPABAP

There are many functions that can be used to read csv however many are broken and read part of content. You need to go through each file and then process the file content. I would prefer to perform this manually.

You can use the READ DATASET to read data from a file on the application server. Below is the syntax:

READ DATASET <dsn> INTO <f> [LENGTH <len>].

Below is SAP documentation link that you can use to know more about reading data from files:

SAP Documentation

Example

Incase you are using binary mode, you can use LENGTH to find the length of data transferred to <f>. The value of variable length is set by system in <len> as below:

DATA FNAME(60) VALUE 'file'.
DATA: TEXT1(10) VALUE 'helloworld',
      TEXT3(5),
      LENG TYPE I.
OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
TRANSFER TEXT1 TO FNAME.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN BINARY MODE.
DO.
  READ DATASET FNAME INTO TEXT2 LENGTH LENG.
  WRITE: / SY-SUBRC, TEXT2, LENG.
  IF SY-SUBRC <> 0.
    EXIT.
  ENDIF.
ENDDO.
CLOSE DATASET FNAME.
raja
Published on 25-Dec-2017 14:08:41
Advertisements