0% found this document useful (0 votes)
141 views6 pages

CL Salv Table

The document describes how to customize and add functionality to an ALV (Application List Viewer) grid in ABAP. It includes examples of how to add a custom menu, handle user commands, set column colors, and sort the grid. Key aspects covered are setting the screen status to add a menu, handling user commands via events, appending color definitions, and accessing the sorts object to enable sorting.

Uploaded by

cessantanna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views6 pages

CL Salv Table

The document describes how to customize and add functionality to an ALV (Application List Viewer) grid in ABAP. It includes examples of how to add a custom menu, handle user commands, set column colors, and sort the grid. Key aspects covered are setting the screen status to add a menu, handling user commands via events, appending color definitions, and accessing the sorts object to enable sorting.

Uploaded by

cessantanna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CL_SALV_TABLE

terça-feira, 6 de junho de 2023


12:52
TOP OF PAGE
DEFINTION
top_of_page
IMPORTING
VALUE(i_nrreg) TYPE i
CHANGING
VALUE(c_alv) TYPE REF TO cl_salv_table.

IMPLMENTATION
METHOD top_of_page.
DATA(li_row) = 0.

DATA(lo_grid) = NEW cl_salv_form_layout_grid( ).

* ADD 1 TO li_row.
* DATA(lo_title) = lo_grid->create_action_information(
* row = li_row
* column = 1
* colspan = 2
* text = TEXT-ape
* ).

ADD 1 TO li_row.
DATA(lo_label) = lo_grid->create_label(
row = li_row
column = 1
text = TEXT-por
).

DATA(lo_text) = lo_grid->create_text(
row = li_row
column = 2
text = sy-uname
).
lo_label->set_label_for( lo_text ).

ADD 1 TO li_row.
lo_label = lo_grid->create_label(
row = li_row
column = 1
text = TEXT-dat
).

lo_text = lo_grid->create_text(
row = li_row
column = 2
text = |{ sy-datum+6(2) }.{ sy-datum+4(2) }.{ sy-datum+0(4)
}.|
).
lo_label->set_label_for( lo_text ).

ADD 1 TO li_row.
lo_label = lo_grid->create_label(
row = li_row
column = 1
text = TEXT-hor
).

lo_text = lo_grid->create_text(
row = li_row
column = 2
text = |{ sy-uzeit+0(2) }:{ sy-uzeit+2(2) }:{ sy-uzeit+4(2)
}.|
).
lo_label->set_label_for( lo_text ).

ADD 1 TO li_row.
lo_label = lo_grid->create_label(
row = li_row
column = 1
text = TEXT-nrg
).

lo_text = lo_grid->create_text(
row = li_row
column = 2
text = i_nrreg
).
lo_label->set_label_for( lo_text ).

c_alv->set_top_of_list(
EXPORTING
value = lo_grid
).

ENDMETHOD.

Cor na celula
Guia de cores

DEFINTION
PUBLIC SECTION.
TYPES:
...
ty_alvnm TYPE c LENGTH 5,
...
BEGIN OF ty_outtab_s,
...
clcor TYPE lvc_t_scol,
END OF ty_outtab_s.

METHODS:
append_color
IMPORTING
VALUE(i_fname) TYPE lvc_s_scol-fname
RETURNING
VALUE(r_color) TYPE lvc_t_scol,

set_colum_[ALVNM]
IMPORTING
VALUE(i_colms) TYPE REF TO cl_salv_columns_table,

IMPLEMANTATION
METHOD process_data.

LOOP AT i_table INTO DATA(ls_table).


...
IF ls_table-field LT 0.
ls_table-clcor = append_color( '[CLNAM]' ).
ENDIF.
...
ENDLOOP.

ENDMETHOD.

METHOD DISPLAY_ALV.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = i_alv
CHANGING
t_table = i_outtab.
CATCH cx_salv_msg INTO DATA(lo_alvms).
ENDTRY.
...

CASE i_alvnm.
WHEN me->c_alvnm.
me->set_column_alvnm1( lo_columns ).
ENDCASE..
...

ENDMETHOD.

METHOD append_color.

APPEND INITIAL LINE TO r_color


ASSIGNING FIELD-SYMBOL(<color>).

<color>-fname = i_fname.
<color>-color-col = 6.
<color>-color-int = 1.
<color>-color-inv = 0.

ENDMETHOD.
METHOD set_colum_[ALVNM].
DATA:
lo_column TYPE REF TO cl_salv_column_list.

...
lo_column ?= i_colms->get_column( '[CLNAM]' ).
i_colms->set_color_column( 'CLCOR' ).
...

ENDMETHOD.

Tipos de Seleção de linha no ALV


IMPLEMENTATION
METHOD DISPLAY_ALV.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = i_alv
CHANGING
t_table = i_outtab.
CATCH cx_salv_msg INTO DATA(lo_alvms).
ENDTRY.
...

DATA(lo_selection) = me->o_alv->get_selections( ).

lo_selection->set_selection_mode( 2 )."Multimplas Linhas


...

ENDMETHOD.

SINGLE 1

MULTIPLE 2

CELL 3

ROW_COLUMN 4

NONE 0

Atribuição de Menu customizado


Fazer a copia do Status-gui do programa: SALV_DEMO_TABLE_FUNCTIONS
Para o programa novo...

Basta aceitar e ir no programa novo e ativar o status GUI SAL_STANDARD

Adicionar o codigo abaixo no mesmo metodo que cria o objeto SALV_TABLE


me->o_alv->set_screen_status(
pfstatus = 'SALV_STANDART'
report = '[PROG_NAME]'
set_functions = me->o_alv->c_functions_all
).

DATA(lo_events) = me->o_alv->get_event( ).
SET HANDLER me->on_ucomm FOR lo_events.

DEFINITION
on_ucomm
FOR EVENT if_salv_events_functions~added_function
OF cl_salv_events_table
IMPORTING e_salv_function

IMPLEMENTATION
METHOD on_ucomm.

CASE e_salv_function.
WHEN '[UCOMM]'.
me->ucomm_method( ).
ENDCASE.

ENDMETHOD. "on_ucomm

DATA(lo_layout) = i_alv->get_layout( ).
ls_layout-report = sy-repid.
lo_layout->set_key( ls_layout ).
lo_layout->set_save_restriction( if_salv_c_layout=>restrict_none )
.

Ordenar o ALV

IMPLEMENTATION
METHOD DISPLAY_ALV.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = i_alv
CHANGING
t_table = i_outtab.
CATCH cx_salv_msg INTO DATA(lo_alvms).
ENDTRY.
...
DATA(lo_sorts) = i_alv->get_sorts( ).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy