Skip to Content

Reader/Writer streams in ABAP

Dec 16, 2017 at 11:02 PM


avatar image

I was recently looking at the ABAP documentation and came across something called as reader/writer streams. The documentation explains the classes and interfaces that are used to for this purpose but can someone help me understand when STREAMING is used? Better yet, can someone provide an example of a practical situation where they have used streams?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Iftah Peretz
Dec 17, 2017 at 06:38 AM


In the documentation that you mentioned there are several examples (with code). As for the practicality, you can think of a few, for example if you want to do a string based analysis of a big body of text (e.g. Word segmentation or any of the NLP tasks) this is one of the methods you can use.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

In object-oriented programming (java, ABAP, etc.), streaming is useful for loose coupling, especially with test-driven development for providing a fake object. More information in Wikipedia: Stream (computing)

For instance, in ABAP, that could be :

  • Let's say you have a code which reads a text file from HTTP, processes it, and returns data
  • Instead of reading the file directly (GUI_UPLOAD), pass a C stream reader instance to your code, and read it (prerequisite: instantiate it using ZCL_ABAP_FRONTEND_C_READER; PS: unfortunately, this Z class should be developped because CL_ABAP_FRONTEND_C_READER was never provided by SAP).
  • With ABAP Unit, do your fake object by instantiating the C reader from dummy files to be tested, like CL_ABAP_STRING_C_READER for instance.

Unfortunately, ABAP streams were never developed further after their release in 7.0 : data sources/sinks frontend, backend, http, etc. are still missing, and I don't know why SAP stopped the development, as it could be very useful.


Sandra, could you share more details on the ZCL_ABAP_FRONTEND_C_READER. What is this intended to do and how should it be any different from GUI_UPLOAD, pros/cons etc?



You can find all the pros/cons you want by reading the Wikipedia or any other web site about Stream concept. The forum is not intended to explain the language programming concepts. Please revert back with precise questions.

Here is some code to help you understand how it could look like in ABAP if you create the class ZCL_ABAP_FRONTEND_C_READER. It should wrap the call to GUI_UPLOAD (which is hidden to the "users" i.e. developers who use the class). The class could be used this way for instance:

data(C_Stream) = new zcl_abap_frontend_c_reader( 'C:\My documents\myfile.txt' ).
main_processing( C_Stream ).

METHOD main_processing.
  IF C_Stream IS NOT BOUND OR C_Stream->is_closed( ) = abap_true.
    result = 0.
  WHILE abap_true = C_Stream->data_available( ).
    data(line) = C_Stream->read_line( ).
    " process the line and calculate the result of the method
  C_Stream->close( ). 
  result = 1.

PS: note that the read_line method is not part of the official ABAP streaming Character interface (but would be useful to develop).

Then the ABAP Unit could test the method easily (it's just one dumb test, among many possible others):

METHOD test_one_empty_line.
  data(C_Stream) = new cl_abap_c_reader( |\n| ). " file with one empty line
  cl_abap_unit=>assert_equals( act = main_processing( C_Stream ) exp = 1 ).


Horst Keller
Dec 17, 2017 at 02:54 PM

The main use case were LOB handles in Open SQL.

There were also plans for a more general concept with much more functionality, but then there was no demand any more.

10 |10000 characters needed characters left characters exceeded