Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[ABAP] SALV – Access column name

  TRY.
      cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv)
                              CHANGING  t_table      = lt_output ).
    CATCH cx_salv_msg INTO DATA(lx_salv).
      WRITE: / lx_salv->get_text( ).
  ENDTRY.

  DATA(columns) = lo_alv->get_columns( ).
  DATA(lt_cols) = columns->get( ).

  LOOP AT lt_cols INTO DATA(ls_cols).
    DATA(lo_column) = ls_cols-r_column.
    CASE ls_cols-columnname.
      WHEN 'MANDT'
        lo_column->set_visible( abap_false ).
    ENDCASE.
  ENDLOOP.

[ABAP] ALV traffic lights

TYPES: BEGIN OF ty_log,
         status TYPE icon-id,
       END OF ty_log.

DATA gt_log TYPE TABLE OF ty_log.

gt_log = VALUE #( ( status = icon_red_light    )
                  ( status = icon_yellow_light )
                  ( status = icon_green_light  ) ).

TRY.
    cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv_table)
                            CHANGING  t_table      = gt_log ).

    alv_table->display( ).

  CATCH cx_salv_msg.
ENDTRY.

icon_red, icon_yellow etc. will be automatically loaded from the TYPE-POOL: icon during runtime.

You can check all available icons via the table icon.

SELECT SINGLE id INTO @DATA(icon_red) FROM icon WHERE name = 'ICON_RED_LIGHT'.

[ABAP] ALV column header

DATA: o_salv TYPE REF TO cl_salv_table.

cl_salv_table=>factory( IMPORTING r_salv_table = o_salv
                        CHANGING  t_table      = l_lines ).

LOOP AT o_salv->get_columns( )->get( ) REFERENCE INTO DATA(l_column).
  DATA(lo_column) = CAST cl_salv_column( l_column->r_column ).
  lo_column->set_fixed_header_text( 'L' ).
ENDLOOP.

o_salv->get_columns( )->get_column( 'TEST1' )->set_long_text( 'Test1 Header' ).
o_salv->get_columns( )->get_column( 'TEST2' )->set_long_text( 'Test2 Header' ).

[ABAP] Select-Option for ALV Layout

Create a ALV Layout Variant
Select-Option for Layout Variant on Selectionscreen
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-b03.
PARAMETERS: p_vari TYPE slis_vari.
SELECTION-SCREEN END OF BLOCK b3.

INITIALIZATION.

  "Load default layout
  DATA: ls_layout TYPE salv_s_layout_info,
        ls_key    TYPE salv_s_layout_key.

  ls_key-report = sy-repid.

  ls_layout = cl_salv_layout_service=>get_default_layout( s_key    = ls_key
                                                          restrict = '1' ).
  p_vari = ls_layout-layout.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.

  "Value Help
  DATA: ls_layout TYPE salv_s_layout_info,
        ls_key    TYPE salv_s_layout_key.

  ls_key-report = sy-repid.

  ls_layout = cl_salv_layout_service=>f4_layouts( s_key    = ls_key
                                                  restrict = '1' ).
  p_vari = ls_layout-layout.

[ABAP] SALV

    TRY.
        cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv_table)
                                CHANGING  t_table      = lt_display_data ).
        alv_table->display( ).

      CATCH cx_salv_msg.
    ENDTRY.