title: Creating a range for a field from internal table using RTTS
body: <p>I want to create a function/custom class method that takes in 2 parameters:</p>
  
  <p>1) IM_ITAB type ANY TABLE</p>
  
  <p>2) IM_COMPONENT type STRING</p>
  
  <p>and returns 1 parameter:</p>
  
  <p>1) EX_RANGE type PIQ_SELOPT_T</p>
  
  <p>So, algorithm is like this:</p>
  
  <ul>
  <li>First of all, we check if the column with a component name at all exists</li>
  <li>Then, we check that internal table is not empty.</li>
  <li>Then, we loop through internal table assigning component and filling range table. Code is below.</li>
  </ul>
  
  <pre><code>METHODS compose_range_from_itab
      IMPORTING 
        IM_ITAB      type ANY TABLE
        IM_COMPONENT type STRING
      EXPORTING
        EX_RANGE     type PIQ_SELOPT_T.
  ...
  METHOD compose_range_from_itab.
  
    DATA: lo_obj   TYPE REF TO cl_abap_tabledescr,
          wa_range TYPE selopt,
          lt_range TYPE piq_selopt_t.
  
    FIELD-SYMBOLS: &lt;fs_line&gt; TYPE ANY,
                   &lt;fs_component&gt; TYPE ANY.
  
    lo_obj ?= cl_abap_typedescr=&gt;describe_by_data( p_data = im_itab ).
  
    READ TABLE lo_obj-&gt;key TRANSPORTING NO FIELDS WITH KEY name = im_component.
  
    IF sy-subrc IS INITIAL.
  
      IF LINES( im_itab ) GT 0.
  
        LOOP AT im_itab ASSIGNING &lt;fs_line&gt;.
  
          ASSIGN COMPONENT im_component OF STRUCTURE &lt;fs_line&gt; TO &lt;fs_component&gt;.
  
          wa_range-sign = 'I'.
          wa_range-option = 'EQ'.
          wa_range-low = &lt;fs_component&gt;.
  
          APPEND wa_range TO lt_range.
  
        ENDLOOP.
  
        SORT lt_range BY low.
        DELETE ADJACENT DUPLICATES FROM lt_range COMPARING low.
  
        ex_range[] = lt_range[].
  
      ENDIF.
  
    ENDIF.
  
  ENDMETHOD.
  </code></pre>
  
  <p>But I want to improve the method further. If the imported internal table has, let's say, 255 columns, then it will take longer to loop through such table. But I need only one column to compose the range.</p>
  
  <p>So I want to get components of internal table, then choose only one component, create a new line type containing only that component, then create internal table with that line type and copy.</p>
  
  <p>Here is the pseudo code corresponding to what I want to achieve:</p>
  
  <pre><code>append corresponding fields of im_itab into new_line_type_internal_table.
  </code></pre>
  
  <p>How can I "cut out" one component and create a new line type using RTTS?</p>