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 on my website:

Scroll to Top