Converting a file into a byte array in SAP ABAP


Here is a code snippet to do the same.

data: f_line type xstring.               // to get line by line content
data: f_file type table of xstring.      // to get the final content
data: f_filename type string value 'samplefile.txt'.   // store the filename of file
data: f_len type i.

open dataset f_filename for input in binary mode.   // read the binary
read dataset f_filename into f_line length f_len.  // get the number of lines in the file

while f_len > 0.               // loop through file line by line
   append f_line to f_file.
   read dataset f_filename into f_line length f_len.
endwhile.

close dataset f_filename       // close the dataset

The above code snippet is one of the many possible ways. You can use the same to extend or derive the functionality.

Updated on: 05-Dec-2019

559 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements