title: Grouping + aggregation of itab with table comprehensions
body: <p>Rather typical task but I'm stuck on doing it in a beautiful way.</p>
  
  <p>For example, I need to find the last shipment for each vendor, i.e. to find delivery with the max date for the each vendor</p>
  
  <pre><code>VENDOR     DELIVERY   DATE
  10          00055    01/01/2019
  20          00070    01/19/2019
  20          00088    01/20/2019
  20          00120    11/22/2019
  40          00150    04/01/2019
  40          00200    04/10/2019
  </code></pre>
  
  <p>The result table to be populated</p>
  
  <pre><code>VENDOR     DELIVERY   DATE
  10          00055    01/01/2019
  20          00120    11/22/2019
  40          00200    04/10/2019
  </code></pre>
  
  <p>I implemented this in a following way, via DESCENDING, which I find very ugly</p>
  
  <pre><code>LOOP AT itab ASSIGNING &lt;wa&gt; GROUP BY ( ven_no = &lt;wa&gt;-ven_no ) REFERENCE INTO DATA(vendor).
    LOOP AT GROUP vendor ASSIGNING &lt;ven&gt; GROUP BY ( date = &lt;vendor&gt;-date ) DESCENDING.
      CHECK NOT line_exists( it_vend_max[ ven_no = &lt;ven&gt;-ven_no ] ).
      it_vend_max = VALUE #( BASE it_vend_max ( &lt;ven&gt; ) ).
    ENDLOOP.
  ENDLOOP.
  </code></pre>
  
  <p>Is there more elegant way to do this? </p>
  
  <p>I also tried <code>REDUCE</code></p>
  
  <pre><code>result = REDUCE #( vend_line = value ty_s_vend()
                     MEMBERS = VALUE ty_t_vend( )
                     FOR GROUPS &lt;group_key&gt; OF &lt;wa&gt; IN itab
                     GROUP BY ( key = &lt;wa&gt;-ven_no count = GROUP SIZE
                     ASCENDING
           NEXT vend_line = VALUE #(
                ven_no = &lt;wa&gt;-ven_no
  
                date  = REDUCE i( INIT max = 0
                                  FOR m IN GROUP &lt;group_key&gt;
                                  NEXT max = nmax( val1 = m-date
                                                   val2 = &lt;wa&gt;-date ) )
                deliv_no  = &lt;wa&gt;-deliv_no
           MEMBERS = VALUE ty_s_vend( FOR m IN GROUP &lt;group_key&gt; ( m ) ) ).
  </code></pre>
  
  <p>but <code>REDUCE</code> selects max date from the whole table and it selects only <strong>flat structure</strong>, which is not what I want. However, in ABAP examples I saw samples where table-to-table reductions are also possible. Am I wrong?</p>
  
  <p>Another thing I tried is finding uniques with <code>WITHOUT MEMBERS</code> but this syntax doesn't work:</p>
  
  <pre><code>it_vend_max = VALUE ty_t_vend( FOR GROUPS value OF &lt;line&gt; IN itab 
                                 GROUP BY ( &lt;line&gt;-ven_no &lt;line&gt;-ship_no ) 
                                 WITHOUT MEMBERS ( lifnr = value 
                                                   date = nmax( val1 = &lt;line&gt;-date 
                                                                val2 = value-date ) ) ).
  </code></pre>
  
  <p>Any suggestion of what is wrong here or own elegant solution is appreciated.</p>