‎2020 Apr 08 7:45 AM
Hello together,
I used a READ TABLE statement in combination with ASSIGNING and now replaced it by the following coding:
TRY.
ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
CATCH cx_sy_itab_line_not_found.
" TBD: Error Handling
ENDTRY.
Directly after this read statement, there was an ASSERT sy-subrc = 0 in the old version.
How to enable this by using the new syntax? Can that be replaced if we now do something like ASSERT cx_sy_itab_line_not_found is bound in the CATCH statement?
Any Ideas?
Kind regards
‎2020 Apr 08 11:30 AM
TRY.
ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
CATCH cx_sy_itab_line_not_found.
ENDTRY.
ASSERT sy-subrc = 0.In other instances, you might want to rewrite it to something like this, to make sure that the assignment was successfull. This way you dont rely on sy-subrc, which would also make it more robust and more straight forward:
UNASSIGN <ls_fu_root>.
TRY.
ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
CATCH cx_sy_itab_line_not_found.
" TBD: Error Handling
ENDTRY.
ASSERT <ls_fu_root> IS ASSIGNED.
‎2020 Apr 08 9:23 AM
As of 7.53, ASSERT has no replacement, hopefully.
If you understand what ASSERT means, don't replace it with TRY CATCH.
‎2020 Apr 08 9:52 AM
That means, it is not possible to replace the read statement when an assert follows, correct?
BR
‎2020 Apr 08 11:30 AM
TRY.
ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
CATCH cx_sy_itab_line_not_found.
ENDTRY.
ASSERT sy-subrc = 0.In other instances, you might want to rewrite it to something like this, to make sure that the assignment was successfull. This way you dont rely on sy-subrc, which would also make it more robust and more straight forward:
UNASSIGN <ls_fu_root>.
TRY.
ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
CATCH cx_sy_itab_line_not_found.
" TBD: Error Handling
ENDTRY.
ASSERT <ls_fu_root> IS ASSIGNED.
‎2020 Apr 08 1:54 PM
If you are using ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
then why not check sy-subrc = 0 or if you want to raise some exception then sy-subrc <> 0.
ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
if sy-subrc = 0.
" do something
endif,
OR
ASSIGN mt_fu_root_data[ key = <ls_dlv_kl_fu>-target_key ] TO <ls_fu_root>.
if sy-subrc <> 0.
" raise exception.
endif.
Refer to: https://blogs.sap.com/2015/10/25/abap-740-quick-reference/
Regards,
Teshan