{"id":1535,"date":"2016-07-15T20:34:03","date_gmt":"2016-07-15T19:34:03","guid":{"rendered":"http:\/\/oprsteny.cz\/?p=1535"},"modified":"2016-07-15T20:34:03","modified_gmt":"2016-07-15T19:34:03","slug":"abap-number-ranges-usage","status":"publish","type":"post","link":"https:\/\/oprsteny.cz\/?p=1535","title":{"rendered":"ABAP &#8211; Number ranges usage"},"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=\"SAP\" width=\"44\" height=\"50\" \/>\u00a0I wanted to have a tool for monitoring usage of internal number ranges in a\u00a0system (such tool\u00a0should\u00a0be used also as a backround job) which can alert a system administrator in case a number range is\u00a0reaching end of its interval.<!--more--><\/p>\n<p>It should be possible to explicitly list number ranges we are interested in (parameter <strong>s_object<\/strong>)<\/p>\n<p>I wanted to be able to set a threshold of usage in % dynamically (on selection screen) so I set it as an input parameter too (<strong>p_trshld<\/strong>);.<\/p>\n<p>It should also be possible to exclude some range when we are simply not\u00a0interested in it or it&#8217;s an &#8220;auto-rotating&#8221; number range (parameter <strong>s_excl<\/strong>)<\/p>\n<p>So the selection screen might look like the following:<\/p>\n<pre lang=\"abap\">DATA:\r\n  gv_nrobj       TYPE nrobj,\r\n  gv_exluded(18) TYPE c.\r\n\r\nSELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME.\r\n  SELECT-OPTIONS:\r\n            s_object  FOR gv_nrobj,\r\n            s_excl    FOR gv_exluded NO INTERVALS.\r\n  PARAMETERS: p_trshld  TYPE p DECIMALS 2 OBLIGATORY DEFAULT '90.00'.  \r\n\r\n********************************************\r\n*** HINTS FOR THE EXCLUDED NUMBER RANGES ***\r\n********************************************\r\n  SELECTION-SCREEN BEGIN OF LINE.\r\n    SELECTION-SCREEN COMMENT 1(75) s_hint.\r\n  SELECTION-SCREEN END OF LINE.\r\n\r\n  SELECTION-SCREEN BEGIN OF LINE.\r\n    SELECTION-SCREEN COMMENT 7(67) s_hint01.\r\n  SELECTION-SCREEN END OF LINE.\r\n\r\n  SELECTION-SCREEN BEGIN OF LINE.\r\n    SELECTION-SCREEN COMMENT 17(58) s_hint02.\r\n  SELECTION-SCREEN END OF LINE.\r\n\r\n  SELECTION-SCREEN BEGIN OF LINE.\r\n    SELECTION-SCREEN COMMENT 23(52) s_hint03.\r\n  SELECTION-SCREEN END OF LINE.\r\n\r\nSELECTION-SCREEN END OF BLOCK b01 WITH FRAME.<\/pre>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_01.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1536\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=1536\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_01.png\" data-orig-size=\"734,335\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Selection screen\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_01.png\" class=\"size-medium wp-image-1536 alignnone\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_01-300x137.png\" alt=\"Selection screen\" width=\"300\" height=\"137\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_01-300x137.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_01-500x228.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_01.png 734w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The output will be displayed on a screen 0100 where I created a PF_STATUS with the most common functions BACK, LEAVE and CANCEL.<\/p>\n<p>Events PBO and PAI of screen 0100 are handled in a local helper class<\/p>\n<pre lang=\"abap\">INITIALIZATION.\r\n  %_s_object_%_app_%-text = 'Number range object'.\r\n  %_p_trshld_%_app_%-text = 'Number range usage in %'.\r\n  %_s_excl_%_app_%-text   = 'Exclude number range'.\r\n  s_hint                  = 'Excluded Object: XXXXXXXXXXYYYYYYZZ'.\r\n  s_hint01                = 'X = Number Range'.\r\n  s_hint02                = 'Y = Sub Object'.\r\n  s_hint03                = 'Z = No.'.\r\n\r\nSTART-OF-SELECTION.\r\n  lcl_app=&gt;get_instance( )-&gt;execute( ).\r\n\r\nMODULE pbo_0100 OUTPUT.\r\n  lcl_app=&gt;get_instance( )-&gt;pbo_0100( ).\r\nENDMODULE.\r\n\r\nMODULE pai_0100 INPUT.\r\n  CASE sy-ucomm.\r\n    WHEN 'BACK' OR 'LEAVE' OR 'CANCEL'.\r\n      LEAVE TO SCREEN 0.\r\n  ENDCASE.\r\nENDMODULE.<\/pre>\n<p>Here follows the contents of the helper class where the most important is the GET_DATA method where the relevant data is selected (and filtered)<\/p>\n<pre lang=\"abap\">CLASS lcl_app DEFINITION CREATE PRIVATE.\r\n  PUBLIC SECTION.\r\n    CLASS-METHODS:\r\n      get_instance RETURNING VALUE(ro_instance) TYPE REF TO lcl_app.\r\n    METHODS:\r\n      execute,\r\n      pbo_0100.\r\nPRIVATE SECTION.\r\n  TYPES:\r\n    BEGIN OF ty_s_data,\r\n      object     TYPE nriv-object,\r\n      subobject  TYPE nriv-subobject,\r\n      nrrangenr  TYPE nriv-nrrangenr,\r\n      toyear     TYPE nriv-toyear,\r\n      fromnumber TYPE nriv-fromnumber,\r\n      tonumber   TYPE nriv-tonumber,\r\n      nrlevel    TYPE nriv-nrlevel,\r\n      txtshort   TYPE tnrot-txtshort,\r\n      usage(6)   TYPE c,\r\n    END OF ty_s_data,\r\n    ty_t_data TYPE TABLE OF ty_s_data WITH DEFAULT KEY.\r\n\r\n  CLASS-DATA:\r\n    mo_instance TYPE REF TO lcl_app.\r\n\r\n  DATA:\r\n    mt_data               TYPE ty_t_data,\r\n    mv_num_checked_ranges TYPE i,\r\n    mo_container          TYPE REF TO cl_gui_docking_container,\r\n    mo_grid               TYPE REF TO cl_gui_alv_grid.\r\n\r\n  METHODS:\r\n    get_data \r\n      RETURNING VALUE(rt_data) TYPE ty_t_data,\r\n    get_fcat_4_itab \r\n      IMPORTING it_table       TYPE ANY TABLE\r\n      RETURNING VALUE(rt_fcat) TYPE lvc_t_fcat,\r\n    display_alv.\r\n\r\nENDCLASS.\r\n\r\nCLASS lcl_app IMPLEMENTATION.\r\n\r\n  METHOD get_instance.\r\n    IF mo_instance IS INITIAL.\r\n      CREATE OBJECT mo_instance.\r\n    ENDIF.\r\n\r\n    ro_instance = mo_instance.\r\n  ENDMETHOD.\r\n\r\n  METHOD execute.\r\n    me-&gt;mt_data = me-&gt;get_data( ).\r\n\r\n    IF me-&gt;mv_num_checked_ranges = 0.\r\n      MESSAGE 'No interval shortage detected' TYPE 'S'.\r\n      LEAVE LIST-PROCESSING.\r\n    ENDIF.\r\n\r\n    CALL SCREEN 0100.\r\n  ENDMETHOD.\r\n\r\n  METHOD pbo_0100.\r\n    DATA:\r\n      lv_msg TYPE string.\r\n    \r\n    SET PF-STATUS 'PFSTATUS'.\r\n    SET TITLEBAR 'TITLEBAR'.\r\n\r\n    me-&gt;display_alv( ).\r\n\r\n    lv_msg = | Checked number ranges: { me-&gt;mv_num_checked_ranges }|.\r\n    MESSAGE lv_msg TYPE 'S'.\r\n  ENDMETHOD.\r\n\r\n  METHOD get_data.\r\n    SELECT r~object\r\n           r~subobject\r\n           r~nrrangenr\r\n           r~toyear\r\n           r~fromnumber\r\n           r~tonumber\r\n           r~nrlevel\r\n \r\n           t~txtshort\r\n    INTO CORRESPONDING FIELDS OF TABLE rt_data\r\n    FROM nriv AS r\r\n      LEFT JOIN tnrot AS t ON t~object = r~object\r\n                          AND t~langu  = sy-langu\r\n    WHERE r~object     IN s_object\r\n       AND r~externind EQ ' '.\r\n\r\n**********************************************************************\r\n*   FILTER DATA\r\n\r\n*   Remove excluded number ranges (given on selection screen\r\n    LOOP AT s_excl ASSIGNING FIELD-SYMBOL(&lt;ls_excl&gt;).\r\n\r\n      READ TABLE rt_data TRANSPORTING NO FIELDS\r\n        WITH KEY object    = &lt;ls_excl&gt;-low+0(10)\r\n                 subobject = &lt;ls_excl&gt;-low+10(6)\r\n                 nrrangenr = &lt;ls_excl&gt;-low+16(2).\r\n\r\n      IF sy-subrc = 0.\r\n        DELETE rt_data INDEX sy-tabix.\r\n      ENDIF.\r\n    ENDLOOP.\r\n\r\n*   Remove entries where TOYEAR is not initial \r\n*   and not equal to current year\r\n    DELETE rt_data \r\n      WHERE toyear IS NOT INITIAL \r\n        AND toyear &lt;&gt; sy-datum(4).\r\n\r\n*   Remove entries where NRLEVEL is INITIAL (number range not used yet)\r\n    DELETE rt_data WHERE nrlevel IS INITIAL.\r\n\r\n    me-&gt;mv_num_checked_ranges = lines( rt_data ).\r\n\r\n*   Compute usage in %\r\n    LOOP AT rt_data ASSIGNING FIELD-SYMBOL(&lt;ls_data&gt;).\r\n      &lt;ls_data&gt;-usage = ( &lt;ls_data&gt;-nrlevel  - &lt;ls_data&gt;-fromnumber ) \/\r\n                        ( &lt;ls_data&gt;-tonumber - &lt;ls_data&gt;-fromnumber ) *\r\n                        100.\r\n    ENDLOOP.\r\n\r\n*   Remove entries where usage is less than given treshold\r\n    DELETE rt_data WHERE used &lt; p_trshld.\r\n\r\n*   Sort data by range number name\r\n    SORT rt_data BY object.\r\n  ENDMETHOD.\r\n\r\n  METHOD display_alv.\r\n    IF me-&gt;mo_grid IS INITIAL.\r\n      CREATE OBJECT mo_container\r\n        EXPORTING\r\n          parent    = cl_gui_container=&gt;screen0\r\n          repid     = sy-repid\r\n          dynnr     = '0100'\r\n          side      = cl_gui_docking_container=&gt;dock_at_left\r\n          extension = 10000\r\n        EXCEPTIONS\r\n          cntl_error                  = 1\r\n          cntl_system_error           = 2\r\n          create_error                = 3\r\n          lifetime_error              = 4\r\n          lifetime_dynpro_dynpro_link = 5\r\n          OTHERS                      = 6.\r\n\r\n      IF sy-subrc &lt;&gt; 0.\r\n        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno\r\n          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.\r\n      ENDIF.\r\n\r\n      CREATE OBJECT mo_grid\r\n        EXPORTING\r\n          i_parent = me-&gt;mo_container\r\n        EXCEPTIONS\r\n          error_cntl_create = 1\r\n          error_cntl_init   = 2\r\n          error_cntl_link   = 3\r\n          error_dp_create   = 4\r\n          OTHERS            = 5.\r\n      IF sy-subrc &lt;&gt; 0.\r\n        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno\r\n          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.\r\n      ENDIF.\r\n\r\n      DATA(lt_fcat) = me-&gt;get_fcat_4_itab( me-&gt;mt_data ).\r\n\r\n      lt_fcat[ fieldname = 'USAGE' ]-scrtext_s = '%'.\r\n      lt_fcat[ fieldname = 'USAGE' ]-scrtext_m = 'Used %'.\r\n\r\n      mo_grid-&gt;set_table_for_first_display(\r\n        EXPORTING\r\n          i_save    = 'A'\r\n          i_default = 'X'\r\n        CHANGING\r\n          it_outtab       = me-&gt;mt_data\r\n          it_fieldcatalog = lt_fcat\r\n        EXCEPTIONS\r\n          invalid_parameter_combination = 1\r\n          program_error                 = 2\r\n          too_many_lines                = 3\r\n          OTHERS                        = 4\r\n      ).\r\n      IF sy-subrc &lt;&gt; 0.\r\n        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno\r\n          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.\r\n      ENDIF.\r\n    ELSE.\r\n      me-&gt;mo_grid-&gt;refresh_table_display( ).\r\n    ENDIF.\r\n  ENDMETHOD.\r\n\r\n  METHOD get_fcat_4_itab.\r\n    DATA: \r\n      lo_columns      TYPE REF TO cl_salv_columns_table,\r\n      lo_aggregations TYPE REF TO cl_salv_aggregations,\r\n      lo_salv_table   TYPE REF TO cl_salv_table,\r\n      lr_table        TYPE REF TO data.\r\n    FIELD-SYMBOLS:\r\n      &lt;table&gt; TYPE STANDARD TABLE.\r\n\r\n*   Create unprotected table from import data\r\n    CREATE DATA lr_table LIKE it_table.\r\n    ASSIGN lr_table-&gt;* TO &lt;table&gt;.\r\n\r\n*   New ALV Instance\r\n    TRY.\r\n        cl_salv_table=&gt;factory(\r\n          EXPORTING list_display = abap_false\r\n          IMPORTING r_salv_table = lo_salv_table\r\n          CHANGING t_table = &lt;table&gt;\r\n        ).\r\n      CATCH cx_salv_msg. \"#EC NO_HANDLER\r\n    ENDTRY.\r\n\r\n    lo_columns = lo_salv_table-&gt;get_columns( ).\r\n    lo_aggregations = lo_salv_table-&gt;get_aggregations( ).\r\n\r\n    rt_fcat = cl_salv_controller_metadata=&gt;get_lvc_fieldcatalog(\r\n      r_columns = lo_columns\r\n      r_aggregations = lo_aggregations\r\n    ).\r\n  ENDMETHOD.\r\nENDCLASS.<\/pre>\n<p><a href=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1537\" data-permalink=\"https:\/\/oprsteny.cz\/?attachment_id=1537\" data-orig-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02.png\" data-orig-size=\"1044,202\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Result screen\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02-1024x198.png\" class=\"alignleft size-medium wp-image-1537\" src=\"http:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02-300x58.png\" alt=\"Result screen\" width=\"300\" height=\"58\" srcset=\"https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02-300x58.png 300w, https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02-768x149.png 768w, https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02-1024x198.png 1024w, https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02-500x97.png 500w, https:\/\/oprsteny.cz\/wp-content\/uploads\/NUMBER_RANGE_USAGE_02.png 1044w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0I wanted to have a tool for monitoring usage of internal number ranges in a\u00a0system (such tool\u00a0should\u00a0be used also as a backround job) which can alert a system administrator in case a number range is\u00a0reaching end of its interval.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_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}},"categories":[16,233,9],"tags":[446,475,474],"class_list":["post-1535","post","type-post","status-publish","format-standard","hentry","category-abap","category-customizing","category-development","tag-abap","tag-monitoring","tag-number-ranges"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3nYbe-oL","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1535","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=1535"}],"version-history":[{"count":3,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1535\/revisions"}],"predecessor-version":[{"id":1540,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=\/wp\/v2\/posts\/1535\/revisions\/1540"}],"wp:attachment":[{"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oprsteny.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}