Skip to Content
avatar image
Former Member

Reader/Writer streams in ABAP

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 17, 2017 at 06:38 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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.

      .

  • Dec 17, 2017 at 02:54 PM

    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_lob_handles.htm

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

    Add comment
    10|10000 characters needed characters exceeded