Handle and show SQL Exception show in popup message box in SAP ABAP

1. Delare a variable ( lo_exc). You can use any word. DATA lo_exc TYPE REF TO cx_root . 2. Use TRY and CATCH Syntax TRY. select single MATNRR from MARA INTO (varable) UP TO 1 ROWS. CATCH CX_SY_DYNAMIC_OSQL_SEMANTICS INTO lo_exc. MESSAGE lo_exc TYPE 'I' DISPLAY LIKE 'E'. ENDTRY. Note: This Exception ( CX_SY_DYNAMIC_OSQL_SEMANTICS ) return SQL Query Errors. Result: