Loop at Group by with reference field symbol challenge | SAP Community

PHOTO EMBED

Mon May 10 2021 11:00:39 GMT+0000 (UTC)

Saved by @uxkjaer #abap

TYPES:
  BEGIN OF ty_sflight,
    carrid TYPE sflight-carrid,
    connid TYPE sflight-connid,
  END OF ty_sflight.
DATA:
  lt_sflight   TYPE STANDARD TABLE OF ty_sflight,
  r_type_table TYPE REF TO cl_abap_tabledescr,
  r_data_tab   TYPE REF TO data.
FIELD-SYMBOLS:
  <lt_table>   TYPE ANY TABLE.

START-OF-SELECTION.
  lt_sflight = VALUE #(
               ( carrid = 'AA' connid = 1 )
               ( carrid = 'LH' connid = 1 )
               ( carrid = 'AA' connid = 2 )
               ( carrid = 'LH' connid = 3 ) ).
  r_type_table = cl_abap_tabledescr=>create(
      p_line_type = cl_abap_structdescr=>create(
        p_components = VALUE #(
          ( name = 'CARRID' type = CAST #( cl_abap_datadescr=>describe_by_name( 'SFLIGHT-CARRID' ) ) )
          ( name = 'CONNID' type = CAST #( cl_abap_datadescr=>describe_by_name( 'SFLIGHT-CONNID' ) ) ) ) ) ).
  CREATE DATA r_data_tab TYPE HANDLE r_type_table.
  ASSIGN r_data_tab->* TO <lt_table>.

  <lt_table> = lt_sflight.

  FIELD-SYMBOLS <lt_temp> TYPE HASHED TABLE.
  r_type_table = cl_abap_tabledescr=>create(
      p_line_type = cl_abap_structdescr=>create(
        p_components = VALUE #(
          ( name = 'CARRID' type = CAST #( cl_abap_datadescr=>describe_by_name( 'SFLIGHT-CARRID' ) ) ) ) )
      p_table_kind = cl_abap_tabledescr=>tablekind_hashed
      p_unique = abap_true
      p_key_kind = cl_abap_tabledescr=>keydefkind_tableline ).
  CREATE DATA r_data_tab TYPE HANDLE r_type_table.
  ASSIGN r_data_tab->* TO <lt_temp>.

  <lt_temp> = CORRESPONDING #( <lt_table> DISCARDING DUPLICATES ).

  LOOP AT <lt_temp> ASSIGNING FIELD-SYMBOL(<ls_temp>).
    ASSIGN COMPONENT 1 OF STRUCTURE <ls_temp> TO FIELD-SYMBOL(<field>).
    cl_demo_output=>write( |Group - { <field> }| ).
  ENDLOOP.

  cl_demo_output=>display( ).
content_copyCOPY

https://answers.sap.com/questions/12884088/loop-at-group-by-with-reference-field-symbol-chall.html