<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Creating a range for a field from internal table using RTTS in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-range-for-a-field-from-internal-table-using-rtts/m-p/11885729#M1961039</link>
    <description>&lt;P&gt;Hello, experts.&lt;/P&gt;
  &lt;P&gt;I want to create a function/custom class method that takes in 2 parameters:&lt;/P&gt;
  &lt;P&gt;1) IM_ITAB type ANY TABLE &lt;/P&gt;
  &lt;P&gt;2) IM_COMPONENT type STRING&lt;/P&gt;
  &lt;P&gt;and spits out 1 parameter:&lt;/P&gt;
  &lt;P&gt;1) EX_RANGE type PIQ_SELOPT_T&lt;/P&gt;
  &lt;P&gt;So, algorithm is like this:&lt;/P&gt;
  &lt;P&gt;First of all, we check if the column with a component name at all exists&lt;/P&gt;
  &lt;P&gt;Then, we check that internal table is not empty.&lt;/P&gt;
  &lt;P&gt;Then, we loop through internal table assigning component and filling range table. Code is below.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;METHOD compose_range_from_itab.

  DATA: lo_obj TYPE REF TO cl_abap_tabledescr.

  DATA: wa_range TYPE selopt,

        lt_range TYPE piq_selopt_t.


  FIELD-SYMBOLS: &amp;lt;fs_line&amp;gt; TYPE ANY,

                 &amp;lt;fs_component&amp;gt; TYPE ANY.

  lo_obj ?= cl_abap_typedescr=&amp;gt;describe_by_data( p_data = im_itab ).

  READ TABLE lo_obj-&amp;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 &amp;lt;fs_line&amp;gt;.

        ASSIGN COMPONENT im_component OF STRUCTURE &amp;lt;fs_line&amp;gt; TO &amp;lt;fs_component&amp;gt;.

        wa_range-sign = 'I'.

        wa_range-option = 'EQ'.

        wa_range-low = &amp;lt;fs_component&amp;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.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;But I want to improve the method further. If 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.&lt;/P&gt;
  &lt;P&gt;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:&lt;/P&gt;
  &lt;P&gt;append corresonding fields of im_itab into new_line_type_internal_table.&lt;/P&gt;
  &lt;P&gt;How can I "cut out" one component and create a new line type using RTTS? Please help&lt;/P&gt;</description>
    <pubDate>Fri, 24 May 2019 07:21:55 GMT</pubDate>
    <dc:creator>former_member491157</dc:creator>
    <dc:date>2019-05-24T07:21:55Z</dc:date>
    <item>
      <title>Creating a range for a field from internal table using RTTS</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-range-for-a-field-from-internal-table-using-rtts/m-p/11885729#M1961039</link>
      <description>&lt;P&gt;Hello, experts.&lt;/P&gt;
  &lt;P&gt;I want to create a function/custom class method that takes in 2 parameters:&lt;/P&gt;
  &lt;P&gt;1) IM_ITAB type ANY TABLE &lt;/P&gt;
  &lt;P&gt;2) IM_COMPONENT type STRING&lt;/P&gt;
  &lt;P&gt;and spits out 1 parameter:&lt;/P&gt;
  &lt;P&gt;1) EX_RANGE type PIQ_SELOPT_T&lt;/P&gt;
  &lt;P&gt;So, algorithm is like this:&lt;/P&gt;
  &lt;P&gt;First of all, we check if the column with a component name at all exists&lt;/P&gt;
  &lt;P&gt;Then, we check that internal table is not empty.&lt;/P&gt;
  &lt;P&gt;Then, we loop through internal table assigning component and filling range table. Code is below.&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;METHOD compose_range_from_itab.

  DATA: lo_obj TYPE REF TO cl_abap_tabledescr.

  DATA: wa_range TYPE selopt,

        lt_range TYPE piq_selopt_t.


  FIELD-SYMBOLS: &amp;lt;fs_line&amp;gt; TYPE ANY,

                 &amp;lt;fs_component&amp;gt; TYPE ANY.

  lo_obj ?= cl_abap_typedescr=&amp;gt;describe_by_data( p_data = im_itab ).

  READ TABLE lo_obj-&amp;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 &amp;lt;fs_line&amp;gt;.

        ASSIGN COMPONENT im_component OF STRUCTURE &amp;lt;fs_line&amp;gt; TO &amp;lt;fs_component&amp;gt;.

        wa_range-sign = 'I'.

        wa_range-option = 'EQ'.

        wa_range-low = &amp;lt;fs_component&amp;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.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;But I want to improve the method further. If 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.&lt;/P&gt;
  &lt;P&gt;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:&lt;/P&gt;
  &lt;P&gt;append corresonding fields of im_itab into new_line_type_internal_table.&lt;/P&gt;
  &lt;P&gt;How can I "cut out" one component and create a new line type using RTTS? Please help&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 07:21:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-a-range-for-a-field-from-internal-table-using-rtts/m-p/11885729#M1961039</guid>
      <dc:creator>former_member491157</dc:creator>
      <dc:date>2019-05-24T07:21:55Z</dc:date>
    </item>
  </channel>
</rss>

