zoukankan      html  css  js  c++  java
  • SAP 实例 13 Random Grouping with LOOP

    REPORT demo_loop_group_by_random.
    
    CLASS demo DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
          main,
          class_constructor.
      PRIVATE SECTION.
        CLASS-DATA
          numbers TYPE STANDARD TABLE OF i WITH EMPTY KEY.
    ENDCLASS.
    
    CLASS demo IMPLEMENTATION.
      METHOD main.
        DATA(out) = cl_demo_output=>new( ).
    
        DATA(rnd) = cl_abap_random_int=>create(
          seed = CONV i( sy-uzeit ) min = 1 max = 10 ).
    
        DATA members LIKE numbers.
        LOOP AT numbers INTO DATA(line)
             GROUP BY rnd->get_next( )
                      ASCENDING
                      ASSIGNING FIELD-SYMBOL(<group>).
          out->begin_section( |Group Key: { <group> }| ).
          members = VALUE #( FOR <wa> IN GROUP <group> ( <wa> ) ).
          out->write( members
            )->write( |Lines: { lines( members ) }|
            )->end_section( ).
        ENDLOOP.
    
        out->display( ).
      ENDMETHOD.
      METHOD class_constructor.
        numbers = VALUE #( FOR j = 1 UNTIL j > 100 ( j ) ).
      ENDMETHOD.
    ENDCLASS.
    
    START-OF-SELECTION.
      demo=>main( ).

    Description

    Grouping of an internal table numbers with group key binding. The group key of the group loop is constructed as a value of the type i, which is determined as a random number fully independent of the internal table. This casts the table rows into groups of approximately the same size.

    In the group loop, the rows of each group are placed in an internal table members using a table comprehension. This table is the output. 

  • 相关阅读:
    java线程管理
    java进程间通信
    Possible multiple enumeration of IEnumerable
    Adding Search
    Working with SQL Server LocalDB
    ASP.NET Razor
    ASP.NET Razor
    modelstate.isvalid false
    Razor Intro
    open Command window here
  • 原文地址:https://www.cnblogs.com/JackeyLove/p/13490272.html
Copyright © 2011-2022 走看看