Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- report zz_extract_subtable.
- types: ernam_tab type standard table of ernam with non-unique default key,
- vbak_tab type standard table of vbak with non-unique key vbeln.
- * Extract a standard table of elementary line type ERNAM
- * from a table of some 100 VBAK rows
- * containing the distinct values that appear in column VBAK-ERNAM
- * Different ways to do it, with old and with new syntax.
- start-of-selection.
- perform start.
- * ---
- form start.
- data: lt_vbak type vbak_tab,
- lt_ernam type ernam_tab.
- select * up to 100 rows from vbak into table lt_vbak.
- perform with_collect using lt_vbak changing lt_ernam.
- perform add_result using `with collect` lt_ernam.
- perform with_explicit_aux_hash using lt_vbak changing lt_ernam.
- perform add_result using `with auxiliary hash` lt_ernam.
- perform with_value_for using lt_vbak changing lt_ernam.
- perform add_result using `with value for` lt_ernam.
- perform with_reduce_for using lt_vbak changing lt_ernam.
- perform add_result using `with reduce for` lt_ernam.
- perform with_grouping using lt_vbak changing lt_ernam.
- perform add_result using `with grouping` lt_ernam.
- cl_demo_output=>display( ).
- endform.
- form with_collect using it_vbak type vbak_tab
- changing ct_ernam type ernam_tab.
- clear ct_ernam.
- loop at it_vbak assigning field-symbol(<ls_vbak>).
- collect <ls_vbak>-ernam into ct_ernam.
- endloop.
- endform.
- form with_explicit_aux_hash using it_vbak type vbak_tab
- changing ct_ernam type ernam_tab.
- data: lt_ernam type hashed table of ernam with unique key table_line.
- loop at it_vbak assigning field-symbol(<ls_vbak>).
- insert <ls_vbak>-ernam into table lt_ernam.
- endloop.
- ct_ernam = lt_ernam.
- endform.
- form with_value_for using it_vbak type vbak_tab
- changing ct_ernam type ernam_tab.
- ct_ernam = value #( for <ls_vbak> in it_vbak
- ( <ls_vbak>-ernam ) " Inserting into a hash table will dump on multiple values.
- " No way to avoid this
- ).
- sort ct_ernam.
- delete adjacent duplicates from ct_ernam.
- endform.
- form with_reduce_for using it_vbak type vbak_tab
- changing ct_ernam type ernam_tab.
- ct_ernam = reduce #( init names type ernam_tab
- for <ls_vbak> in it_vbak
- next names =
- cond #(
- when line_exists( names[ table_line = <ls_vbak>-ernam ] ) then names
- else value #( base names ( <ls_vbak>-ernam ) )
- )
- ).
- endform.
- form with_grouping using it_vbak type vbak_tab
- changing ct_ernam type ernam_tab.
- clear ct_ernam.
- loop at it_vbak assigning field-symbol(<ls_vbak>)
- group by <ls_vbak>-ernam
- ascending
- assigning field-symbol(<lv_group>).
- append <lv_group> to ct_ernam.
- endloop.
- endform.
- form add_result using iv_name type string
- it_ernam type ernam_tab.
- cl_demo_output=>write_data( name = iv_name value = concat_lines_of( table = it_ernam sep = ',' ) ).
- endform.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement