2021 Feb 12 8:30 AM
Dear Experts,
With some reference, I have written below statement instead of normal Read statement to get an entry from an Internal table with some Key. But as the entry not existing with the passed key, process goes to runtime error.
ABAP Statement:
DATA(ls_ekko) = gt_ekko[ ebeln = ls_bseg-ebeln ].
IF sy-subrc = 0.
ls_output = VALUE zncms0002( bedat = ls_ekko-bedat ).
ENDIF.
"In the above statement LS_BSEG-EBELN is blank.
Runtime Error:
The reason for the exception is: Access failed for table "GT_EKKO". Access method: "KEY". Line index (for "INDEX" access) / key name (for "KEY" access): "<free key>". Key values: " " " " " " " "
Can anyone please let me know how can we overcome this runtime error and use as general READ statement?
2021 Feb 12 1:17 PM
14434537ae0441799e327b92f10dfe46 suggested a good blog in the comment.
There is also information to read in the ABAP documentation.
The cx_sy_itab_line_not_found is what is thrown when no line is found, instead of sy-subrc for READ TABLE, so you need to catch that one as suggested.
There is also the possibility to using the value operator here, depending on your exact use case/need:
ekko_bedat = VALUE #( gt_ekko[ ebeln = ls_bseg-ebeln ]-bedat OPTIONAL ).
Using the OPTIONAL parameter will NOT cause the exception to be thrown if no line is found. Instead the 'ekko_bedat' will be INITIAL (whatever that is for the current data type) so you would still have to check it before you use it further down in the code...
2021 Feb 12 9:14 AM
"If a table line is not found, the exception CX_SY_ITAB_LINE_NOT_FOUND is raised. No sy-subrc from expressions, of course."
Please refer to: https://blogs.sap.com/2013/05/29/abap-news-for-release-740-table-expressions/
I Think that you could try someting like this:
TRY.
DATA(ls_ekko) = gt_ekko[ ebeln = ls_bseg-ebeln ].
CATCH cx_sy_itab_line_not_found.
ENDTRY.
2021 Feb 12 9:32 AM
Hi Luis,
Thanks for your quick response / solution and blog. Now I would like to ask, can these statement meant for replacement of Read statement? And is there any performance differences in Read and the above statement, as we are not using any search techniques (Binary)?
2021 Feb 12 1:17 PM
14434537ae0441799e327b92f10dfe46 suggested a good blog in the comment.
There is also information to read in the ABAP documentation.
The cx_sy_itab_line_not_found is what is thrown when no line is found, instead of sy-subrc for READ TABLE, so you need to catch that one as suggested.
There is also the possibility to using the value operator here, depending on your exact use case/need:
ekko_bedat = VALUE #( gt_ekko[ ebeln = ls_bseg-ebeln ]-bedat OPTIONAL ).
Using the OPTIONAL parameter will NOT cause the exception to be thrown if no line is found. Instead the 'ekko_bedat' will be INITIAL (whatever that is for the current data type) so you would still have to check it before you use it further down in the code...
2021 Feb 12 1:19 PM
or
ls_output = VALUE #( bedat = VALUE #( gt_ekko[ ebeln = ls_bseg-ebeln ]-bedat OPTIONAL ) ).
2021 Feb 17 12:54 PM
Hello All,
I would like to say 14434537ae0441799e327b92f10dfe46's comment is also very much helpful to resolve my issue. Thank you!