<?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 Re: Delete internal table with condition and same ID in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687611#M30855</link>
    <description>&lt;P&gt;Dear Zeynep,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need entries specific to one parameter. You can do it without using loop and simply with one statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE itab WHERE date NE p_date.&lt;/P&gt;&lt;P&gt;I hope this will resolve your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Arpan Shukla &lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Oct 2018 11:00:18 GMT</pubDate>
    <dc:creator>arpan_shukla</dc:creator>
    <dc:date>2018-10-02T11:00:18Z</dc:date>
    <item>
      <title>Delete internal table with condition and same ID</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687610#M30854</link>
      <description>&lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Hello experts,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I have a problem I can not solve, and hope you can help me.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; Here is an internal table: &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;ID name Datefrom &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;1 Test 02.10.2018&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;1 Test1 01.10.2018&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;2 Test3 29.09.2018&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;The rows with the same ID belong together. I have a report where you can select the dates. If you choose for example the date „02.10.2018“. The result should show up both rows with the same id . This is because at least one of the rows with the same id meets the condition.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;For example if I put „02.10.2018“ in the parameter field, I want the result to show to this example below: &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;ID name Datefrom &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;1 Test 02.10.2018&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;1 Test1 01.10.2018&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Here is what I tried so far and I don't get any results.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;FIELD-SYMBOLS &amp;lt;wa_itab&amp;gt; LIKE LINE OF itab. LOOP AT itab ASSIGNING &amp;lt;wa_itab&amp;gt;.&lt;BR /&gt; IF &amp;lt;wa_itab&amp;gt;date &amp;lt; p_date.&lt;BR /&gt; DELETE TABLE itab FROM &amp;lt;wa_itab&amp;gt;ENDIF.&lt;BR /&gt; ENDLOOP.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;I am very thankful for any help.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 09:48:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687610#M30854</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-02T09:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Delete internal table with condition and same ID</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687611#M30855</link>
      <description>&lt;P&gt;Dear Zeynep,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need entries specific to one parameter. You can do it without using loop and simply with one statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE itab WHERE date NE p_date.&lt;/P&gt;&lt;P&gt;I hope this will resolve your issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Arpan Shukla &lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 11:00:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687611#M30855</guid>
      <dc:creator>arpan_shukla</dc:creator>
      <dc:date>2018-10-02T11:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Delete internal table with condition and same ID</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687612#M30856</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report ZWELT
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*

REPORT zwelt.


 PARAMETERS: p_date TYPE sy-datum DEFAULT '20181002'.

 TYPES BEGIN OF it_tabline.
   TYPES: id TYPE i,
          name(10) TYPE c,
          date TYPE sy-datum.
   TYPES END OF it_tabline.
 DATA: it_tab TYPE TABLE OF it_tabline.
 DATA: lr_tab TYPE it_tabline.

 FIELD-SYMBOLS &amp;lt;wa_itab&amp;gt; LIKE LINE OF it_tab.

 lr_tab-id = 1.
 lr_tab-name = 'Test'.
 lr_tab-date = '20181002'.
 APPEND lr_tab TO it_tab.

 lr_tab-id = 1.
 lr_tab-name = 'Test1'.
 lr_tab-date = '20181001'.
 APPEND lr_tab TO it_tab.

 lr_tab-id = 2.
 lr_tab-name = 'Test3'.
 lr_tab-date = '20180929'.
 APPEND lr_tab TO it_tab.

 READ TABLE it_tab INTO lr_tab WITH KEY date = p_date.

 CHECK sy-subrc EQ 0.

 LOOP AT it_tab ASSIGNING &amp;lt;wa_itab&amp;gt; WHERE id EQ lr_tab-id.
   WRITE: / &amp;lt;wa_itab&amp;gt;-id,
            &amp;lt;wa_itab&amp;gt;-name,
            &amp;lt;wa_itab&amp;gt;-date.
 ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or if you want to delete the lines with the same id: put instead of the loop. endloop.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; DELETE it_tab WHERE id EQ lr_tab-id.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 11:49:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687612#M30856</guid>
      <dc:creator>MichaelTe</dc:creator>
      <dc:date>2018-10-02T11:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delete internal table with condition and same ID</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687613#M30857</link>
      <description>&lt;P&gt;Dear Zeynep,&lt;/P&gt;&lt;P&gt;even if your request is already old, maybe my solution (works only with NW7.40PL08 and higher) helps you in future.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT zstkoes_internal_table_new.


TYPES:
  BEGIN OF gtys_data,
    id   TYPE i,
    name TYPE name1,
    date TYPE d,
  END OF gtys_data,
  gtyt_data TYPE TABLE OF gtys_data WITH DEFAULT KEY.


PARAMETERS: pa_date TYPE d DEFAULT '20181002'.


DATA(gt_data) = VALUE gtyt_data(
                  ( id = 1 name = 'Test'  date = '20181002' )
                  ( id = 1 name = 'Test1' date = '20181002' )
                  ( id = 1 name = 'Test2' date = '20181001' )
                  ( id = 2 name = 'Test3' date = '20180929' ) ).


cl_demo_output=&amp;gt;begin_section( |Original Data| ).
cl_demo_output=&amp;gt;write_data( gt_data  ).


DATA(gt_data_nested_loop) = VALUE gtyt_data(  FOR ls_data IN gt_data
                                                WHERE ( date EQ pa_date )   " First loop with valid parameter-date
                                              FOR ls_data_filtered IN gt_data
                                                WHERE ( id EQ ls_data-id )  " Second loop for all ids
                                                  ( ls_data_filtered ) ).   " Entries which fits both condition


cl_demo_output=&amp;gt;begin_section( |Nested Loop| ).
cl_demo_output=&amp;gt;write( |Be careful with this logic.{
                        cl_abap_char_utilities=&amp;gt;newline }It can cause multiple entries, if date condition one id fits multiple times.{
                        cl_abap_char_utilities=&amp;gt;newline }If date is unique then logic is working fine.| ).
cl_demo_output=&amp;gt;write_data( gt_data_nested_loop ).


DATA(gt_data_grouped_loop) = VALUE gtyt_data( FOR GROUPS ids OF ls_data IN gt_data
                                                WHERE ( date EQ pa_date )   " First loop to get ids of valid parameter-date
                                                GROUP BY ls_data-id
                                              FOR ls_data_filtered IN gt_data
                                                WHERE ( id EQ ids )         " Second loop for all ids
                                                  ( ls_data_filtered ) ).   " Entries which fits both condition
cl_demo_output=&amp;gt;begin_section( |Loop Grouped by| ).
cl_demo_output=&amp;gt;write( |This logic is working perfect.| ).
cl_demo_output=&amp;gt;write_data( gt_data_grouped_loop ).




cl_demo_output=&amp;gt;display( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here is the output of the report:&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1711520-grouped-by.png" /&gt;&lt;/P&gt;&lt;P&gt;Greetings&lt;BR /&gt;Stephan&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 10:46:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/delete-internal-table-with-condition-and-same-id/m-p/687613#M30857</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-07-23T10:46:21Z</dc:date>
    </item>
  </channel>
</rss>

