Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Reader/Writer streams in ABAP

Former Member
0 Kudos

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?

5 REPLIES 5

iftah_peretz
Active Contributor

Hi,

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.

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.

0 Kudos

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?

Vikram.M

0 Kudos

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.
    RETURN.
  ENDIF.
  WHILE abap_true = C_Stream->data_available( ).
    data(line) = C_Stream->read_line( ).
    " process the line and calculate the result of the method
  ENDWHILE.
  C_Stream->close( ). 
  result = 1.
ENDMETHOD.

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 ).
ENDMETHOD.

.

horst_keller
Product and Topic Expert
Product and Topic Expert

The main use case were LOB handles in Open SQL.

https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenselect_into_lo...

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