In the previous post I described the basic concepts of programming using SE91 messages
If you used to do OO programming your logic probably works on class-based exceptions.
In most of cases I would choose IF_T100_MESSAGE variant to explain the reason of the error (Rule #4)
Meanwhile, sometime you have a foreign code you’re not responsible to modify and this code raises an exception.
Now we speak about the case when you want to output the message immediately. To be abstract let’s just use cx_root example.
If you go the easiest way:
try. do_something( ). catch cx_root into data(lo_cx). message lo_cx->get_text( ) type 'I' . endtry.
you will get the popup:
but unfortunatelly F1 button won’t work here. Debugger on you, my friend.
But let’s jut imagine that we press F1 and have a documentation like this:
and when we click “Navigate to source” link we go directly to the source code when the exception has been raised:
Pretty cool, isn’t it?! =)
Let’s just see how many actions do we need to do this? Saying it before, i wanted to reuse standard SAP UI without own screen creation.
1. We need 3 SET/GET parameters.
Go to SE80.
Edit object (Shift+F5) -> Enhanced options -> SET/GET parameter ID -> type zcw_nav_prog -> Create (F5).
repeat these steps for zcw_nav_incl and zcw_nav_line parameters.
2. Go to SE38 and create a very simple program:
program zcw_navigate_to_source. parameters: p_prog type syrepid memory id zcw_nav_prog, p_incl type syrepid memory id zcw_nav_incl, p_line type num10 memory id zcw_nav_line. start-of-selection. /iwfnd/cl_sutil_moni=>get_instance( )->show_source( iv_program = p_prog " Source Program iv_include = p_incl " Source Include iv_line = conv #( p_line ) " Source Line iv_new_window = '' " New Window ).
I really hope you have this component. If not – you can find something similar in where-used-list for ‘RS_ACCESS_TOOL’ FM
3. Create ZCW_NAV_SRC transaction in SE93.
Choose report transaction and assign ZCW_NAVIGATE_TO_SOURCE report to it.
4. We need a real SE91 message.
Just create some message with the text &1&2&3&4. Remove self-explanatory flag and go to long text.
Put the cursor where you wish to place a link ->Insert menu -> Link
Choose “Link to transaction and skip first screen” as Document class, use the transaction from step 3.
“Name in Document” is the real text that you see on the screen like “Navigate to source”.
5. Now we’re ready to code.
try. do_something( ). catch cx_root into data(lo_cx). " get source code position lo_cx->get_source_position( importing program_name = data(lv_prog) " ABAP Program: Current Main Program include_name = data(lv_incl) source_line = data(lv_line) ). " it's not possible to store integer as parameter value data(lv_line_c) = conv num10( lv_line ). " export parameter values set parameter id 'ZCW_NAV_PROG' field lv_prog. set parameter id 'ZCW_NAV_INCL' field lv_incl. set parameter id 'ZCW_NAV_LINE' field lv_line_c. types: begin of message_ts , msgv1 type bal_s_msg-msgv1, msgv2 type bal_s_msg-msgv2, msgv3 type bal_s_msg-msgv3, msgv4 type bal_s_msg-msgv4, end of message_ts . " parse our string to message format data(ls_message) = conv message_ts( lo_cx->get_text( ) ). " Output, don't forget we always use static message definition " Put here message created in Step 4. message id 'ZCW_COMMON' type 'I' number 124 with ls_message-msgv1 ls_messagemsgv2 ls_message-msgv3 ls_message-msgv4. endtry.
That’s it! What I actually did – I put this handling logic into a minimalistic method ZCL_MSG=>CX( lo_cx ) and actively use it in my code.
I hope you enjoyed it.