Skip to end of metadata
Go to start of metadata

REPORT  zrin_dataranges_check NO STANDARD PAGE HEADING.

TYPES: BEGIN OF x_tnro,
         object TYPE nrobj,
         txtshort TYPE nreltxttxt,
         txt TYPE nreltxtlng,
         code TYPE nrcode,
         percentage TYPE nrperc,
         buffer TYPE nrbuffer,
         noivbuffer TYPE nrivbuffer,
         nrrangenr TYPE nrnr,
         fromnumber TYPE nrfrom,
         tonumber TYPE nrto,
         nrlevel TYPE nrlevel,
         externind TYPE nrind,
        END OF x_tnro.

CLASS lcl_handle_events DEFINITION DEFERRED.

DATA: gt_tnro TYPE TABLE OF x_tnro,
       gw_tnro TYPE x_tnro.

DATA: gcl_columns TYPE REF TO cl_salv_columns,
       gcl_column  TYPE REF TO cl_salv_column_table,
       gcl_alvtab_events TYPE REF TO cl_salv_events_table.

DATA: gv_header_content TYPE REF TO cl_salv_form_element.
DATA: gv_rep_date TYPE sydatum VALUE '31129999',
       wa_tnro TYPE tnro,
       gv_count TYPE i,
       gv_mess TYPE string,
       gc_true TYPE sap_bool VALUE 'X'.

DATA: gcx_msgtab TYPE REF TO cx_salv_msg,
       gcx_salv_not_found TYPE REF TO cx_salv_not_found,
       gcl_alvtab TYPE REF TO cl_salv_table.

DATA: gcl_events  TYPE REF TO lcl_handle_events.
*----------------------------------------------------------------------*
*       CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
   PUBLIC SECTION.
     METHODS: on_link_click FOR EVENT link_click OF cl_salv_events_table
                             IMPORTING row column.
ENDCLASS.                    "lcl_handle_events DEFINITION
**---------------------------------------------------------------------
**       CLASS lcl_handle_events IMPLEMENTATION
**---------------------------------------------------------------------
*
CLASS lcl_handle_events IMPLEMENTATION.
   METHOD on_link_click.          "on_LINK_CLICK
     READ TABLE gt_tnro INTO gw_tnro INDEX row.
     IF sy-subrc EQ 0.
       CALL TRANSACTION gw_tnro-code.
     ENDIF.
   ENDMETHOD.                     "on_LINK_CLICK
ENDCLASS.                    "lcl_handle_events IMPLEMENTATION 

****************************************************
*    SELECTION-SCREEN DEFINITION
****************************************************
SELECTION-SCREEN BEGIN OF BLOCK blk01 WITH FRAME TITLE text-t01 .
SELECT-OPTIONS: s_nrange FOR wa_tnro-object OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk01.

****************************************************
*    AT SELECTION-SCREEN
****************************************************
AT SELECTION-SCREEN.

****************************************************
*    START-OF-SELECTION
****************************************************
START-OF-SELECTION.

*Fetch Number Ranges details
   SELECT a~object
          b~txt
          b~txtshort
          a~code
          a~percentage
          a~buffer
          a~noivbuffer
          c~nrrangenr
          c~fromnumber
          c~tonumber
          c~nrlevel
          c~externind
     INTO CORRESPONDING FIELDS OF TABLE  gt_tnro
     FROM ( ( tnro AS a INNER JOIN tnrot AS b ON b~langu = sy-langu
                                             AND b~object = a~object )
              LEFT JOIN nriv AS c ON c~object = a~object )
     WHERE a~object IN s_nrange.

   IF sy-subrc EQ 0.

     "Get Records Count and Sort by Object name
     DESCRIBE TABLE gt_tnro LINES gv_count.
     SORT gt_tnro BY object.

     TRY.
         cl_salv_table=>factory(
           IMPORTING
             r_salv_table = gcl_alvtab
           CHANGING
             t_table      = gt_tnro ).

*Activate ALV generic Functions
         gcl_alvtab->set_screen_status(
           pfstatus      =  'ZALV_STANDARD'
           report        =  sy-repid
           set_functions = gcl_alvtab->c_functions_all ).

*Optimize Columns
         gcl_columns = gcl_alvtab->get_columns( ).
         gcl_columns->set_optimize( gc_true ).

*Set hotspot column
         TRY.
             gcl_column ?= gcl_columns->get_column( 'CODE' ).
             gcl_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
           CATCH cx_salv_not_found INTO gcx_salv_not_found.
             gv_mess = gcx_salv_not_found->get_text( ).
             MESSAGE gv_mess TYPE 'E'.
         ENDTRY.

*Get the events of cl_salv_table
         gcl_alvtab_events = gcl_alvtab->get_event( ).

*Create Eventhandler
         CREATE OBJECT gcl_events.
*Set Eventhandler to the object of interest
         SET HANDLER gcl_events->on_link_click FOR gcl_alvtab_events.

*Build Header Data for ALV
         PERFORM built_header CHANGING gv_header_content.
         gcl_alvtab->set_top_of_list( gv_header_content ).

       CATCH cx_salv_msg INTO gcx_msgtab.
         gv_mess = gcx_msgtab->get_text( ).
         MESSAGE gv_mess TYPE 'E'.
     ENDTRY.

   ENDIF.

****************************************************
*    END-OF-SELECTION
****************************************************
END-OF-SELECTION.

   TRY.
*Display Table
       gcl_alvtab->display( ).
     CATCH cx_salv_msg INTO gcx_msgtab.
   ENDTRY.

*&---------------------------------------------------------------------*
*&      Form  built_header
*----------------------------------------------------------------------*
FORM built_header CHANGING cr_content TYPE REF TO cl_salv_form_element.

   DATA: lcl_grid   TYPE REF TO cl_salv_form_layout_grid,
         lcl_grid_1 TYPE REF TO cl_salv_form_layout_grid,
         lcl_label  TYPE REF TO cl_salv_form_label,
         lcl_text   TYPE REF TO cl_salv_form_text,
         lv_text    TYPE string.

*Build Header Grid
   CREATE OBJECT lcl_grid.

*Create header info
   lv_text = 'Number Ranges' .
   lcl_grid->create_header_information(
     row    = 1
     column = 1
     text    = lv_text
     tooltip = lv_text ).

*Add Row
   lcl_grid->add_row( ).

*Create next grid
   lcl_grid_1 = lcl_grid->create_grid(
                 row    = 4
                 column = 1 ).

*Create Records Data
   lcl_label = lcl_grid_1->create_label(
     row     = 1
     column  = 1
     text    = text-t02
     tooltip = text-t02 ).
   lcl_text = lcl_grid_1->create_text(
     row     = 1
     column  = 2
     text    = gv_count
     tooltip = gv_count ).

   lcl_label->set_label_for( lcl_text ).

*Create Date data
   lcl_label = lcl_grid_1->create_label(
     row    = 2
     column = 1
     text    = text-t03
     tooltip = text-t03  ).

   lcl_text = lcl_grid_1->create_text(
     row    = 2
     column = 2
     text    = sy-datum
     tooltip = sy-datum ).

   lcl_label->set_label_for( lcl_text ).

*Create User data
   lcl_label = lcl_grid_1->create_label(
     row    = 3
     column = 1
     text    = text-t04
     tooltip = text-t04 ).

   lcl_text = lcl_grid_1->create_text(
     row    = 3
     column = 2
     text    = sy-uname
     tooltip = sy-uname ).

   lcl_label->set_label_for( lcl_text ).

   cr_content = lcl_grid.
ENDFORM.                    " built_header