Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV Report

Former Member
0 Likes
2,284

Hi,

I have to display some columns in some differenct colours in the ALV Report.

How to do in ALV ? Is there any option in the field catalog ? I tried with KEY in the field catalog . But it is not coming ..

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'NAME1'.

LS_FIELDCAT-TABNAME = 'ITAB_FINAL'.

LS_FIELDCAT-NO_OUT = ' '.

LS_FIELDCAT-COL_POS = '3'.

LS_FIELDCAT-SELTEXT_L = 'Vendor Name'.

<b> LS_FIELDCAT-KEY = '3'.</b>

Bye,

Satya.

Hi,

I have to display some columns in some differenct colours in the ALV Report.

How to do in ALV ? Is there any option in the field catalog ? I tried with KEY in the field catalog . But it is not coming ..

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'NAME1'.

LS_FIELDCAT-TABNAME = 'ITAB_FINAL'.

LS_FIELDCAT-NO_OUT = ' '.

LS_FIELDCAT-COL_POS = '3'.

LS_FIELDCAT-SELTEXT_L = 'Vendor Name'.

<b> LS_FIELDCAT-KEY = '3'.</b>

Bye,

Satya.

5 REPLIES 5
Read only

Former Member
0 Likes
1,175

try this..

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'NAME1'.

LS_FIELDCAT-TABNAME = 'ITAB_FINAL'.

LS_FIELDCAT-NO_OUT = ' '.

LS_FIELDCAT-COL_POS = '3'.

LS_FIELDCAT-SELTEXT_L = 'Vendor Name'.

LS_FIELDCAT-KEY = 'X'. " this will give in blue color

<b>LS_FIELDCAT-EMPHASIZE = 'C310'.</b>

C -- constant

3-- color code , chk program SHOWCOLO for color code

1 - intensified on/off , 0 for off

0 -- inverse on/off

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,175

Yes, you simply apply the coloring code to the EMPHASIZE field in the field catalog.

The coding is like this.

First character is always C

Second character is the coloring code, 1- 7

Third is the intensify code 1 or 0

Fourth is the inverse code 1 or 0

So try something like this.

wa_fieldcat-emphasize = 'C610'.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,175

Hello,

Check this sample report.


REPORT  ZTESTALV.
TYPE-POOLS: SLIS.
INCLUDE <ICON>.
*- Fieldcatalog
DATA: IT_FIELDCAT  TYPE SLIS_T_FIELDCAT_ALV,
      IT_FIELDCAT1  TYPE SLIS_T_FIELDCAT_ALV..
 
DATA:  X_FIELDCAT  TYPE SLIS_FIELDCAT_ALV,
        X_FIELDCAT1  TYPE SLIS_FIELDCAT_ALV.
 
DATA: IT_EVENTS TYPE SLIS_T_EVENT,
      X_EVENTS TYPE SLIS_ALV_EVENT.
 
X_EVENTS-NAME = 'END_OF_LIST'.
X_EVENTS-FORM = 'LIST_MODIFY_OUPUT'.
APPEND X_EVENTS TO IT_EVENTS.
 
 
DATA: BEGIN OF IT_VBAP OCCURS 0,
      VBELN LIKE VBAP-VBELN,
      POSNR LIKE VBAP-POSNR,
      FLAG(1),
     END OF IT_VBAP.
 
SELECT VBELN
       POSNR
       UP TO 10 ROWS
      INTO TABLE IT_VBAP
      FROM VBAP.
LOOP AT IT_VBAP.
 
  IF SY-TABIX = 1 OR SY-TABIX = 5.
    IT_VBAP-FLAG = 'X'.
    MODIFY IT_VBAP INDEX SY-TABIX.
  ENDIF.
 
ENDLOOP.
 
DATA:L_POS TYPE I VALUE 1.
CLEAR: L_POS.
L_POS = L_POS + 1.
X_FIELDCAT-SELTEXT_M = 'VBELN'.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'IT_VBAP'.
X_FIELDCAT-COL_POS    = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
 
X_FIELDCAT-SELTEXT_M = 'POSNR'.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'IT_VBAP'.
X_FIELDCAT-COL_POS    = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
 
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM = SY-REPID
    IT_FIELDCAT        = IT_FIELDCAT
    IT_EVENTS          = IT_EVENTS
  TABLES
    T_OUTTAB           = IT_VBAP
  EXCEPTIONS
    PROGRAM_ERROR      = 1
    OTHERS             = 2.
IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
 
*&--------------------------------------------------------------------*
*&      Form  LIST_MODIFY_OUPUT
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM LIST_MODIFY_OUPUT.
  DATA: L_VBELN LIKE VBAK-VBELN,
        L_POSNR LIKE VBAP-POSNR,
        l_index type sy-index.
        clear it_vbap.
  DO 20 TIMES.
    CLEAR: L_VBELN, L_POSNR.
    READ LINE SY-INDEX INDEX SY-LSIND
         FIELD VALUE IT_VBAP-VBELN INTO L_VBELN
                     IT_VBAP-POSNR INTO L_POSNR .
"3lines are reserved for alv headings , so i am reading it form 4th line
"so 4th line is equal to 1st line of itab
    IF SY-SUBRC = 0 AND SY-INDEX GE 4.
       l_index = sy-index - 3.
      READ TABLE IT_VBAP INDEX l_index.
      IF SY-SUBRC = 0 AND IT_VBAP-FLAG = 'X'.
*-Modifying current list
        MODIFY LINE SY-INDEX INDEX SY-LSIND
                   FIELD FORMAT IT_VBAP-POSNR COLOR 6 INVERSE.
        MODIFY LINE SY-INDEX INDEX SY-LSIND
                   FIELD FORMAT IT_VBAP-VBELN COLOR 6 INVERSE.
      ENDIF.
    ENDIF.
  ENDDO.
 
ENDFORM.                    "LIST_MODIFY_OUPUT
 
 
 
The above programs makes conditional cell coloring.
 
Regards
VAsanth



Read only

rodrigo_paisante3
Active Contributor
0 Likes
1,175

Hi, this is an example:

The comentary is in portuguese, but the program works. The FORM zf_altera_cores. does what you want.

-

-


REPORT zgtc1004_avl_g NO STANDARD PAGE HEADING

LINE-SIZE 150 MESSAGE-ID zfi.

TABLES:

j_1bnfdoc, j_1bnflin. "Documentos de faturamento

TYPE-POOLS:

vrm, "Necessário para uso de ALV

slis. "Tipos globais para ALV

*----

-


  • Tipos do usuário

*----

-


TYPES:

BEGIN OF y_vbrk,

nota LIKE j_1bnflin-docnum,

material LIKE j_1bnflin-matnr,

preco LIKE j_1bnflin-netpr,

valor LIKE j_1bnflin-netwr,

mark TYPE c,

END OF y_vbrk.

*----

-


  • Tabelas internas ALV

*

  • As estruturas aqui utilizadas (SLIS) estão explicadas com as opções

  • mais importantes no final da apostila

*----

-


DATA:

t_linecolor TYPE slis_specialcol_alv OCCURS 0 WITH HEADER LINE,

t_listheader TYPE slis_t_listheader,

t_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,

t_sort TYPE slis_sortinfo_alv OCCURS 0 WITH HEADER LINE.

DATA:

v_listheader TYPE slis_listheader, "Cabeçalho

v_layout TYPE slis_layout_alv, "layout para saída

v_print TYPE slis_print_alv, "Ctrl de impressão

v_variante LIKE disvariant. "Variante de exibição

*----

-


  • Tabelas internas

*----

-


DATA:

t_vbrk TYPE y_vbrk OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF t_alv OCCURS 0.

INCLUDE STRUCTURE t_vbrk.

DATA:

color TYPE slis_t_specialcol_alv. "Definir a cor

DATA: END OF t_alv.

*----

-


  • Variáveis de uso geral

*----

-


DATA:

v_tabix LIKE sy-tabix,

v_repid LIKE sy-repid,

v_flag.

*----

-


  • Tela de seleção

*----

-


SELECTION-SCREEN BEGIN OF BLOCK one.

SELECT-OPTIONS:

s_vbeln FOR j_1bnflin-docnum. "Documento de faturamento

SELECTION-SCREEN SKIP.

PARAMETERS:

p_varia LIKE disvariant-variant. "Variante de exibição

SELECTION-SCREEN END OF BLOCK one.

*----

-


  • Eventos

*----

-


INITIALIZATION.

PERFORM zf_init_alv.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varia.

PERFORM zf_recupera_layouts_salvos.

*----

-


  • Principal

*----

-


START-OF-SELECTION.

PERFORM:

zf_selecao_dados, "Seleciona a VBRK

zf_altera_cores, "Alterando as cores dos campos

zf_monta_tabela_alv, "Preenche o catálogo

zf_sort_subtotal, "Ordenação dos campos e subtotais

zf_executa_funcao_alv. "Gera o relatório

END-OF-SELECTION.

*----

-


  • Rotinas

*----

-


*----

-


FORM zf_init_alv.

v_repid = sy-repid.

CLEAR v_variante.

v_variante-report = v_repid.

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

i_save = 'A'

CHANGING

cs_variant = v_variante

EXCEPTIONS

not_found = 2.

IF sy-subrc = 0.

p_varia = v_variante.

ENDIF.

ENDFORM.

*----

-


  • Form zf_recupera_layouts_salvos

*----

-


FORM zf_recupera_layouts_salvos.

v_variante-report = v_repid.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = v_variante

i_save = 'A'

IMPORTING

es_variant = v_variante

EXCEPTIONS

not_found = 2.

IF sy-subrc = 2.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSE.

p_varia = v_variante-variant.

ENDIF.

ENDFORM.

*----

-


  • Form zf_selecao_dados

*----

-


  • Seleção dos dados

*----

-


FORM zf_selecao_dados.

SELECT

docnum

matnr

netpr

netwr

FROM j_1bnflin

INTO TABLE t_vbrk

WHERE docnum IN s_vbeln.

LOOP AT t_vbrk.

MOVE-CORRESPONDING t_vbrk TO t_alv.

APPEND t_alv.

ENDLOOP.

ENDFORM.

*----


*

  • Form zf_altera_cores

*----


*

  • Permite informar a cor que vc deseja para a coluna, inclusive

  • pelo valor da variável

*----


*

FORM zf_altera_cores.

LOOP AT t_alv.

REFRESH t_linecolor.

REFRESH t_alv-color.

t_linecolor-fieldname = 'NOTA'.

t_linecolor-color-col = '6'.

t_linecolor-color-inv = '1'. "Inverso, 1 liga e 0 desliga

APPEND t_linecolor.

  • Temos a opção INV, que é invertido, mesmo esquema do INT

  • 1 liga e 0 desliga

IF t_vbrk-preco <> 0.

t_linecolor-fieldname = 'PRECO'.

t_linecolor-color-col = '1'.

t_linecolor-color-int = '1'. "Negrito (1-ligado, 0-Desligado)

ELSE.

t_linecolor-fieldname = 'PRECO'.

t_linecolor-color-col = '6'.

t_linecolor-color-int = '1'. "Negrigo (1-ligado, 0-Desligado)

ENDIF.

APPEND t_linecolor.

t_alv-color[] = t_linecolor[].

MODIFY t_alv.

ENDLOOP.

ENDFORM.

*----

-


  • Form zf_monta_tabela_alv

*----

-


FORM zf_monta_tabela_alv.

CLEAR t_fieldcat.

t_fieldcat-fieldname = 'MARK'.

t_fieldcat-tabname = 'T_ALV'.

t_fieldcat-reptext_ddic = 'S'.

t_fieldcat-inttype = 'C'.

t_fieldcat-outputlen = 1.

t_fieldcat-checkbox = 'X'.

APPEND t_fieldcat.

CLEAR t_fieldcat.

t_fieldcat-fieldname = 'NOTA'.

t_fieldcat-tabname = 'T_ALV'.

t_fieldcat-reptext_ddic = 'N° Nota'.

t_fieldcat-inttype = 'C'.

t_fieldcat-outputlen = 10.

APPEND t_fieldcat.

CLEAR t_fieldcat.

t_fieldcat-fieldname = 'MATERIAL'.

t_fieldcat-tabname = 'T_ALV'.

t_fieldcat-reptext_ddic = 'Material'.

t_fieldcat-inttype = 'C'.

t_fieldcat-outputlen = 2.

APPEND t_fieldcat.

ENDFORM.

*----

-


  • Form zf_sort_subtotal

*----

-


  • Classificação e item de subtotalização

*----

-


FORM zf_sort_subtotal.

CLEAR t_sort[].

t_sort-spos = 1.

t_sort-fieldname = 'MATERIAL'.

t_sort-tabname = 'T_ALV'.

t_sort-up = 'X'.

t_sort-subtot = 'X'.

APPEND t_sort.

ENDFORM.

*----

-


  • Form zf_executa_funcao_alv

*----

-


  • Apresenta relatório

*----

-


FORM zf_executa_funcao_alv.

  • Preenchendo algumas opções de impressão (Não é obrigatório)

v_layout-expand_all = 'X'. "Abrir subitens

v_layout-colwidth_optimize = 'X'. "Largura melhor possível da coluna

v_layout-edit = 'X'. "Permitir a edição

  • Indicando para função qual o layout que deve ser apresentado

  • primeiro

v_variante-variant = p_varia.

v_print-no_print_listinfos = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

i_background_id = 'ALV_BACKGROUND'

i_callback_top_of_page = 'ZF_TOP_OF_PAGE'

i_callback_user_command = 'ZF_USER_COMMAND'

it_fieldcat = t_fieldcat[]

is_layout = v_layout

it_sort = t_sort[]

i_default = 'X'

i_save = 'A'

is_variant = v_variante

is_print = v_print

TABLES

t_outtab = t_alv

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDFORM.

*----

-


  • Form zf_user_command

*----

-


  • Tratamento das opções do usuário. Por exemplo um Drill-down ou

  • algum botão que você inseriu ou alterou. O importante é conhecer

  • os parâmetros que o form recebe

*----

-


FORM zf_user_command USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

  • UCOMM: é o sy-ucomm (Ok-code)

  • SELFIELD: é uma estrutura com dados que nós permite identifcar

  • o que foi selecionado. Essa estrutura também está

  • explicada no anexo ao final da apostila

  • Salva a posição do relatório (Linha escolhida)

selfield-row_stable = 'X'.

  • Uma das questões foi como alterar o conteúdo de uma tabela

  • transparente com as alterações feitas no relatório ALV

  • Segue um exemplo de como pode ser feito:

  • Em nossa barra de ferramentas criamos o botão com código

  • ZATU

IF ucomm = 'ZATU'.

  • Vamos ler a tabela T_VBRK onde mark = X. A idéia é que

  • o usuário mark com X os registros alterados

LOOP AT t_vbrk WHERE mark = 'X'.

v_tabix = sy-tabix.

  • Atualiza a tabela transparente

" update ztabela ....

  • Então voltamos a T_VBRK sem marcação alguma

CLEAR t_vbrk-mark.

MODIFY t_vbrk INDEX v_tabix.

  • Veja que esse tipo de esquema pode ser feito para

  • excluir registros também

ENDLOOP.

ENDIF.

ENDFORM.

*----

-


  • Form zf_status

*----

-


  • Status com botão de log (Item a mais na barra ALV)

*----

-


FORM zf_status USING rt_extab TYPE slis_t_extab.

  • Aqui estamos informando a função que ela deverá utilizar a barra de

  • ferramentas ZALV_BOTOES.

"set pf-status 'ZALV_BOTOES'.

  • Também é possível excluir funções

"if sy-uname = ...

"EXCLUDING ...

"endif.

ENDFORM.

Read only

Former Member
0 Likes
1,175

hi,

ALV provides an option for displaying columns in differrnt colours, for that one we pass the value to <b>EMPHASIZE</b> field of FIELD CATALOG <b>LVC_T_FCAT</b>

if the filed is set to 'X' the ALV uses a predefined color for highlighiting the columns.if the character field begins with 'C' (color code), the remaining numbers have the following meaning.

<b>filed EMPHASIZE of LVC_T_FCAT has value range..

LVC_T_FCAT-EMPHASIZE = space " no color assigned to columns

LVC_T_FCAT-EMPHASIZE = 'X' "assign predefined color

LVC_T_FCAT-EMPHASIZE = 'Cxyz'

here x : color number ( starts from 1 to 9)

y : intensified dispaly on / off ( on =1 , off = 0)

z : inverse display on / off ( on =1, off =0)</b>

as per your color requirement you can pass values to EMPHASIZE field of field catalog.

for more information on color coding , see the F1 help on the FORMAT statement.

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'NAME1'.

LS_FIELDCAT-TABNAME = 'ITAB_FINAL'.

LS_FIELDCAT-NO_OUT = ' '.

LS_FIELDCAT-COL_POS = '3'.

LS_FIELDCAT-SELTEXT_L = 'Vendor Name'.

<b>LS_FIELDCAT-EMPHASIZE = 'C411'. "here pass value as per your selected color.</b>

regards,

Ashokreddy.