{"id":2604,"date":"2017-05-23T12:27:14","date_gmt":"2017-05-23T06:27:14","guid":{"rendered":"http:\/\/sdn.kz\/?p=2604"},"modified":"2017-05-23T12:27:14","modified_gmt":"2017-05-23T06:27:14","slug":"error-handling-when-calling-other-system-using-rfc","status":"publish","type":"post","link":"https:\/\/entropii.net\/2017\/05\/23\/error-handling-when-calling-other-system-using-rfc\/","title":{"rendered":"Error handling when calling other system using RFC"},"content":{"rendered":"<p><strong>Preparation<\/strong><\/p>\n<p>You have configured outbound connection and started to write code.<\/p>\n<p><strong>Iteration 1<\/strong><\/p>\n<blockquote>\n<p><font face=\"Courier New\">CALL FUNCTION &#8216;RFC_PING&#8217; DESTINATION &#8216;DUMMY&#8217;.<\/font><\/p>\n<\/blockquote>\n<p>Looks fine enough. But if you make mistake or connection is temporarily down or happens something else, you will get short dumps CALL_FUNCTION_REMOTE_ERROR,&#160; CALL_FUNCTION_NO_DEST or CALL_FUNCTION_OPEN_ERROR etc.<\/p>\n<p>You should always avoid short dumps in common environment.<\/p>\n<p><!--more--><\/p>\n<p>&#160;<\/p>\n<p><strong>Iteration 2<\/strong><\/p>\n<p>When you use <strong>CALL FUNCTION \u2026 DESTINATION \u2026<\/strong> statement you should always add EXCEPTIONS section.<\/p>\n<blockquote>\n<p><font face=\"Courier New\">CALL FUNCTION &#8216;RFC_PING&#8217; DESTINATION &#8216;NONE&#8217;        <br \/>&#160; EXCEPTIONS         <br \/>&#160;&#160;&#160; communication_failure = 1         <br \/>&#160;&#160;&#160; system_failure&#160;&#160;&#160;&#160;&#160;&#160;&#160; = 2.<\/font><\/p>\n<\/blockquote>\n<p>These system exceptions are part of RFC concept and do not exist in FM implementation.<\/p>\n<p>Looks better.<\/p>\n<p>In most cases dev-team just checks <strong>sy-subrc<\/strong> and displays error with common message:<\/p>\n<blockquote>\n<p><font face=\"Courier New\">IF sy-subrc NE 0.        <br \/>&#160; MESSAGE e001(zzz). &quot;Connection error. Try again later         <br \/>ENDIF.<\/font><\/p>\n<\/blockquote>\n<p>You should get details. Why? Because it saves team\u2019s time.<\/p>\n<p>When user or support team member faces the indefinite message he will spent more time or\/and involve more people to identify the root cause. <\/p>\n<p>Also definite message error is very useful for bug reporting.<\/p>\n<p><strong>Iteration 3<\/strong><\/p>\n<p>To get text of error message you should add <strong>MESSAGE<\/strong> key word.<\/p>\n<blockquote>\n<p><font face=\"Courier New\">DATA:&#160; lv_msg TYPE char200.        <br \/>CLEAR lv_msg.         <br \/>CALL FUNCTION &#8216;RFC_PING&#8217; DESTINATION &#8216;NONE&#8217;         <br \/>&#160; EXCEPTIONS         <br \/>&#160;&#160;&#160; communication_failure = 1 MESSAGE lv_msg         <br \/>&#160;&#160;&#160; system_failure&#160;&#160;&#160;&#160;&#160;&#160;&#160; = 2 MESSAGE lv_msg.         <br \/>IF sy-subrc NE 0.         <br \/>&#160; WRITE: \/ sy-subrc, lv_msg.         <br \/>&#160; MESSAGE e001(zzz) with lv_msg. &quot;Connection error: &amp;1         <br \/>ENDIF.<\/font><\/p>\n<\/blockquote>\n<p>Is it best solution?<\/p>\n<p>No, if you use message-based error handling and logging, sometimes you will receive cropped message:<\/p>\n<blockquote>\n<p>Error when opening an RFC connection (CPIC-CALL: &#8216;<\/p>\n<\/blockquote>\n<p><strong>Iteration 4<\/strong><\/p>\n<p>For an easy solution just add substring manipulation:<\/p>\n<blockquote>\n<p><font face=\"Courier New\">MESSAGE i000(zzz)&#160; <br \/>&#160; WITH lv_msg(50)&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160; lv_msg+50(50)&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160; lv_msg+100(50)&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160; lv_msg+150(50). &quot;System error: &amp;1&amp;2&amp;3&amp;4<\/font><\/p>\n<\/blockquote>\n<p>Here is new error message:<\/p>\n<blockquote>\n<p>Error when opening an RFC connection (CPIC-CALL: &#8216;ThSAPOCMINIT&#8217;, communication rc: CM_RESOURCE_FAILURE_RETRY (cmRc=27).<\/p>\n<\/blockquote>\n<p>Some developers find this snippet ugly, but I have no problem with that.<\/p>\n<p><strong>Iteration 5<\/strong><\/p>\n<p>You can use structures instead:<\/p>\n<blockquote>\n<p><font face=\"Courier New\">DATA: BEGIN OF ls_msg,        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgv1 TYPE char50,         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgv2 TYPE char50,         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgv3 TYPE char50,         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgv4 TYPE char50,         <br \/>&#160;&#160;&#160;&#160;&#160; END OF ls_msg.         <br \/>CLEAR ls_msg.         <br \/>CALL FUNCTION &#8216;RFC_PING&#8217; DESTINATION &#8216;DUMMY&#8217;         <br \/>&#160; EXCEPTIONS         <br \/>&#160;&#160;&#160; communication_failure = 1 MESSAGE ls_msg         <br \/>&#160;&#160;&#160; system_failure&#160;&#160;&#160;&#160;&#160;&#160;&#160; = 2 MESSAGE ls_msg.         <br \/>IF sy-subrc NE 0.         <br \/>&#160; MESSAGE i000(zzz)         <br \/>&#160;&#160;&#160; WITH ls_msg-msgv1         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ls_msg-msgv2         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ls_msg-msgv3         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ls_msg-msgv4. &quot;System error: &amp;1&amp;2&amp;3&amp;4         <br \/>ENDIF.<\/font><\/p>\n<\/blockquote>\n<p>Verbose code or not?<\/p>\n<p>&#160;<\/p>\n<p>Thank you for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Preparation You have configured outbound connection and started to write code. Iteration 1 CALL FUNCTION &#8216;RFC_PING&#8217; DESTINATION &#8216;DUMMY&#8217;. Looks fine enough. But if you make mistake or connection is temporarily down or happens something else, you will get short dumps &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2604","post","type-post","status-publish","format-standard","hentry","category-abap"],"_links":{"self":[{"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/posts\/2604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/comments?post=2604"}],"version-history":[{"count":0,"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/posts\/2604\/revisions"}],"wp:attachment":[{"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/media?parent=2604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/categories?post=2604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entropii.net\/wp-json\/wp\/v2\/tags?post=2604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}