<?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: Read statement fetching wrong value in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691646#M2017679</link>
    <description>&lt;P&gt;When you post code, please use the handy little CODE button in the editor to make the code readable.&lt;/P&gt;&lt;P&gt;Also, while your working on this code, you should follow the scout principle of improving it. E.g. no longer use a table with a header line.&lt;/P&gt;&lt;P&gt;As far as you question goes,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE it_ekpa WITH KEY parvw = 'RS' BINARY SEARCH.&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;cannot return a record where parvw is not 'RS', unless your ABAP interpretator is broken. Which seems impossibly unlikely.&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Your image does not demonstrate that it is. Since sy-tabix is 2, it is clearly reading the right record. Instead of checking the table contents in debug, try checking the header line. Oh, and if you had fixed the program to not use a table with a header-line, you would never have got confused.&lt;/P&gt;</description>
    <pubDate>Sat, 08 Apr 2023 08:32:23 GMT</pubDate>
    <dc:creator>matt</dc:creator>
    <dc:date>2023-04-08T08:32:23Z</dc:date>
    <item>
      <title>Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691645#M2017678</link>
      <description>&lt;P&gt;Dar ALl,&lt;/P&gt;
  &lt;P&gt;Can anybody kindly help me?I have following old code in the system and its Read statement at the end started fetching wrong row in internal table after I added "defpa" as shown below.The table entries in it_ekpa before and after adding DEFPA are same.&lt;/P&gt;
  &lt;P&gt; it_po_tmp[] = it_po[].&lt;/P&gt;
  &lt;P&gt; SORT it_po_tmp BY lifnr ekorg.&lt;BR /&gt; DELETE ADJACENT DUPLICATES FROM it_po_tmp COMPARING lifnr ekorg.&lt;BR /&gt; IF NOT it_po_tmp[] IS INITIAL.&lt;BR /&gt; SELECT lifnr ekorg parvw lifn2&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;      defpa  "I added this defpa&lt;/CODE&gt;&lt;/PRE&gt; INTO TABLE it_wyt3 
  &lt;BR /&gt; FROM wyt3 
  &lt;BR /&gt; FOR ALL ENTRIES IN it_po_tmp 
  &lt;BR /&gt; WHERE lifnr EQ it_po_tmp-lifnr 
  &lt;BR /&gt; AND ekorg EQ it_po_tmp-ekorg 
  &lt;BR /&gt; AND parvw EQ 'RS'. 
  &lt;BR /&gt; REFRESH it_po_tmp. 
  &lt;BR /&gt; IF NOT it_wyt3[] IS INITIAL. 
  &lt;BR /&gt; SORT it_wyt3 BY lifnr ekorg. 
  &lt;BR /&gt; ENDIF. 
  &lt;BR /&gt; ENDIF. 
  &lt;BR /&gt;* End of changes pthati 205929 01/10/11 
  &lt;P&gt; LOOP AT it_po.&lt;/P&gt; 
  &lt;BR /&gt; PERFORM bdc_dynpro USING: 'X' 'SAPMM06E' '0105', 
  &lt;BR /&gt; ' ' 'RM06E-BSTNR' it_po-banfn, 
  &lt;BR /&gt; ' ' 'BDC_OKCODE' '/00'. 
  &lt;BR /&gt; CLEAR it_last_po. 
  &lt;BR /&gt; READ TABLE it_last_po WITH KEY banfn = it_po-banfn BINARY SEARCH. 
  &lt;BR /&gt;*--Partner functions 
  &lt;BR /&gt; CLEAR : it_ekpa, it_ekpa[]. 
  &lt;BR /&gt; SELECT ebeln 
  &lt;BR /&gt; ebelp 
  &lt;BR /&gt; ekorg 
  &lt;BR /&gt; ltsnr 
  &lt;BR /&gt; werks 
  &lt;BR /&gt; parvw 
  &lt;BR /&gt; parza 
  &lt;BR /&gt; lifn2 
  &lt;BR /&gt; INTO TABLE it_ekpa 
  &lt;BR /&gt; FROM ekpa 
  &lt;BR /&gt; WHERE ebeln = it_last_po-ebeln 
  &lt;BR /&gt; AND ekorg = 'P101' 
  &lt;BR /&gt;
  &lt;P&gt;* and werks = it_eban-werks &lt;/P&gt;
  &lt;P&gt; AND parvw IN ('VA', 'BA', 'RS' ). &lt;/P&gt; 
  &lt;BR /&gt;
  &lt;P&gt; SORT it_ekpa BY parvw.&lt;/P&gt;READ TABLE it_ekpa WITH KEY parvw = 'RS' BINARY SEARCH.
  &lt;P&gt;endloop.&lt;/P&gt;
  &lt;P&gt;The row with PARVW = 'VA' is fetched istead of "RS".&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2161882-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 06:32:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691645#M2017678</guid>
      <dc:creator>sanjay_deshpande4</dc:creator>
      <dc:date>2023-04-08T06:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691646#M2017679</link>
      <description>&lt;P&gt;When you post code, please use the handy little CODE button in the editor to make the code readable.&lt;/P&gt;&lt;P&gt;Also, while your working on this code, you should follow the scout principle of improving it. E.g. no longer use a table with a header line.&lt;/P&gt;&lt;P&gt;As far as you question goes,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE it_ekpa WITH KEY parvw = 'RS' BINARY SEARCH.&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;cannot return a record where parvw is not 'RS', unless your ABAP interpretator is broken. Which seems impossibly unlikely.&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Your image does not demonstrate that it is. Since sy-tabix is 2, it is clearly reading the right record. Instead of checking the table contents in debug, try checking the header line. Oh, and if you had fixed the program to not use a table with a header-line, you would never have got confused.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 08:32:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691646#M2017679</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2023-04-08T08:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691647#M2017680</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;it_po_tmp[] = it_po[].

SORT it_po_tmp BY lifnr ekorg.
DELETE ADJACENT DUPLICATES FROM it_po_tmp COMPARING lifnr ekorg.
IF NOT it_po_tmp[] IS INITIAL.
  SELECT lifnr ekorg parvw lifn2

      defpa  "I added this defpaINTO TABLE it_wyt3
    FROM wyt3
    FOR ALL ENTRIES IN it_po_tmp
    WHERE lifnr EQ it_po_tmp-lifnr
    AND ekorg EQ it_po_tmp-ekorg
    AND parvw EQ 'RS'.
  REFRESH it_po_tmp.
  IF NOT it_wyt3[] IS INITIAL.
    SORT it_wyt3 BY lifnr ekorg.
  ENDIF.
ENDIF.
* End of changes pthati 205929 01/10/11
LOOP AT it_po.


  PERFORM bdc_dynpro USING: 'X' 'SAPMM06E' '0105',
' ' 'RM06E-BSTNR' it_po-banfn,
' ' 'BDC_OKCODE' '/00'.
  CLEAR it_last_po.
  READ TABLE it_last_po WITH KEY banfn = it_po-banfn BINARY SEARCH.
*--Partner functions
  CLEAR : it_ekpa, it_ekpa[].
  SELECT ebeln
    ebelp
    ekorg
    ltsnr
    werks
    parvw
    parza
    lifn2
    INTO TABLE it_ekpa
    FROM ekpa
    WHERE ebeln = it_last_po-ebeln
    AND ekorg = 'P101'
*    and werks = it_eban-werks

    AND parvw IN ('VA', 'BA', 'RS' ).


  SORT it_ekpa BY parvw.

  READ TABLE it_ekpa WITH KEY parvw = 'RS' BINARY SEARCH.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Apr 2023 10:34:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691647#M2017680</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-04-08T10:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691648#M2017681</link>
      <description>&lt;P&gt;Dear Matthew,&lt;/P&gt;&lt;P&gt;Thanks for replying and apologies for uploading the screen shot of debugger without DEFPA being added(wrong screen shot).&lt;/P&gt;&lt;P&gt;I will add the code in code button going ahead.&lt;/P&gt;&lt;P&gt;Here is the screen shot after adding the DEFPA in select query in debug mode. I have tried F1 help as well, however couldnt understand why it should affect the existing functionality after adding DEFPA in select query. kindly help.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2161895-image.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 17:29:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691648#M2017681</guid>
      <dc:creator>sanjay_deshpande4</dc:creator>
      <dc:date>2023-04-08T17:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691649#M2017682</link>
      <description>&lt;P&gt;As I said:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE it_ekpa WITH KEY parvw = 'RS' BINARY SEARCH.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;cannot return a record where parvw is not 'RS'&lt;/P&gt;&lt;P&gt;Your screen shot doesn't show any evidence of any issue.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 07:32:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691649#M2017682</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2023-04-09T07:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691650#M2017683</link>
      <description>&lt;P&gt;I can see sorting is on non-unique key.&lt;/P&gt;&lt;P&gt;try below if you still not got the solution,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;loop at it_po into data(lwa_po).
Sort it_ekpa by ebeln parvw.
read table it_epka with key ebeln = lwa_po-ebeln parvw = 'RS' binary search.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Apr 2023 08:59:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691650#M2017683</guid>
      <dc:creator>shantraj6</dc:creator>
      <dc:date>2023-04-12T08:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691651#M2017684</link>
      <description>&lt;P&gt;It makes no difference if the table is sorted by a non-unique key. The read still cannot return a row that doesn't have parvw = 'RS'.&lt;/P&gt;&lt;P&gt;And as you can see from his debug, there's only on entry with parvw = 'RS', and the fact that sy-tabix = 2, indicates he is getting the right row.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 09:45:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691651#M2017684</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2023-04-12T09:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691652#M2017685</link>
      <description>&lt;P&gt;Just wondering, because I gladly cut my fingers than to use header lines... but what happens when the READ TABLE finds nothing but its header line had values prior the READ?&lt;/P&gt;&lt;P&gt;I mean, what if you fetched the VA before, and when trying to fetch the RS your SAP was unable to reach it?&lt;/P&gt;&lt;P&gt;How is that it_ekpa defined? sorted, hashed, standard? What's the difference if you use binary search with those types?&lt;/P&gt;&lt;P&gt;Just wondering, I'm too lazy to search it by myself.&lt;/P&gt;&lt;P&gt;Advice: get rid of the header line, declare a proper workarea variable and check the result of the query (sy-subrc equals???) to know if SAP found your row or if it didn't.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 10:52:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691652#M2017685</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2023-04-12T10:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691653#M2017686</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;Sort it_ekpa by parvw.
loop at it_po.
read table it_epka with key parvw = 'RS' binary search assigning field-symbol(&amp;lt;lfs_ekpa&amp;gt;).
endloop.

Please check the above code.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Apr 2023 05:03:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691653#M2017686</guid>
      <dc:creator>shantraj6</dc:creator>
      <dc:date>2023-04-14T05:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691654#M2017687</link>
      <description>&lt;P&gt;Please check Below code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;Sort it_ekpa by parvw.
loop at it_po.
read table it_ekpa with key parvw = 'RS' binary search assigning field-symbol(&amp;lt;lfs_ekpa&amp;gt;).
endloop.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Apr 2023 05:05:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691654#M2017687</guid>
      <dc:creator>shantraj6</dc:creator>
      <dc:date>2023-04-14T05:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read statement fetching wrong value</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691655#M2017688</link>
      <description>&lt;P&gt;Instead of posting many answers to fix typo or whatever, please use &lt;STRONG&gt;Actions &amp;gt; Edit&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 05:14:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-statement-fetching-wrong-value/m-p/12691655#M2017688</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2023-04-14T05:14:03Z</dc:date>
    </item>
  </channel>
</rss>

