ABAP - Developing Interactive ALV Report using OOABAP

1. Have a field designated for the color.

For eg:

TYPES:
    BEGIN OF tw_xresult,
            text      TYPE zsdtype,
            vbeln    TYPE vbeln,
            ernam   TYPE ernam,
            persrb   TYPE zpers_resp,
            erdat     TYPE erdat,
            vkorg     TYPE vkorg,
            vtweg    TYPE vtweg,
            spart      TYPE spart,
            vkbur     TYPE vkbur,
            vkgrp     TYPE vkgrp,
            vbtyp     TYPE vbtyp,
            fehler     TYPE znumber,
            netwr     TYPE netwr_ak,
            uvall       TYPE uvall,
            uvvlk      TYPE uvvlk,
            uvfak     TYPE uvfak,
            uvprs     TYPE uvprs,
            t_color  TYPE lvc_t_scol,     "For row color
          END OF tw_xresult .
  TYPES:

    tt_result  TYPE STANDARD TABLE OF tw_xresult .

2. Register the events for which you need to act upon.

  METHOD ALV_SET_EVENTS.
    DATA: lr_events TYPE REF TO cl_salv_events_table.

    lr_events = mcn_alv-> get_event().

*- Register the event Double click
    SET HANDLER me->mt_on_double_click FOR lr_events.

*- Register the event User command
    SET HANDLER me->mt_on_user_command FOR lr_events.

ENDMETHOD.
3. Once the required data is fetched into the internal table (say, into internal table mt_result), we use the following code, to display the records with provision to select multiple records (through the selection pushbutton on the left for each record)

 METHOD alv_show .
  DATA : lr_selections TYPE REF TO cl_salv_selections.

  FIELD-SYMBOLS: <fs_data> TYPE STANDARD TABLE.

*- Show ALV on the screen

  ASSIGN me->mn_data->* TO <fs_data>.
  CHECK <fs_data> IS ASSIGNED.

  TRY.
      cl_salv_table=>factory( EXPORTING list_display = abap_false
                              IMPORTING r_salv_table = mcn_alv
                               CHANGING t_table = <fs_data> ).
    CATCH cx_salv_msg INTO mcn_alv_exception.
      MESSAGE mcn_alv_exception TYPE 'E'.
      EXIT.
  ENDTRY.
  me->alv_set_functions( ).
  me->alv_set_columns( ).
  me->alv_set_layout( mf_variantname ).

  me->alv_set_events( ).
  me->alv_set_headers( ).
  CALL METHOD alv_modify_settings( ).

  lr_selections = mcn_alv->get_selections( ).

  lt_rows = lr_selections->get_selected_rows().      " This will get the selected record numbers, in lt_rows.

*- Set selection mode
  lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

    mcn_alv->set_screen_status(
    pfstatus      =  'ZREPINCOMP'
    report        =  mf_repid
    set_functions = mcn_alv->c_functions_all ).

  mcn_alv->display( ).
ENDMETHOD.

4. With the above code, you will be able to select multiple records, and then the following code will process the selected records, and set a color for the processed records.

   DATA   lw_row        TYPE i,

        lt_color TYPE lvc_t_scol ,
        ls_color TYPE lvc_s_scol .
   FIELD-SYMBOLS: <fs_result> TYPE tw_xresult.               "#EC NEEDED
 
  LOOP AT lt_rows INTO lw_row.

    READ TABLE mt_result ASSIGNING <fs_result> INDEX lw_row.

    IF SY_SUBRC EQ 0.

     

       <code for processing your selected record>

      

*- For setting the color to the record      
       CLEAR lt_color.

       CLEAR ls_color.

       ls_color-color-col = co_color.
       ls_color-color-int = 0.
       ls_color-color-inv = 0.
       APPEND ls_color TO lt_color.
 
       <fs_result>-t_color =  lt_color.
 
    ENDIF.

   ENDLOOP.

Labels

alv alv Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.