<?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: Dynamic Table read with Dynamic Key fields in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739435#M1301344</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matt n Ankur,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Thanks for your reply, but in my scenario, I'm not sure about Number of key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  So, in where clause how do I include multiple keys in the below mentioned syntax?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;STRONG&gt;WITH KEY ('FIELD') = some_value.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Jun 2009 10:20:43 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-06-08T10:20:43Z</dc:date>
    <item>
      <title>Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739432#M1301341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  I've got a query related to &lt;STRONG&gt;Dynamic table read with Dynamic key fields&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Int. Table Name####    CASE 1####                               CASE 2&lt;/P&gt;&lt;P&gt;T_CURRENT####        Structure of MARA####               Structure of BSEG&lt;/P&gt;&lt;P&gt;T_COMPARE####       Structure of MARA####               Structure of BSEG&lt;/P&gt;&lt;P&gt;T_FIELD####               MATNR####                               BUKRS/BELNR/GJAHR/BUZEI &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;T_CURRENT and T_COMPARE tables have dynamic structure, and they will be populated at run time based on the table name specified. So, table keys depend on the table name selected by the user, which will be available in T_FIELDS table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've to read contents of the table T_CURRENT, for each record of T_COMPARE table using key fields. As mentioned in given example, we can have multiple scenarios, where Key fields vary from 1 to n.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, how do I tackle this logic?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Amit Satose on Jun 8, 2009 9:49 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 07:47:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739432#M1301341</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T07:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739433#M1301342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Please make use of field-symbols for creating the dynamic internal table and&lt;/P&gt;&lt;P&gt;use ASSIGN COMPONENT  OF STRUCTURE statement to access the fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can check this wiki for more details.&lt;/P&gt;&lt;P&gt;[https://wiki.sdn.sap.com/wiki/x/UYA_Bg]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ankur Parab&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 08:25:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739433#M1301342</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T08:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739434#M1301343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your dynamic table has, for example, a field with the name "FIELD", you can use&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE &amp;lt;dynamic_table&amp;gt; INTO &amp;lt;dynamic_work_area&amp;gt; WITH KEY ('FIELD') = some_value.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; or better &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CONTANTS: l_field TYPE fieldname VALUE 'FIELD'.
READ TABLE &amp;lt;dynamic_table&amp;gt; INTO &amp;lt;dynamic_work_area&amp;gt; WITH KEY (l_field) = some_value.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 08:26:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739434#M1301343</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2009-06-08T08:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739435#M1301344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matt n Ankur,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Thanks for your reply, but in my scenario, I'm not sure about Number of key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  So, in where clause how do I include multiple keys in the below mentioned syntax?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;STRONG&gt;WITH KEY ('FIELD') = some_value.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 10:20:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739435#M1301344</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T10:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739436#M1301345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;In that case instead of READ you can go for a LOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ankur Parab&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 10:28:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739436#M1301345</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T10:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739437#M1301346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ankur,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  As per my knowledge, system doesn't accept below mentioned syntax.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop @ T_table&lt;/P&gt;&lt;P&gt;  where (W_WHERE_CLAUSE).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Do you have any idea about the syntax to be used?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 10:52:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739437#M1301346</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T10:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739438#M1301347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;What i meant by loop was as follows:-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PARAMETERS: p_matnr  TYPE matnr,
            p_matnr1 TYPE matnr.

DATA: t_current TYPE STANDARD TABLE OF mara.
DATA: t_compare TYPE STANDARD TABLE OF mara,
      t_fields  TYPE STANDARD TABLE OF string.


DATA: wa  TYPE mara,
      wa1 TYPE string,
      wa2 TYPE mara.

DATA : cntr TYPE i,
       flag TYPE x.


FIELD-SYMBOLS: &amp;lt;f1&amp;gt; TYPE ANY,
               &amp;lt;f2&amp;gt; TYPE ANY.


wa1 = 'MATNR'.
APPEND wa1 TO t_fields.

wa1 = 'MEINS'.
APPEND wa1 TO t_fields.



SELECT * FROM mara
INTO TABLE t_current
WHERE matnr EQ p_matnr.

SELECT * FROM mara
INTO TABLE t_compare
WHERE matnr EQ p_matnr1.


CLEAR : flag .
LOOP AT t_compare INTO wa.
  LOOP AT t_current INTO wa2.
    CLEAR : cntr.
    LOOP AT t_fields INTO wa1.

      ASSIGN COMPONENT wa1 OF STRUCTURE wa  TO &amp;lt;f1&amp;gt;.
      ASSIGN COMPONENT wa1 OF STRUCTURE wa2 TO &amp;lt;f2&amp;gt;.

      IF &amp;lt;f1&amp;gt; EQ &amp;lt;f2&amp;gt;.
* read successful
      ELSE.
        ADD 1 TO cntr.
* read unsuccessful
      ENDIF.

    ENDLOOP.
    IF sy-subrc EQ 0.
      IF cntr EQ 0.
* record found
        WRITE:/ 'Record found'.
        flag = 'X'.
        EXIT.

      ELSE.
* record not found
        WRITE:/ 'Record not found'.
      ENDIF.

    ENDIF.
  ENDLOOP.
  IF flag EQ 'X'.
    EXIT.
  ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps you.&lt;/P&gt;&lt;P&gt;The read would be a bit tedious but thats the way it is if you have dynamic fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ankur Parab&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ankur Parab on Jun 8, 2009 4:53 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 11:23:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739438#M1301347</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T11:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739439#M1301348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ankur,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Thanks again for quick turnaround.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  But, as per your logic, all the fields of the table are getting compared. But I need to compare only key fields, and if match found/not found, need to generate report for the non-key fields contents.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Do you see any modification for this logic to suit the requirements?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 11:54:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739439#M1301348</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T11:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739440#M1301349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I was under the assuption that the table T_FIELDS will contain only the keyfields.&lt;/P&gt;&lt;P&gt;Anyways if you are referring to data dictionary tables then you can make use of FM 'DDIF_FIELDINFO_GET' to get the fields of the particular table. The field KEYFLAG of the tables parameter DFIES_TAB will indicate whether the field is a key field or not.&lt;/P&gt;&lt;P&gt;So in this way you can get your key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Incase your dynamic tables are not directly coming from the data dictionary then in that case you will have to think of some solution as to how to find the key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ankur Parab&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2009 12:33:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739440#M1301349</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-08T12:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Table read with Dynamic Key fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739441#M1301350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Modified the logic provided by Ankur to suit the end user requirement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jun 2009 05:59:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-table-read-with-dynamic-key-fields/m-p/5739441#M1301350</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-06-09T05:59:03Z</dc:date>
    </item>
  </channel>
</rss>

