{"id":1635,"date":"2017-12-19T07:42:58","date_gmt":"2017-12-19T06:42:58","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=1635"},"modified":"2018-01-08T08:04:30","modified_gmt":"2018-01-08T07:04:30","slug":"abap-get-max-value-of-variable-type-as-packed-number","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=1635","title":{"rendered":"ABAP &#8211; Get max value of variable type as PACKED number"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"358\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=358\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" data-orig-size=\"44,50\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Picasa&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1365690880&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"SAP\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" class=\"alignleft size-full wp-image-358\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/SAP.jpg\" alt=\"\" width=\"44\" height=\"50\" \/>In this short code snippet I try to get maximum number of a variable typed as packed number and compare it against given amount.<\/p>\n<p>This code can be used to detect possible overflow and let program react accordingly.<\/p>\n<p><!--more--><\/p>\n<pre lang=\"&quot;abap\">CLASS lcl_amount_checks DEFINITION.\n  PUBLIC SECTION.\n    CLASS-METHODS:\n      check_max_amount\n        IMPORTING  iv_pack_length   TYPE i DEFAULT 7\n                   iv_pack_decimals TYPE i DEFAULT 2\n                   iv_amount        TYPE p\n        EXCEPTIONS amount_too_big.\nENDCLASS.\n\nCLASS lcl_amount_checks IMPLEMENTATION.\n  METHOD check_max_amount.\n    DATA:\n      lr_amount TYPE REF TO data.\n\n    CREATE DATA lr_amount \n      TYPE p LENGTH iv_pack_length \n      DECIMALS iv_pack_decimals.\n    ASSIGN lr_amount-&gt;* TO FIELD-SYMBOL(&lt;lv_amount&gt;).\n\n*   GET MAX amount for P(LENGTH,DECIMALS)\n    DATA(lr_max_value) = cl_abap_exceptional_values=&gt;get_max_value( \n                           &lt;lv_amount&gt; ).\n    ASSIGN lr_max_value-&gt;* TO &lt;lv_amount&gt;.\n\n    IF iv_amount GT &lt;lv_amount&gt;.      \n      MESSAGE 'Amount too large' type 'E' RAISING amount_too_big.\n    ENDIF.\n  ENDMETHOD.\nENDCLASS.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this short code snippet I try to get maximum number of a variable typed as packed number and compare it against given amount. This code can be used to detect possible overflow and let program react accordingly.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[16,9,484,389],"tags":[446],"class_list":["post-1635","post","type-post","status-publish","format-standard","hentry","category-abap","category-development","category-finance","category-sap","tag-abap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-qn","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1635"}],"version-history":[{"count":4,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1635\/revisions"}],"predecessor-version":[{"id":1641,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1635\/revisions\/1641"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}