Read binary file from application server

Simple ABAP snippet how to read a binary file from an application server.
DATA:
  filename     TYPE string,
  buffer       TYPE xstring,
  content      TYPE xstring,
  mlen         TYPE i,
  alen         TYPE i.

filename = '/tmp/file.bin'.
OPEN DATASET filename FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
  mlen = 1024.
  alen = 9999.
  WHILE alen <> 0.
    READ DATASET filename INTO buffer MAXIMUM LENGTH mlen ACTUAL LENGTH alen.
    IF sy-subrc = 0.
      CONCATENATE content buffer INTO content IN BYTE MODE.
    ENDIF.
  ENDWHILE.
  CLOSE DATASET filename.
ENDIF.
See other related notes in my infodepot:
Upload Excel file to internal table Save internal table as CSV file delimited by Tab
Full list of examples in my infodepot

If you have a question, have found an error or just want to contact me, please use this form.

Copyright (C) 2018 http://www.kerum.pl/infodepot/

Disclaimer: I am not affiliated or related to any division or subsidiary of SAP AG.
Trademarks or registered trademarks of any products or companies referred to on this site belong to those companies.
Anyone using the given solutions, is doing it under his/her own responsibility and at own risk.