2023 Apr 08 7:32 AM
Dar ALl,
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.
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 defpa
INTO TABLE it_wyt3
LOOP AT it_po.
* 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.
The row with PARVW = 'VA' is fetched istead of "RS".
Regards,
2023 Apr 08 9:32 AM
When you post code, please use the handy little CODE button in the editor to make the code readable.
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.
As far as you question goes,
READ TABLE it_ekpa WITH KEY parvw = 'RS' BINARY SEARCH.<br>
cannot return a record where parvw is not 'RS', unless your ABAP interpretator is broken. Which seems impossibly unlikely.
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.
2023 Apr 08 6:29 PM
Dear Matthew,
Thanks for replying and apologies for uploading the screen shot of debugger without DEFPA being added(wrong screen shot).
I will add the code in code button going ahead.
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.
2023 Apr 09 8:32 AM
As I said:
READ TABLE it_ekpa WITH KEY parvw = 'RS' BINARY SEARCH.
cannot return a record where parvw is not 'RS'
Your screen shot doesn't show any evidence of any issue.
2023 Apr 12 11:52 AM
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?
I mean, what if you fetched the VA before, and when trying to fetch the RS your SAP was unable to reach it?
How is that it_ekpa defined? sorted, hashed, standard? What's the difference if you use binary search with those types?
Just wondering, I'm too lazy to search it by myself.
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.
2023 Apr 08 11:34 AM
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.
2023 Apr 12 9:59 AM
I can see sorting is on non-unique key.
try below if you still not got the solution,
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.
2023 Apr 12 10:45 AM
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'.
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.
2023 Apr 14 6:14 AM
Instead of posting many answers to fix typo or whatever, please use Actions > Edit.
2023 Apr 14 6:03 AM
Sort it_ekpa by parvw.
loop at it_po.
read table it_epka with key parvw = 'RS' binary search assigning field-symbol(<lfs_ekpa>).
endloop.
Please check the above code.
2023 Apr 14 6:05 AM
Please check Below code.
Sort it_ekpa by parvw.
loop at it_po.
read table it_ekpa with key parvw = 'RS' binary search assigning field-symbol(<lfs_ekpa>).
endloop.