<?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: Comparing two tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468936#M2000819</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;SELECT list_of_columns_you_want  
       INTO TABLE DATA(my_beautiful_table_CATSDB)
       FROM CATSDB 
       WHERE my_date in S_my_select_option_on_date.

LOOP AT my_beautiful_table_CATSDB
     refence into data(o_ligne_catsdb).
  READ TABLE my_custom_table
       TRANSPORTING NO FIELDS
       WITH KEY pernr = o_ligne_catsdb-&amp;gt;pernr.
  IF sy-subrc EQ 0.
    " do something
  ELSE.
    " do something else
  ENDIF.
ENDLOOP.
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Jun 2021 09:23:08 GMT</pubDate>
    <dc:creator>FredericGirod</dc:creator>
    <dc:date>2021-06-29T09:23:08Z</dc:date>
    <item>
      <title>Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468935#M2000818</link>
      <description>&lt;P&gt;I want to take date and pernr from CATSDB table based on date from my selection screen and check if this pernr is available in a custom table's pernr. How do I do this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 09:17:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468935#M2000818</guid>
      <dc:creator>simantini_sh</dc:creator>
      <dc:date>2021-06-29T09:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468936#M2000819</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;SELECT list_of_columns_you_want  
       INTO TABLE DATA(my_beautiful_table_CATSDB)
       FROM CATSDB 
       WHERE my_date in S_my_select_option_on_date.

LOOP AT my_beautiful_table_CATSDB
     refence into data(o_ligne_catsdb).
  READ TABLE my_custom_table
       TRANSPORTING NO FIELDS
       WITH KEY pernr = o_ligne_catsdb-&amp;gt;pernr.
  IF sy-subrc EQ 0.
    " do something
  ELSE.
    " do something else
  ENDIF.
ENDLOOP.
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jun 2021 09:23:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468936#M2000819</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2021-06-29T09:23:08Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468937#M2000820</link>
      <description>&lt;P&gt;Hi Fredric, thanks for the help, just wanted to know what is (o_ligne_catsdb)?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 09:27:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468937#M2000820</guid>
      <dc:creator>simantini_sh</dc:creator>
      <dc:date>2021-06-29T09:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468938#M2000821</link>
      <description>&lt;P&gt;You could also use an outer join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;   SELECT CATSDB~PERNR as pernr1,&lt;BR /&gt;          ZTABLE~PERNR as pernr2
          FROM CATSDB LEFT OUTER JOIN ZTABLE
          ON CATSDB~PERNR EQ ZTABLE~PERNR
          into TABLE @data(RESULT).
  
                         &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;   The table "RESULT" should cointain all PERNRs in the first column PERNR1 and should be empty in column PERNR2 if the pernr is missing in your custom Z table &lt;/P&gt;&lt;P&gt;PERN1 | PERNR2&lt;/P&gt;&lt;P&gt;000001 | 000001&lt;/P&gt;&lt;P&gt;000002 | 000000         -&amp;gt; PERNR2 would is missing in your Z Table&lt;/P&gt;&lt;P&gt;000003 | 000003&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 09:34:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468938#M2000821</guid>
      <dc:creator>BenjaminWeishei</dc:creator>
      <dc:date>2021-06-29T09:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468939#M2000822</link>
      <description>&lt;P&gt; LOOP AT it_catsdb&lt;BR /&gt; REFERENCE INTO DATA(o_ligne_catsdb).&lt;BR /&gt; READ TABLE zps_resource_asn&lt;BR /&gt;WITH KEY pernr = o_ligne_catsdb-&amp;gt;pernr&lt;BR /&gt; TRANSPORTING NO FIELDS.&lt;BR /&gt; IF sy-subrc = 0.&lt;BR /&gt; &amp;lt;fs_it_catsdb&amp;gt;-rproj = &amp;lt;fs_ld_prps&amp;gt;-posid.&lt;BR /&gt; ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;here, I am getting an error saying "Field "PERNR" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. "DATA" statement." But I have declared it before.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 10:29:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468939#M2000822</guid>
      <dc:creator>simantini_sh</dc:creator>
      <dc:date>2021-06-29T10:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468940#M2000823</link>
      <description>&lt;P&gt;You can pass the loop to a variable and not to a ref data if you want... it's not as cool, but it's effective and easier to understand (I'm strill trying to understand it).&lt;BR /&gt;But in the line of Frederic's code&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at cats into data(cat).&lt;BR /&gt;  if line_exists( zres[ pernr = cat-pernr ] ).&lt;BR /&gt;    "do something.&lt;BR /&gt;  endif.&lt;BR /&gt;endloop.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Jun 2021 10:39:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468940#M2000823</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2021-06-29T10:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468941#M2000824</link>
      <description>&lt;P&gt;Hi Simantini,&lt;/P&gt;&lt;P&gt;In order to check this, you can use FOR ALL ENTRIES to be the most accurate option.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Select  pernr
       workdate
FROM CATSDB
INTO TABLE GT_CATSDB
WHERE WORKDATE EQ P_DATE.
IF sy-subrc IS INITIAL.
SORT gt_catsdb BY pernr.
ENDIF.

Data(lt_catsdb) = gt_catsdb.
DELETE lt_catsdb WHERE PERNR IS INITIAL.
DELETE ADJACENT DUPLICATES FROM lt_catsdb COMPARING lt_catsdb.

IF lt_catsdb IS NOT INITIAL.
SELECT PERNR
FROM ZTABLE
INTO TABLE GT_ZTABLE
FOR ALL ENTRIES IN lt_catsdb
WHERE PERNR = lt_catsdb-pernr.
IF  sy-subrc IS INITIAL.
SORT gt_ztable BY pernr. 
ENDIF. 
ENDIF.

LOOP AT gt_catsdb INTO gs_catsdb.
READ TABLE gt_ztable TRANSPORTING NO FIELDS WITH KEY pernr = gs_catsdb-pernr BINARY SEARCH.
IF sy-subrc IS INITIAL.
"Do something like below example
MESSAGE "Pernr exists in ZTABLE" TYPE 'S'.
ELSE.
MESSAGE "Pernr does not exists in ZTABLE" TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF
ENDLOOP.
CLEAR gs_catsdb.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rohit&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 13:48:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468941#M2000824</guid>
      <dc:creator>former_member753791</dc:creator>
      <dc:date>2021-06-29T13:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing two tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468942#M2000825</link>
      <description>&lt;P&gt;What do you want to do, do you need the records with data in both tables or only records without corresponding records?&lt;/P&gt;&lt;P&gt;You should look at the &lt;A href="https://help.sap.com/viewer/search?q=%22SELECT%22%20%22JOIN%22%20%22ABAP%22%20%22STATEMENT%22"&gt;multiple JOIN types&lt;/A&gt; available in Abap SQL, you could also consider&lt;A href="https://help.sap.com/viewer/search?q=%22SELECT%22%20%22SUBQUERY%22%20%22ABAP%22%20%22STATEMENT%22"&gt; subquery&lt;/A&gt;.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;" JOIN 
SELECT DISTINCT catsdb~pernr, catsdb~workdate, ztable~pernr AS pernr_check
  INTO TABLE @DATA(my_itab)
  FROM catsdb
  JOIN ztable " Adapt to your requirement LEFT/INNER/OUTER
    ON ztable~pernr EQ catsdb~pernr.
" SUBQUERY
SELECT DISTINCT catsdb~pernr, catsdb~workdate
  INTO TABLE @DATA(my_itab_2)
  FROM catsdb
  WHERE NOT EXISTS ( SELECT * FROM ztable WHERE pernr EQ catsdb~pernr ). " Adapt to your requirement&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Jul 2021 09:32:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/comparing-two-tables/m-p/12468942#M2000825</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2021-07-02T09:32:46Z</dc:date>
    </item>
  </channel>
</rss>

