Skip to content

Commit

Permalink
added code
Browse files Browse the repository at this point in the history
  • Loading branch information
brandoncaulfield committed Sep 12, 2020
1 parent aab6a9f commit c13e082
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions z_reduce_example.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
CLASS lcl|_reduce_test DEFINITION CREATE PRIVATE FINAL.

PUBLIC SECTION.

CLASS-METHODS: create
RETURNING
VALUE(ro_obj) TYPE REF TO lcl|_reduce_test.
METHODS: run.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS lcl|_reduce_test IMPLEMENTATION.

METHOD create.
ro_obj = NEW lcl|_reduce_test( ).
ENDMETHOD.
METHOD run.
DATA lt_test TYPE TABLE OF i WITH EMPTY KEY.
    lt_test = VALUE #( FOR j = 1 WHILE j <= 10 ( j ) ).
    cl_demo_output=>new(
    )->next_section( |Simple Sum| )->write(
      REDUCE i( INIT s = 0
                FOR i = 1 UNTIL i > 10
                NEXT s = s + i )
    )->next_section( |String concatenation| )->write(
      REDUCE string( INIT text = |Count down:|
                     FOR i = 10 THEN i - 1 UNTIL i = 0
                     NEXT text = text && | { i }| )
    )->next_section( |Table Example| )->write(
      lt_test
    )->next_section( |Table Reduction using REDUCE| )->write(
      REDUCE i( INIT x = 0
                FOR ls_test IN lt_test
                NEXT x = x + ls_test )
    )->display( ).
ENDMETHOD.
ENDCLASS.

0 comments on commit c13e082

Please sign in to comment.