<?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: Filter data using loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/filter-data-using-loop/m-p/673775#M29741</link>
    <description>&lt;P&gt;Hi Rachid, You have to put where condition for the second loop. But from the above code i dont think you are retrieving item data based on header data. &lt;/P&gt;&lt;P&gt;1. corresponding is not necessary and use for all entries to get data from VBAP data&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select * from vbak
into of table gt_vbak
where ( vbtyp = 'B' or vbtyp = 'C' ) and kunnr = customer .
if sy-subrc = 0.
* Delete the order which are not required for further processing.
  delete gt_vbak where vbtyp = 'C' or vbtyp = 'B'.
* Get Sales Item data
  if gt_vbak is not initial.
    select * from vbap 
    into of table gt_vbap
    for all entries in gt_vbak
    where vbeln = vbak-vbeln.
  endif.
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;2.Not sure why did you take another internal table - GT_VBAK2. &lt;/P&gt;&lt;P&gt;And get the delivery data based on the above sales order.Here you no need to have LOOP statement.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Oct 2018 20:29:24 GMT</pubDate>
    <dc:creator>srikanthnalluri</dc:creator>
    <dc:date>2018-10-11T20:29:24Z</dc:date>
    <item>
      <title>Filter data using loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/filter-data-using-loop/m-p/673774#M29740</link>
      <description>&lt;P&gt;I am new to abap and I need your help. I am basically creating a function module with import parameter the customer number(KUNNR). and returning 8 tables .&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;This is the source code of the function module.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;*"*"Local Interface:&lt;BR /&gt; *" IMPORTING&lt;BR /&gt; *" VALUE(CUSTOMER) TYPE KUNNR&lt;BR /&gt; *" TABLES&lt;BR /&gt; *" GT_VBAK STRUCTURE VBAK&lt;BR /&gt; *" GT_VBAP STRUCTURE VBAP&lt;BR /&gt; *" GT_LIKP STRUCTURE LIKP&lt;BR /&gt; *" GT_LIPS STRUCTURE LIPS&lt;BR /&gt; *" GT_VBRK STRUCTURE VBRK&lt;BR /&gt; *" GT_VBRP STRUCTURE VBRP&lt;BR /&gt; *" GT_VBAK2 STRUCTURE VBAK&lt;BR /&gt; *" GT_VBAP2 STRUCTURE VBAP&lt;BR /&gt; *" RETURN STRUCTURE BAPIRET2&lt;BR /&gt; *"----------------------------------------------------------------------&lt;BR /&gt; data: wa_return type bapiret2 .&lt;BR /&gt; data gs_vbak type vbak .&lt;BR /&gt; data gs_vbap type vbap .&lt;BR /&gt; data gs_vbak2 type vbak .&lt;BR /&gt; data gs_vbap2 type vbap .&lt;BR /&gt; data: gs_likp type likp.&lt;BR /&gt; data gs_lips type lips .&lt;BR /&gt; data: gs_vbrk type vbrk ,&lt;BR /&gt; gs_vbrp type vbrp .&lt;BR /&gt; data w_tabix type sy-tabix .&lt;BR /&gt; &lt;BR /&gt; select * from vbak&lt;BR /&gt; into corresponding fields of table gt_vbak&lt;BR /&gt; where vbak~vbtyp = 'B' or vbak~vbtyp = 'C'&lt;BR /&gt; and&lt;BR /&gt; vbak~kunnr = customer .&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; select * from vbap&lt;BR /&gt; into corresponding fields of table gt_vbap.&lt;BR /&gt;*this works&lt;BR /&gt; loop at gt_vbak into gs_vbak.&lt;BR /&gt; append gs_vbak to gt_vbak2 .&lt;BR /&gt; if gs_vbak-vbtyp = 'B' .&lt;BR /&gt; delete gt_vbak where vbtyp = 'C' .&lt;BR /&gt; endif.&lt;BR /&gt; loop at gt_vbak2 into gs_vbak2.&lt;BR /&gt; if gs_vbak2-vbtyp = 'C' .&lt;BR /&gt; delete gt_vbak2 where vbtyp = 'B'.&lt;BR /&gt; endif.&lt;BR /&gt; endloop.&lt;BR /&gt; &lt;BR /&gt; endloop.&lt;BR /&gt; &lt;BR /&gt; *filter vbap-vbeln must be eq to vbak-vbeln. It doesn't work it shows me all vbeln that are *not the same&lt;BR /&gt; loop at gt_vbak into gs_vbak .&lt;BR /&gt; loop at gt_vbap into gs_vbap .&lt;BR /&gt; W_TABIX = SY-TABIX.&lt;BR /&gt; if gs_vbap-vbeln ne gs_vbak-vbeln .&lt;BR /&gt; delete gt_vbap index w_tabix .&lt;BR /&gt; endif.&lt;BR /&gt; &lt;BR /&gt; endloop.&lt;BR /&gt; endloop.&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; select * from vbap&lt;BR /&gt; into corresponding fields of table gt_vbap2 .&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;loop at gt_vbak2 into gs_vbak2 .&lt;BR /&gt;loop at gt_vbap2 into gs_vbap2 ."where vbeln eq gs_vbak2-vbeln .&lt;BR /&gt; read table gt_vbap2 into gs_vbap2 with key vbeln = gs_vbak-vbeln.&lt;BR /&gt; if sy-subrc ne 0.&lt;BR /&gt; delete gt_vbap2 .&lt;BR /&gt; endif.&lt;BR /&gt;W_TABIX = SY-TABIX.&lt;BR /&gt;&lt;BR /&gt;modify gt_vbap2 from gs_vbap2 index w_tabix.&lt;BR /&gt;&lt;BR /&gt;endloop.&lt;BR /&gt; endloop.&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; select * from likp&lt;BR /&gt; into corresponding fields of table gt_likp&lt;BR /&gt; where kunnr = customer .&lt;BR /&gt; &lt;BR /&gt; select * from lips&lt;BR /&gt; into corresponding fields of table gt_lips.&lt;BR /&gt; &lt;BR /&gt; loop at gt_likp into gs_likp .&lt;BR /&gt; loop at gt_lips into gs_lips .&lt;BR /&gt; if gs_lips-vbeln ne gs_likp-vbeln.&lt;BR /&gt; delete gt_lips .&lt;BR /&gt; endif.&lt;BR /&gt; endloop.&lt;BR /&gt; endloop.&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; select * from vbrk&lt;BR /&gt; into corresponding fields of table gt_vbrk&lt;BR /&gt; where kunag = customer .&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; select * from vbrp&lt;BR /&gt; into corresponding fields of table gt_vbrp.&lt;BR /&gt; &lt;BR /&gt; loop at gt_vbrk into gs_vbrk.&lt;BR /&gt; loop at gt_vbrp into gs_vbrp.&lt;BR /&gt; if gs_vbrp-vbeln ne gs_vbrk-vbeln.&lt;BR /&gt; delete gt_vbrp .&lt;BR /&gt; endif.&lt;BR /&gt; endloop.&lt;BR /&gt; endloop.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Basically I need a way to filter the records which the vbeln in vbap is equal to the vbeln in vbak.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;How can I achieve this ?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 19:49:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/filter-data-using-loop/m-p/673774#M29740</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2018-10-11T19:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Filter data using loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/filter-data-using-loop/m-p/673775#M29741</link>
      <description>&lt;P&gt;Hi Rachid, You have to put where condition for the second loop. But from the above code i dont think you are retrieving item data based on header data. &lt;/P&gt;&lt;P&gt;1. corresponding is not necessary and use for all entries to get data from VBAP data&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select * from vbak
into of table gt_vbak
where ( vbtyp = 'B' or vbtyp = 'C' ) and kunnr = customer .
if sy-subrc = 0.
* Delete the order which are not required for further processing.
  delete gt_vbak where vbtyp = 'C' or vbtyp = 'B'.
* Get Sales Item data
  if gt_vbak is not initial.
    select * from vbap 
    into of table gt_vbap
    for all entries in gt_vbak
    where vbeln = vbak-vbeln.
  endif.
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;2.Not sure why did you take another internal table - GT_VBAK2. &lt;/P&gt;&lt;P&gt;And get the delivery data based on the above sales order.Here you no need to have LOOP statement.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 20:29:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/filter-data-using-loop/m-p/673775#M29741</guid>
      <dc:creator>srikanthnalluri</dc:creator>
      <dc:date>2018-10-11T20:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: Filter data using loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/filter-data-using-loop/m-p/673776#M29742</link>
      <description>&lt;P&gt;you could have performance issue with select *, into corresponding, select no where conditions...etc so I suggest you re-check your code, requirement first.&lt;/P&gt;&lt;P&gt;Second, your thinking is too complicate. I suppose your requirement is get data from vbap and vbak with each vbtyp = B, vbtyp = C to corresponding output table. I can suggest you doing like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT VBAK~*, VBAP~* FROM vbak
 INNER JOIN vbap ON ( vbak~vbeln = vbap~vbeln )
 WHERE vbak~vbtyp IN ( 'B' , 'C' ) INTO TABLE @DATA(lt_all).

LOOP AT lt_all INTO DATA(ls_all).
 IF ls_all-vbak-vbtyp = 'C'.
 APPEND ls_all-vbak TO gt_vbak.
 APPEND ls_all-vbap TO gt_vbap.
 ENDIF.

ENDLOOP.
SORT gt_vbak BY vbeln.
DELETE ADJACENT DUPLICATES FROM lt_vbak.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Oct 2018 02:42:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/filter-data-using-loop/m-p/673776#M29742</guid>
      <dc:creator>DoanManhQuynh</dc:creator>
      <dc:date>2018-10-12T02:42:01Z</dc:date>
    </item>
  </channel>
</rss>

