ALV SALV, IDA Reporting Framework

  1. Designing a Report Interface using ALV
  2. SALV functions
    • Normal ALV Table Display
    • Adding Default PF STATUS in ALV
    • Adding Custom PF STATUS in ALV
    • Setting up Layout
    • Add Header (Top of page) & Footer (End of Page)
    • Changing Column settings
    • Apply Colors
    • Add & Handle Hotspot
    • Apply Aggregations
    • Apply Styles to Cell
    • Apply sorts
    • ICONs and Tooltips
    • Columns Specific Grouping
  3. SALV Hierarchical Table
    • Simple table display
    • Adding Default PF Status
    • Add Expand/Collapse Option
  4. IDA
    • Display Sales Order Details
    • Apply Filtering
    • Set the parameter
    • Example
  5. CL_ALV (old)
    • Edit mode
  6. CL_SALV_HIERSEQ_TABLE
  7. Links

Designing a Report Interface using SALV/IDA

SALV (easy to implement if we do not need CDS views) , IDA (optimized for HANA), ALV Classic ( editable; simple, hierarchy ).
  1. Decide on the source
  2. Decide on the look
    • ALV splitter 
  3. List fields 
  4. List functions
    • Variant
    • Layout
    • Format ( colors )
    • Field descriptions
    • Sorting
    • Filtering
    • Status with own buttons
    • Editabale fields
  5. Events
    • hotspot on field
    • double click
    • Toolbar with own buttons

SALV functions 

  • Simple 2D table display
    • CL_SALV_TABLE
  • Hierarchical ALV display
    • CL_SALV_HIERSEQU_TABLE
  • Tree ALV using class
    • CL_SALV_TREE

Normal ALV Table Display

ALV reference
DATA: lo_alv TYPE REF TO cl_salv_table.
DATA: lx_msg TYPE REF TO cx_salv_msg.

TRY. cl_salv_table=>factory( IMPORTING r_salv_table = o_alv CHANGING t_table = t_vbak ). CATCH cx_salv_msg INTO lx_msg. ENDTRY.
lo_alv->display( ).

Adding Default PF STATUS in ALV

DATA: lo_functions TYPE REF TO cl_salv_functions_list. 
lo_functions = co_alv->get_functions( ). 
lo_functions->set_default( abap_true ).

Adding Custom PF STATUS in ALV

We need to create a PF status with our own buttons as well as the ALV standard buttons. 
We will copy the PF-Status using of any standard SALV_DEMO report using the transaction SE41: 
Menu Painter. After Copying the PF-Status we can add our own buttons.

* Calling method to set the PF-Status
    lo_alv->set_screen_status(
      pfstatus      =  'SALV_CUSTOM'
      report        =  'XXXXXXXXXX'
      set_functions = lo_alv->c_functions_all ).

Setting up Layout

  DATA: lo_layout  TYPE REF TO cl_salv_layout,
               lf_variant TYPE slis_vari,
               ls_key    TYPE salv_s_layout_key.

    lo_layout = lo_alv->get_layout( ).

    ls_key-report = sy-repid.
    lo_layout->set_key( ls_key ).

    lo_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

    lf_variant = 'DEFAULT'.
    lo_layout->set_initial_layout( lf_variant ).

Add Header (Top of page) & Footer (End of Page)

  DATA: lo_header  TYPE REF TO cl_salv_form_layout_grid,
               lo_h_label TYPE REF TO cl_salv_form_label,
               lo_h_flow  TYPE REF TO cl_salv_form_layout_flow.
 
    CREATE OBJECT lo_header.

    lo_h_label = lo_header->create_label( row = 1 column = 1 ).
    lo_h_label->set_text( 'Header in Bold' ).
 
    lo_h_flow = lo_header->create_flow( row = 2  column = 1 ).
    lo_h_flow->create_text( text = 'This is text of flow' ).
 
    lo_h_flow = lo_header->create_flow( row = 3  column = 1 ).
    lo_h_flow->create_text( text = 'Number of Records in the output' ).
 
    lo_h_flow = lo_header->create_flow( row = 3  column = 2 ).
    lo_h_flow->create_text( text = 20 ).

Changing Column settings

    DATA: lo_cols TYPE REF TO cl_salv_columns.
                lo_cols = o_alv->get_columns( ).
 
    lo_cols->set_optimize( 'X' ).
 
    DATA: lo_column TYPE REF TO cl_salv_column.
 
    TRY.
        lo_column = lo_cols->get_column( 'KUNNR' ).
        lo_column->set_long_text( 'Sold-To Party' ).
        lo_column->set_medium_text( 'Sold-To Party' ).
        lo_column->set_short_text( 'Sold-To' ).
        lo_column->set_output_length( 10 ).
      CATCH cx_salv_not_found.                          "#EC NO_HANDLER
    ENDTRY. 

Add & Handle Hotspot

Apply Colors

    DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table,
                 lo_col_tab  TYPE REF TO cl_salv_column_table.
    DATA: ls_color TYPE lvc_s_colo.    " Colors strucutre

*   get Columns object
    lo_cols_tab = co_alv->get_columns( ).

    INCLUDE <color>.

*   Get ERDAT column & set the yellow Color fot it
    TRY.
        lo_col_tab ?= lo_cols_tab->get_column( 'ERDAT' ).
        ls_color-col = col_total.
        lo_col_tab->set_color( ls_color ).
      CATCH cx_salv_not_found.
    ENDTRY.
 
*.......Color for Specific Cell & Rows.................
*   Applying color on the 3rd Row and Column AUART
*   Applying color on the Entire 5th Row
 
    DATA: lt_s_color TYPE lvc_t_scol,
          ls_s_color TYPE lvc_s_scol,
          la_vbak    LIKE LINE OF ct_vbak,
          l_count    TYPE i.

    LOOP AT ct_vbak INTO la_vbak.
      l_count = l_count + 1.
      CASE l_count.
*       Apply RED color to the AUART Cell of the 3rd Row
        WHEN 3.
          ls_s_color-fname     = 'AUART'.
          ls_s_color-color-col = col_negative.
          ls_s_color-color-int = 0.
          ls_s_color-color-inv = 0.
          APPEND ls_s_color TO lt_s_color.
          CLEAR  ls_s_color.
 
*       Apply GREEN color to the entire row # 5
*         For entire row, we don't pass the Fieldname
        WHEN 5.
          ls_s_color-color-col = col_positive.
          ls_s_color-color-int = 0.
          ls_s_color-color-inv = 0.
          APPEND ls_s_color TO lt_s_color.
          CLEAR  ls_s_color.
      ENDCASE.

*     Modify that data back to the output table
      la_vbak-t_color = lt_s_color.
      MODIFY ct_vbak FROM la_vbak.
      CLEAR  la_vbak.
      CLEAR  lt_s_color.
    ENDLOOP.
 
*   We will set this COLOR table field name of the internal table to
*   COLUMNS tab reference for the specific colors
    TRY.
        lo_cols_tab->set_color_column( 'T_COLOR' ).
      CATCH cx_salv_data_error.                         "#EC NO_HANDLER
    ENDTRY.

Apply Aggregations

   DATA: lo_aggrs TYPE REF TO cl_salv_aggregations.
*
    lo_aggrs = co_alv->get_aggregations( ).
*
*   Add TOTAL for COLUMN NETWR
    TRY.
        CALL METHOD lo_aggrs->add_aggregation
          EXPORTING
            columnname  = 'NETWR'
            aggregation = if_salv_c_aggregation=>total.
      CATCH cx_salv_data_error .                        "#EC NO_HANDLER
      CATCH cx_salv_not_found .                         "#EC NO_HANDLER
      CATCH cx_salv_existing .                          "#EC NO_HANDLER
    ENDTRY.
*
*   Bring the total line to top
    lo_aggrs->set_aggregation_before_items( ).

Apply Filters
    DATA: lo_filters TYPE REF TO cl_salv_filters.
*
    lo_filters = co_alv->get_filters( ).
*
*   Set the filter for the column ERDAT
*     the filter criteria works exactly same as any
*     RANGE or SELECT-OPTIONS works.
    TRY.
        CALL METHOD lo_filters->add_filter
          EXPORTING
            columnname = 'ERDAT'
            sign       = 'I'
            option     = 'EQ'
            low        = '20091214'
*           high       =
            .
      CATCH cx_salv_not_found .                         "#EC NO_HANDLER
      CATCH cx_salv_data_error .                        "#EC NO_HANDLER
      CATCH cx_salv_existing .                          "#EC NO_HANDLER
    ENDTRY.

Apply Styles to Cell  

*...Get all the Columns
    DATA: lo_cols TYPE REF TO cl_salv_columns_table.
    lo_cols = o_alv->get_columns( ).
*
*   set the Column optimization
    lo_cols->set_optimize( 'X' ).
 
*   Set the Cell Type
    TRY.
        lo_cols->set_cell_type_column( 'I_CELLTYPE' ).
      CATCH cx_salv_data_error.                         "#EC NO_HANDLER
    ENDTRY.                     "

Apply sorts

    DATA: lo_sort TYPE REF TO cl_salv_sorts.
*
*   get Sort object
    lo_sort = co_alv->get_sorts( ).
*
*   Set the SORT on the AUART with Subtotal
    TRY.
        CALL METHOD lo_sort->add_sort
          EXPORTING
            columnname = 'AUART'
            subtotal   = if_salv_c_bool_sap=>true.
      CATCH cx_salv_not_found .                         "#EC NO_HANDLER
      CATCH cx_salv_existing .                          "#EC NO_HANDLER
      CATCH cx_salv_data_error .                        "#EC NO_HANDLER
    ENDTRY.
*
  ENDMETHOD.                    "set_sorts
*
  METHOD set_aggregations.
*
    DATA: lo_aggrs TYPE REF TO cl_salv_aggregations.
*
    lo_aggrs = co_alv->get_aggregations( ).
*
*   Add TOTAL for COLUMN NETWR
    TRY.
        CALL METHOD lo_aggrs->add_aggregation
          EXPORTING
            columnname  = 'NETWR'
            aggregation = if_salv_c_aggregation=>total.
      CATCH cx_salv_data_error .                        "#EC NO_HANDLER
      CATCH cx_salv_not_found .                         "#EC NO_HANDLER
      CATCH cx_salv_existing .   

ICONs and Tooltips

 DATA: lo_tooltips             TYPE REF TO cl_salv_tooltips,
       lv_value                TYPE lvc_value.

*...Tooltips
    lo_functional_settings = o_salv->get_functional_settings( ).
    lo_tooltips = lo_functional_settings->get_tooltips( ).
    TRY.
        lv_value = icon_green_light.
        lo_tooltips->add_tooltip(
          TYPE    = cl_salv_tooltip=>c_type_icon
          VALUE   = lv_value
          tooltip = 'Everything is Processed' ).            "#EC NOTEXT
      CATCH cx_salv_existing.                           "#EC NO_HANDLER
    ENDTRY.
    TRY.
        lv_value = icon_yellow_light.
        lo_tooltips->add_tooltip(
          TYPE    = cl_salv_tooltip=>c_type_icon
          VALUE   = lv_value
          tooltip = 'Partially processed' ).                "#EC NOTEXT
      CATCH cx_salv_existing.                           "#EC NO_HANDLER
    ENDTRY.
    TRY.
        lv_value = icon_red_light.
        lo_tooltips->add_tooltip(
          TYPE    = cl_salv_tooltip=>c_type_icon
          VALUE   = lv_value
          tooltip = 'Nothing Yet processed' ).              "#EC NOTEXT
      CATCH cx_salv_existing.                           "#EC NO_HANDLER
    ENDTRY.

 Columns Specific Grouping

*----
*   create the Groups
*----
    DATA: lo_functional_settings  TYPE REF TO cl_salv_functional_settings,
          lo_specific_groups      TYPE REF TO cl_salv_specific_groups,
          lv_text                 TYPE cl_salv_specific_groups=>y_text.
 
    lo_functional_settings = o_salv->get_functional_settings( ).
    lo_specific_groups = lo_functional_settings->get_specific_groups( ).
 
* Group for column which start with HSL, as group ID GRP1
    TRY.
        lv_text = 'HSL Amounts'.
        lo_specific_groups->add_specific_group( ID   = 'GRP1'
                                                text = lv_text ).
      CATCH cx_salv_existing.                           "#EC NO_HANDLER
    ENDTRY.
* Group for column which start with TSL, as group ID GRP2
    TRY.
        lv_text = 'TSL Amounts'.
        lo_specific_groups->add_specific_group( ID   = 'GRP2'
                                                text = lv_text ).
      CATCH cx_salv_existing.                           "#EC NO_HANDLER
    ENDTRY.
 
 
*----
*   Assign the group to columns
*----
    DATA: lo_columns  TYPE REF TO cl_salv_columns_table,
          lo_column   TYPE REF TO cl_salv_column_list,
          lt_cols     TYPE        salv_t_column_ref,
          ls_cols     LIKE LINE OF lt_cols.
 
 
    lo_columns = o_salv->get_columns( ).
    lt_cols    = lo_columns->get( ).
    TRY.
        lo_column ?= lo_columns->get_column( 'MANDT' ).
        lo_column->set_technical( if_salv_c_bool_sap=>true ).
      CATCH cx_salv_not_found.                          "#EC NO_HANDLER
    ENDTRY.
 
    LOOP AT lt_cols INTO ls_cols.
      lo_column ?= ls_cols-r_column.    "Narrow casting
      CASE ls_cols-columnname+0(3).
" GRP1 to HSL columns
        WHEN 'HSL'.
          lo_column->set_specific_group( ID = 'GRP1' ).
          lo_column->set_visible( " ).
" GRP2 to TSL columns
        WHEN 'TSL'.
          lo_column->set_specific_group( ID = 'GRP2' ).
          lo_column->set_visible( " ).
      ENDCASE.
    ENDLOOP.
 
 
  ENDMETHOD.                    "set_column_specific_group

SALV Hierarchical Table 

Simple table display

 DATA: lx_data_err   TYPE REF TO cx_salv_data_error,
              lx_not_found  TYPE REF TO cx_salv_not_found.
 DATA: lt_bind TYPE salv_t_hierseq_binding,
              la_bind LIKE LINE OF lt_bind.
 
    la_bind-master = 'VBELN'.     
    la_bind-slave  = 'VBELN'.    
    APPEND la_bind TO lt_bind.
 
    TRY.
        CALL METHOD cl_salv_hierseq_table=>factory
          EXPORTING
            t_binding_level1_level2 = lt_bind
          IMPORTING
            r_hierseq               = o_hs_alv
          CHANGING
            t_table_level1          = t_vbak
            t_table_level2          = t_vbap.
      CATCH cx_salv_data_error INTO lx_data_err.
      CATCH cx_salv_not_found  INTO lx_not_found.
    ENDTRY.

o_hs_alv->display( )

Adding Default PF Status

DATA: lo_functions TYPE REF TO cl_salv_functions_list. 
 lo_functions = lo_hs_alv->get_functions( ). 
 lo_functions->set_all( abap_true ).

Add Expand/Collapse Option

    DATA:
      lo_columns TYPE REF TO cl_salv_columns_hierseq.
*
*   Get the Columns of the Master
    TRY.
        lo_columns = co_hs_alv->get_columns( 1 ).
      CATCH cx_salv_not_found.
    ENDTRY.
*
*   set expand column
    TRY.
        lo_columns->set_expand_column( 'EXPAND' ).
      CATCH cx_salv_data_error.                         "#EC NO_HANDLER
    ENDTRY.
*
    DATA: lo_level TYPE REF TO cl_salv_hierseq_level.
*
*   Set items expanded by default
    TRY.
        lo_level = co_hs_alv->get_level( 1 ).
        lo_level->set_items_expanded( ).
      CATCH cx_salv_not_found.
    ENDTRY.

IDA

Tables

Example#1: Display Sales Order Details (table)


Check DB Capabilities
CHECK cl_salv_gui_table_ida=>db_capabilities( )->is_table_supported( iv_ddic_table_name = ‘VBAK’).

Create IDA
DATA(o_ida) = cl_salv_gui_table_ida=>create( iv_table_name = ‘VBAK’ ).
or: cl_salv_gui_table_ida=>create_for_cds_view(`Z_Invoice_Items`)->fullscreen( )->display( ).

Set Maximum Rows Recommended
IF cl_salv_gui_table_ida=>db_capabilities( )->is_max_rows_recommended( ).
o_ida->set_maximum_number_of_rows( iv_number_of_rows = 2000 ).
ENDIF.

Display
o_ida->fullscreen( )->display( ).

Example#2: Apply Filtering

data(lo_selection) = new cl_salv_range_tab_collector( ).
lo_selection->add_ranges_for_name( iv_name = 'MATERIAL'
it_ranges = selection->selection-bom-material ).

lo_selection->add_ranges_for_name( iv_name = 'PLANT'
it_ranges = selection->selection-bom-plant ).

lo_selection->get_collected_ranges( IMPORTING et_named_ranges = DATA(lt_named_ranges) ).

lo_ida->set_select_options( it_ranes = lt_named_ranges ).

*4... Build conditions
 lo_condition_factory = lo_alv_display->condition_factory( ).
 lo_additional_condition = lo_condition_factory->equals( name = 'CATEGORY'
                                                         value = p_prdctg ).

*5... Set select options and conditions
lo_alv_display->set_select_options( it_ranges    = lt_select_options
                                    io_condition = lo_additional_condition )

Example #3 Set the parameter

lo_ida->set_view_parameters( it_parameters = VALUE #( name = 'P_KEYDATE' value = selection->selection-bom-key_date ) )

ALV Display Setting


CDS View

Handling Large Internal Tables with CL_SALV_GUI_TABLE_IDA( integrated data access )
..more than 100,000 rows of data.
  • Create a CDS view 
  • Call the function 
  • Set additional settings










Example...
** Start of Selection.
START-OF-SELECTION.

  TRY.
** Create an Object to call the CDS View name
      go_alv = cl_salv_gui_table_ida=>create_for_cds_view( iv_cds_view_name = ‘ZCDS_TEST_FLIGHT’ ).

** To Add the input values to the view
      DATA(go_range) = NEW cl_salv_range_tab_collector( ).

** To get the parameter value, make them as Range table
      IF p_carrid IS NOT INITIAL.
        gt_r_carrid = VALUE #(
                             ( sign = ‘I’ option = ‘EQ’ low = p_carrid ) ).

** Add the parameter to the ranges.
        go_range->add_ranges_for_name( EXPORTING
                                       iv_name = ‘FLIGHT_ID’
                                       it_ranges = gt_r_carrid ).
      ENDIF.
** Add the Select Options to the ranges:
      go_range->add_ranges_for_name( EXPORTING
                                     iv_name = ‘CONN_ID’
                                     it_ranges = so_conid[] ).
** Collect all the ranges.
      go_range->get_collected_ranges( IMPORTING
                                      et_named_ranges = DATA(gt_ranges) ).

*** Condition Factory to set the where condition.
*      go_cond = go_cond_fact->equals( name = ‘FLIGHT_ID’ value = gt_r_carrid )->AND(
*                go_cond_fact->equals( name = ‘CONN_ID’ value = so_conid ) ).

** Set the Ranges to IDA ALV
      go_alv->set_select_options( EXPORTING
*                                  io_condition = go_cond
                                  it_ranges = gt_ranges ).

    CATCH cx_root.
  ENDTRY.

END-OF-SELECTION.
** activate full Screen Mode
  DATA(go_fullscreen) = go_alv->fullscreen( ).

** Display ALV
  go_fullscreen->display( ).

CL_ALV (old)

Steps to change the fieldcatalog after first display

  1. Trigger the PAI using pushbutton or some other manner.
  2. Now for this triggered function code get the existing fieldcatalog using the method get_frontend_fieldcatalog.
  3. Make the required modification to the fieldcatlog.
  4. Now in order to reflect these changes to the ALV grid make use of the method set_frontend_fieldcatalog.
  5. Call the method refresh_table_display of class CL_GUI_ALV_GRID to refresh the ALV display so as to show the modifications done to the ALV grid.
The ALV layout can be changed in a similar manner using the get and set methods meant for layout.

 

Other 

Pop-up ALV

  DATAlx_alv_compare TYPE REF TO cl_salv_table,
          lx_functions   TYPE REF TO cl_salv_functions_list.

    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table lx_alv_compare
          CHANGING
            t_table      lt_comparison_output[] ).

      CATCH cx_salv_msg.
    ENDTRY.


    lx_functions lx_alv_compare->get_functions).
    lx_functions->set_all'X' ).

    IF lx_alv_compare IS BOUND.

      lx_alv_compare->set_screen_popup(
         start_column 25
         end_column  100
         start_line  6
         ).

      lx_alv_compare->display).

    ENDIF.
  ENDIF.


Hier SALV

Data declaration

DATA: go_hs_alv TYPE REF TO cl_salv_hierseq_table.
DATA: go_functions TYPE REF TO cl_salv_functions_list.
DATA: go_layout TYPE REF TO cl_salv_layout.
DATA: gx_data_err TYPE REF TO cx_salv_data_error,
            gx_not_found TYPE REF TO cx_salv_not_found.

DATA: gt_bind TYPE salv_t_hierseq_binding,
            gs_bind LIKE LINE OF gt_bind.

DATA: go_columns TYPE REF TO cl_salv_columns_hierseq,
            go_column TYPE REF TO cl_salv_column_hierseq.

DATA: go_level TYPE REF TO cl_salv_hierseq_level.

DATA: gv_variant TYPE slis_vari,
            gs_key TYPE salv_s_layout_key.

DATA: go_selections TYPE REF TO cl_salv_selections.

DATA: gt_columns TYPE salv_t_column.
DATA: gt_rows TYPE salv_t_row.

DATA: gs_cell TYPE salv_s_cell.

In the head
ICON 1 Types ICON_D
EXPAND 1 Types CHAR1


Display

 IF gt_head IS NOT INITIAL.
    gs_bind-master 'DOCNUM'.
    gs_bind-slave  'DOCNUM'.
    APPEND gs_bind TO gt_bind.

    TRY.
        CALL METHOD cl_salv_hierseq_table=>factory
          EXPORTING
            t_binding_level1_level2 gt_bind
          IMPORTING
            r_hierseq               go_hs_alv
          CHANGING
            t_table_level1          gt_head
            t_table_level2          gt_item.
      CATCH cx_salv_data_error INTO gx_data_err.
      CATCH cx_salv_not_found  INTO gx_not_found.
    ENDTRY.

    lcl_salv_formatter=>add_format_stylesCHANGING co_hs_alv go_hs_alv ).

    go_hs_alv->display).

  ENDIF.

Functions

CLASS lcl_salv_formatter DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: set_expand CHANGING co_hs_alv TYPE REF TO cl_salv_hierseq_table,
             set_hotspots CHANGING co_hs_alv TYPE REF TO cl_salv_hierseq_table,
             set_selection_rule CHANGING co_hs_alv TYPE REF TO cl_salv_hierseq_table,
             set_layout CHANGING co_hs_alv TYPE REF TO cl_salv_hierseq_table,
             add_format_styles CHANGING co_hs_alv TYPE REF TO cl_salv_hierseq_table,
             set_events,
             set_icon,
             set_color CHANGING co_hs_alv TYPE REF TO cl_salv_hierseq_table,
             set_status CHANGING co_hs_alv TYPE REF TO cl_salv_hierseq_table,
             on_link_click FOR EVENT link_click OF cl_salv_events_hierseq IMPORTING row column level.
ENDCLASS.                    "lcl_salv_formatter DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_salv_formatter IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_salv_formatter IMPLEMENTATION.
  METHOD set_icon.
    FIELD-SYMBOLS: <ls_head> LIKE LINE OF gt_head.
    LOOP AT gt_head ASSIGNING <ls_head>.
      CASE <ls_head>-status.
        WHEN '51'.
          <ls_head>-icon     = icon_red_light  .
        WHEN '52' OR '64'.
          <ls_head>-icon     = icon_yellow_light.
        WHEN '53'  .
          <ls_head>-icon     =  icon_green_light .
        WHEN '68'.
          <ls_head>-icon     =  icon_delete.
        WHEN OTHERS.
      ENDCASE.
    ENDLOOP.
  ENDMETHOD.                    "set_icon
  METHOD set_color.
    DATA:   lo_columns TYPE REF TO cl_salv_columns_hierseq,
            ls_color   TYPE lvc_s_colo,
            lo_level   TYPE REF TO cl_salv_hierseq_level,
            lo_column  TYPE REF TO cl_salv_column_hierseq.

    ls_color-col = 4.
    ls_color-int = 1.

    lo_columns = co_hs_alv->get_columns( level = 2 ).
    lo_column ?= lo_columns->get_column( 'DOCNUM' ).
    lo_column->set_color( ls_color ).

  ENDMETHOD.                    "set_color
  METHOD set_status.
    co_hs_alv->set_screen_status(  pfstatus   =  'SALV_STANDARD'
                                   report     =  sy-repid ).
  ENDMETHOD.                    "set_status
  METHOD set_events.
    DATA:  lo_events TYPE REF TO cl_salv_events_hierseq.
    lo_events = go_hs_alv->get_event( ).
    SET HANDLER on_link_click FOR lo_events.
    SET HANDLER lcl_handle_events=>on_user_command FOR lo_events.


  ENDMETHOD.                    "set_events
  METHOD on_link_click.

    DATA: ls_head LIKE LINE OF gt_head,
          lv_idoc TYPE edi_docnum,
          lv_vbeln TYPE vbeln,

          ls_accounting TYPE  wb2_bkpf.

    CASE level.
      WHEN 1.
        READ TABLE gt_head INTO ls_head INDEX row.
        CASE column.
          WHEN 'BELNR'.
            SET PARAMETER ID 'BLN' FIELD ls_head-belnr.
            SET PARAMETER ID 'BUK' FIELD ls_head-bukrs.
            SET PARAMETER ID 'GJR' FIELD ls_head-gjahr.
            CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
          WHEN 'DOCNUM'.
            lv_idoc = ls_head-docnum.
            IF lv_idoc IS NOT INITIAL.
              SUBMIT idoc_tree_control WITH docnum =  lv_idoc AND RETURN.
            ENDIF.
          WHEN 'PUR_ORDER'.
            SELECT SINGLE vbak~vbeln INTO lv_vbeln
              FROM vbak
              INNER JOIN vbap ON vbak~vbeln = vbap~vbeln
              WHERE bstnk = ls_head-pur_order AND vbap~abgru EQ ''.
            SET PARAMETER ID 'AUN' FIELD lv_vbeln.
            CALL TRANSACTION 'VA33' AND SKIP FIRST SCREEN.
          WHEN OTHERS.
        ENDCASE.

      WHEN 2.

    ENDCASE.

  ENDMETHOD.                    "on_click
  METHOD add_format_styles.
    CALL METHOD set_expand
      CHANGING
        co_hs_alv = co_hs_alv.
    CALL METHOD set_hotspots
      CHANGING
        co_hs_alv = co_hs_alv.
    CALL METHOD set_selection_rule
      CHANGING
        co_hs_alv = co_hs_alv.
    CALL METHOD set_layout
      CHANGING
        co_hs_alv = co_hs_alv.

    CALL METHOD set_status
      CHANGING
        co_hs_alv = co_hs_alv.

    CALL METHOD set_color
      CHANGING
        co_hs_alv = co_hs_alv.

    set_icon( ).

    set_events( ).

  ENDMETHOD.                    "add_format_styles
  METHOD set_selection_rule.
    go_selections = co_hs_alv->get_selections( level = 1 ).
    go_selections->set_selection_mode( if_salv_c_selection_mode=>single ).

  ENDMETHOD.                    "set_selection_rule
  METHOD set_hotspots.
    TRY.
        go_column ?= go_columns->get_column( 'BELNR' ).
        go_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
        go_column->set_icon( if_salv_c_bool_sap=>true ).
      CATCH cx_salv_not_found.                          "#EC NO_HANDLER
    ENDTRY.

    TRY.
        go_column ?= go_columns->get_column( 'DOCNUM' ).
        go_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
        go_column->set_icon( if_salv_c_bool_sap=>true ).
      CATCH cx_salv_not_found.                          "#EC NO_HANDLER
    ENDTRY.
    TRY.
        go_column ?= go_columns->get_column( 'PUR_ORDER' ).
        go_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
        go_column->set_icon( if_salv_c_bool_sap=>true ).
      CATCH cx_salv_not_found.                          "#EC NO_HANDLER
    ENDTRY.

  ENDMETHOD.                    "set_hotspots
  METHOD set_layout.
    DATA:lo_display_settings TYPE REF TO cl_salv_display_settings.



    go_functions = go_hs_alv->get_functions( ).
    go_functions->set_all( abap_true ).

    go_layout = co_hs_alv->get_layout( ).
    gs_key-report = sy-repid.
    go_layout->set_key( gs_key ).
    go_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

    go_layout->set_initial_layout( 'DEFAULT' ).

    TRY.
        go_columns = go_hs_alv->get_columns( 2 ).
      CATCH cx_salv_not_found.
    ENDTRY.

    go_columns->set_optimize( abap_true ).

    TRY.
        go_columns = co_hs_alv->get_columns( 1 ).
      CATCH cx_salv_not_found.
    ENDTRY.

    go_columns->set_optimize( abap_true ).

    "Get display_settings class object
    lo_display_settings = go_hs_alv->get_display_settings( ).

    "Set vertical line
    lo_display_settings->set_vertical_lines( abap_true ).
    "Set horizontal line
    lo_display_settings->set_horizontal_lines( abap_true ).



  ENDMETHOD.                    "set_layout
  METHOD set_expand.
    TRY.
        go_columns = co_hs_alv->get_columns( 1 ).
      CATCH cx_salv_not_found.
    ENDTRY.

    TRY.
        go_columns->set_expand_column( 'EXPAND' ).
      CATCH cx_salv_data_error.                         "#EC NO_HANDLER
    ENDTRY.

    TRY.
        go_level = go_hs_alv->get_level( 1 ).
        go_level->set_items_expanded( ).
      CATCH cx_salv_not_found.
    ENDTRY.
  ENDMETHOD.                    "set_expand
ENDCLASS.                    "lcl_salv_formatter IMPLEMENTATION

Links

https://sapyard.com/alv-with-an-editable-row/



Comments