<?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: ABAP new Syntax - Conditional FOR Loop with insert etc. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131381#M1975170</link>
    <description>&lt;P&gt;This is the statement that should work for you, after you have probably modified the TABLE TYPE definitions (and probably other corrections, such as the attribute restriction on MT_XYZ &amp;lt;&amp;gt; C, your coding is missing the attribute)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(lt_keys) = VALUE tty_keys( FOR wa1 IN mt_xyz WHERE ( key &amp;lt;&amp;gt; 'C' AND field = 'z' )
                                FOR wa2 IN lt_abc USING KEY parent_key
                                                  WHERE ( parent_key = wa1-key )
                               ( key = wa1-key ) ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is a test report with sample data and the output for the above coding:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT ZVALUESFOREXAMPLE.

TYPES: BEGIN OF ty_key,
         key TYPE char1,
       END OF ty_key,
       tty_keys TYPE STANDARD TABLE OF ty_key WITH EMPTY KEY,
       BEGIN OF ty_xyz,
         key   TYPE char1,
         field TYPE char1,
       END OF ty_xyz,
       tty_xyz TYPE STANDARD TABLE OF ty_xyz WITH EMPTY KEY,
       BEGIN OF ty_abc,
         key        TYPE char1,
         parent_key TYPE char1,
       END OF ty_abc,
       tty_abc TYPE STANDARD TABLE OF ty_abc WITH EMPTY KEY
            WITH NON-UNIQUE SORTED KEY parent_key COMPONENTS parent_key.

" Test data for table mt_xyz
DATA(mt_xyz) = VALUE tty_xyz( ( key = 'A' field = 'z' )
                              ( key = 'B' field = 'y' )
                              ( key = 'C' field = 'x' )
                              ( key = 'D' field = 'w' ) ).

" Test data for table lt_abc
DATA(lt_abc) = VALUE tty_abc( ( key = 'B' parent_key = 'A' )
                              ( key = 'D' parent_key = 'C' ) ).

" THIS IS THE ACTUAL STATEMENT YOU ARE LOOKING FOR
" Creation of values for table lt_keys based on mt_xyz and lt_abc
DATA(lt_keys) = VALUE tty_keys( FOR wa1 IN mt_xyz WHERE ( key &amp;lt;&amp;gt; 'C' AND field = 'z' )
                                FOR wa2 IN lt_abc USING KEY parent_key
                                                  WHERE ( parent_key = wa1-key )
                               ( key = wa1-key ) ).

" Output of example data
DATA(out) = cl_demo_output=&amp;gt;new( ).
out-&amp;gt;write( mt_xyz ).
out-&amp;gt;write( lt_abc ).
out-&amp;gt;write( lt_keys ).
out-&amp;gt;display( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1793983-example-output.png" /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Apr 2020 08:39:04 GMT</pubDate>
    <dc:creator>michael_piesche</dc:creator>
    <dc:date>2020-04-07T08:39:04Z</dc:date>
    <item>
      <title>ABAP new Syntax - Conditional FOR Loop with insert etc.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131380#M1975169</link>
      <description>&lt;P&gt;Hello together,&lt;/P&gt;
  &lt;P&gt;is it possible to write this in new syntax by using a for loop?&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;LOOP AT mt_xyz assigning &amp;lt;ls_xyz&amp;gt;.

if &amp;lt;ls_xyz&amp;gt; &amp;lt;&amp;gt; 'C'.

CONTINUE.

endif.

READ TABLE lt_abc assigning &amp;lt;ls_abc&amp;gt; with key parent_key components parent_key = &amp;lt;ls_xyz&amp;gt;-key.

if sy-subrc &amp;lt;&amp;gt; 0.

CONTINUE.

endif.

if &amp;lt;ls_xyz&amp;gt;-field = 'z'.

ls_key-key = &amp;lt;ls_xyz&amp;gt;-key.

INSERT ls_key into table lt_keys.

endif.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Kind regards,&lt;/P&gt;
  &lt;P&gt;Pascal&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 07:52:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131380#M1975169</guid>
      <dc:creator>former_member647100</dc:creator>
      <dc:date>2020-04-07T07:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP new Syntax - Conditional FOR Loop with insert etc.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131381#M1975170</link>
      <description>&lt;P&gt;This is the statement that should work for you, after you have probably modified the TABLE TYPE definitions (and probably other corrections, such as the attribute restriction on MT_XYZ &amp;lt;&amp;gt; C, your coding is missing the attribute)&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(lt_keys) = VALUE tty_keys( FOR wa1 IN mt_xyz WHERE ( key &amp;lt;&amp;gt; 'C' AND field = 'z' )
                                FOR wa2 IN lt_abc USING KEY parent_key
                                                  WHERE ( parent_key = wa1-key )
                               ( key = wa1-key ) ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is a test report with sample data and the output for the above coding:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT ZVALUESFOREXAMPLE.

TYPES: BEGIN OF ty_key,
         key TYPE char1,
       END OF ty_key,
       tty_keys TYPE STANDARD TABLE OF ty_key WITH EMPTY KEY,
       BEGIN OF ty_xyz,
         key   TYPE char1,
         field TYPE char1,
       END OF ty_xyz,
       tty_xyz TYPE STANDARD TABLE OF ty_xyz WITH EMPTY KEY,
       BEGIN OF ty_abc,
         key        TYPE char1,
         parent_key TYPE char1,
       END OF ty_abc,
       tty_abc TYPE STANDARD TABLE OF ty_abc WITH EMPTY KEY
            WITH NON-UNIQUE SORTED KEY parent_key COMPONENTS parent_key.

" Test data for table mt_xyz
DATA(mt_xyz) = VALUE tty_xyz( ( key = 'A' field = 'z' )
                              ( key = 'B' field = 'y' )
                              ( key = 'C' field = 'x' )
                              ( key = 'D' field = 'w' ) ).

" Test data for table lt_abc
DATA(lt_abc) = VALUE tty_abc( ( key = 'B' parent_key = 'A' )
                              ( key = 'D' parent_key = 'C' ) ).

" THIS IS THE ACTUAL STATEMENT YOU ARE LOOKING FOR
" Creation of values for table lt_keys based on mt_xyz and lt_abc
DATA(lt_keys) = VALUE tty_keys( FOR wa1 IN mt_xyz WHERE ( key &amp;lt;&amp;gt; 'C' AND field = 'z' )
                                FOR wa2 IN lt_abc USING KEY parent_key
                                                  WHERE ( parent_key = wa1-key )
                               ( key = wa1-key ) ).

" Output of example data
DATA(out) = cl_demo_output=&amp;gt;new( ).
out-&amp;gt;write( mt_xyz ).
out-&amp;gt;write( lt_abc ).
out-&amp;gt;write( lt_keys ).
out-&amp;gt;display( ).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1793983-example-output.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 08:39:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131381#M1975170</guid>
      <dc:creator>michael_piesche</dc:creator>
      <dc:date>2020-04-07T08:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP new Syntax - Conditional FOR Loop with insert etc.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131382#M1975171</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;thanks for your fast reply.&lt;/P&gt;&lt;P&gt;How to add CONTINUE and the Read Table statement?&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Pascal&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 08:46:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131382#M1975171</guid>
      <dc:creator>former_member647100</dc:creator>
      <dc:date>2020-04-07T08:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP new Syntax - Conditional FOR Loop with insert etc.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131383#M1975172</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;coding1407&lt;/SPAN&gt;, the above coding is the final construct with the new syntax of what you did with the old syntax. &lt;/P&gt;&lt;UL&gt;&lt;LI&gt; The first where condition partially represents the CONTINUE logic.&lt;/LI&gt;&lt;LI&gt;The second where condition represents the Read Table statement. &lt;/LI&gt;&lt;LI&gt;The using key statement makes sure to use a specific key when accessing table values of the second table. &lt;/LI&gt;&lt;LI&gt;The last parenthesized statement creates the new values for the third table.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Try it out and play with it. &lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 08:53:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-new-syntax-conditional-for-loop-with-insert-etc/m-p/12131383#M1975172</guid>
      <dc:creator>michael_piesche</dc:creator>
      <dc:date>2020-04-07T08:53:31Z</dc:date>
    </item>
  </channel>
</rss>

