Application Development 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: 

I want to display icons in ALV

Former Member
0 Kudos
273

Hi friends,

I want to display icon indicators in ALV ???

can anybody tell me ??/

Thanks...

1 ACCEPTED SOLUTION

Former Member
0 Kudos
110

Hi sturdy,

this code will help u...copy paste and run...

&----


*& Report ZFI_TEST *

*& *

&----


*& *

*& *

&----


REPORT ZFI_ICON_TEST MESSAGE-ID zz .

*& TABLES DECLARATION *

TABLES: vbak.

*& TYPE POOLS DECLARATION *

&----


TYPE-POOLS: slis.

&----


*& INTERNAL TABLE DECLARATION *

&----


DATA: BEGIN OF itab OCCURS 0,

icon TYPE icon-id, "itab-icon = '@08@' -> Green ; '@09@' -> Yellow ; '@0A@' -> Red

vbeln LIKE vbak-vbeln,

audat LIKE vbak-audat,

vbtyp LIKE vbak-vbtyp,

auart LIKE vbak-auart,

augru LIKE vbak-augru,

netwr LIKE vbak-netwr,

waerk LIKE vbak-waerk,

END OF itab.

*INTERNAL TABLE FOR FIELD CATALOG

DATA: wa_fieldcat TYPE slis_fieldcat_alv,

it_fieldcat TYPE slis_t_fieldcat_alv.

  • IT_FIELDCAT TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV

  • WITH HEADER LINE,

*INTERNAL TABLE FOR EVENTS

DATA: it_event TYPE slis_t_event,

wa_event TYPE slis_alv_event,

*INTERNAL TABLE FOR SORTING

it_sort TYPE slis_t_sortinfo_alv,

wa_sort TYPE slis_sortinfo_alv,

*INTERNAL TABLE FOR LAYOUT

wa_layout TYPE slis_layout_alv.

&----


*& VARIABLE DECLARATION *

&----


DATA : v_repid TYPE sy-repid,

v_pagno(4) TYPE n,

v_date(8) TYPE c.

&----


*& CONSTANTS *

&----


CONSTANTS: c_x TYPE c VALUE 'X'.

&----


*& SELECTION SCREEN *

&----


SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln,

s_vbtyp FOR vbak-vbtyp DEFAULT 'C'.

SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) text-003.

PARAMETERS: p_list RADIOBUTTON GROUP rad1 DEFAULT 'X'.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) text-004.

PARAMETERS: p_grid RADIOBUTTON GROUP rad1.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN: END OF BLOCK b2.

AT SELECTION-SCREEN.

PERFORM validate_screen.

&----


*& START OF SELECTION *

&----


START-OF-SELECTION.

CLEAR: itab, itab[].

  • V_REPID = SY-REPID.

PERFORM get_data.

PERFORM display_data.

&----


*& END OF SELECTION *

&----


END-OF-SELECTION.

*--DO ALV Process

v_repid = sy-repid.

*--Sort the Output Fields

PERFORM sort_fields.

*--Build Field catalog for the Output fields

  • PERFORM BUILD_FIELDCAT.

*--Set the Layout for ALV

PERFORM set_layout.

&----


*& Form GET_DATA

&----


  • text

----


  • TO GET THE DATA FROM TABLES INTO ITAB

----


FORM get_data .

SELECT vbeln

audat

vbtyp

auart

augru

netwr

waerk

INTO CORRESPONDING FIELDS OF TABLE itab

FROM vbak

WHERE vbeln IN s_vbeln AND

audat > '04.04.2005'

AND netwr > 0.

LOOP AT itab.

IF itab-netwr < 10000.

itab-icon = '@08@'.

ELSEIF itab-netwr > 10000 AND itab-netwr < 100000.

itab-icon = '@09@'.

ELSEIF itab-netwr > 100000.

itab-icon = '@0A@'.

ENDIF.

MODIFY itab INDEX sy-tabix.

ENDLOOP.

ENDFORM. " GET_DATA

&----


*& Form sort_fields

&----


FORM sort_fields .

CLEAR wa_sort.

wa_sort-fieldname = 'VBTYP'.

wa_sort-spos = '1'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

wa_sort-fieldname = 'NETWR'.

wa_sort-spos = '2'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

ENDFORM. " sort_fields

*

&----


*& Form set_layout

&----


FORM set_layout .

IF p_list = c_x .

wa_layout-window_titlebar = 'LIST DISPLAY'(016).

wa_layout-zebra = 'X'.

*-- ALV LIST DISPLAY

PERFORM list_display TABLES itab.

*-- ALV GRID DISPLAY

ELSEIF p_grid = c_x.

wa_layout-window_titlebar = 'GRID DISPLAY'(017).

wa_layout-zebra = 'X'.

PERFORM grid_display TABLES itab.

ENDIF.

ENDFORM. " set_layout

&----


*& Form list_display

&----


FORM list_display TABLES p_itab .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

is_layout = wa_layout

it_fieldcat = it_fieldcat[]

it_sort = it_sort[]

i_save = 'U'

TABLES

t_outtab = itab

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.

ENDFORM. " list_display

&----


*& Form GRID_DISPLAY

&----


FORM grid_display TABLES p_itab .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

is_layout = wa_layout

it_fieldcat = it_fieldcat[]

it_sort = it_sort[]

it_events = it_event

TABLES

t_outtab = itab

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.

ENDFORM. " GRID_DISPLAY

&----


*& Form VALIDATE_SCREEN

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM validate_screen .

DATA: lv_vbeln LIKE vbak-vbeln.

IF NOT s_vbeln IS INITIAL.

SELECT vbeln

INTO lv_vbeln

UP TO 1 ROWS

FROM vbak

WHERE vbeln IN s_vbeln.

ENDSELECT.

IF sy-subrc <> 0.

MESSAGE e000 WITH 'INVALID SALES DOC'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_SCREEN

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data .

DEFINE m_fieldcat.

add 1 to wa_fieldcat-col_pos.

wa_fieldcat-fieldname = &1.

wa_fieldcat-ref_tabname = 'VBAK'.

wa_fieldcat-do_sum = &2.

wa_fieldcat-cfieldname = &3.

append wa_fieldcat to it_fieldcat.

END-OF-DEFINITION.

DATA:

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv.

m_fieldcat 'ICON' '' ''.

m_fieldcat 'VBELN' '' ''.

m_fieldcat 'AUDAT' '' ''.

m_fieldcat 'VBTYP' '' ''.

m_fieldcat 'AUART' '' ''.

m_fieldcat 'AUGRU' '' ''.

m_fieldcat 'NETWR' 'C' 'WAERK'.

m_fieldcat 'WAERK' '' ''.

ENDFORM. " display_data[/code]

6 REPLIES 6

Former Member
0 Kudos
111

Hi sturdy,

this code will help u...copy paste and run...

&----


*& Report ZFI_TEST *

*& *

&----


*& *

*& *

&----


REPORT ZFI_ICON_TEST MESSAGE-ID zz .

*& TABLES DECLARATION *

TABLES: vbak.

*& TYPE POOLS DECLARATION *

&----


TYPE-POOLS: slis.

&----


*& INTERNAL TABLE DECLARATION *

&----


DATA: BEGIN OF itab OCCURS 0,

icon TYPE icon-id, "itab-icon = '@08@' -> Green ; '@09@' -> Yellow ; '@0A@' -> Red

vbeln LIKE vbak-vbeln,

audat LIKE vbak-audat,

vbtyp LIKE vbak-vbtyp,

auart LIKE vbak-auart,

augru LIKE vbak-augru,

netwr LIKE vbak-netwr,

waerk LIKE vbak-waerk,

END OF itab.

*INTERNAL TABLE FOR FIELD CATALOG

DATA: wa_fieldcat TYPE slis_fieldcat_alv,

it_fieldcat TYPE slis_t_fieldcat_alv.

  • IT_FIELDCAT TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV

  • WITH HEADER LINE,

*INTERNAL TABLE FOR EVENTS

DATA: it_event TYPE slis_t_event,

wa_event TYPE slis_alv_event,

*INTERNAL TABLE FOR SORTING

it_sort TYPE slis_t_sortinfo_alv,

wa_sort TYPE slis_sortinfo_alv,

*INTERNAL TABLE FOR LAYOUT

wa_layout TYPE slis_layout_alv.

&----


*& VARIABLE DECLARATION *

&----


DATA : v_repid TYPE sy-repid,

v_pagno(4) TYPE n,

v_date(8) TYPE c.

&----


*& CONSTANTS *

&----


CONSTANTS: c_x TYPE c VALUE 'X'.

&----


*& SELECTION SCREEN *

&----


SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln,

s_vbtyp FOR vbak-vbtyp DEFAULT 'C'.

SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) text-003.

PARAMETERS: p_list RADIOBUTTON GROUP rad1 DEFAULT 'X'.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN : BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(20) text-004.

PARAMETERS: p_grid RADIOBUTTON GROUP rad1.

SELECTION-SCREEN : END OF LINE.

SELECTION-SCREEN: END OF BLOCK b2.

AT SELECTION-SCREEN.

PERFORM validate_screen.

&----


*& START OF SELECTION *

&----


START-OF-SELECTION.

CLEAR: itab, itab[].

  • V_REPID = SY-REPID.

PERFORM get_data.

PERFORM display_data.

&----


*& END OF SELECTION *

&----


END-OF-SELECTION.

*--DO ALV Process

v_repid = sy-repid.

*--Sort the Output Fields

PERFORM sort_fields.

*--Build Field catalog for the Output fields

  • PERFORM BUILD_FIELDCAT.

*--Set the Layout for ALV

PERFORM set_layout.

&----


*& Form GET_DATA

&----


  • text

----


  • TO GET THE DATA FROM TABLES INTO ITAB

----


FORM get_data .

SELECT vbeln

audat

vbtyp

auart

augru

netwr

waerk

INTO CORRESPONDING FIELDS OF TABLE itab

FROM vbak

WHERE vbeln IN s_vbeln AND

audat > '04.04.2005'

AND netwr > 0.

LOOP AT itab.

IF itab-netwr < 10000.

itab-icon = '@08@'.

ELSEIF itab-netwr > 10000 AND itab-netwr < 100000.

itab-icon = '@09@'.

ELSEIF itab-netwr > 100000.

itab-icon = '@0A@'.

ENDIF.

MODIFY itab INDEX sy-tabix.

ENDLOOP.

ENDFORM. " GET_DATA

&----


*& Form sort_fields

&----


FORM sort_fields .

CLEAR wa_sort.

wa_sort-fieldname = 'VBTYP'.

wa_sort-spos = '1'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

wa_sort-fieldname = 'NETWR'.

wa_sort-spos = '2'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

ENDFORM. " sort_fields

*

&----


*& Form set_layout

&----


FORM set_layout .

IF p_list = c_x .

wa_layout-window_titlebar = 'LIST DISPLAY'(016).

wa_layout-zebra = 'X'.

*-- ALV LIST DISPLAY

PERFORM list_display TABLES itab.

*-- ALV GRID DISPLAY

ELSEIF p_grid = c_x.

wa_layout-window_titlebar = 'GRID DISPLAY'(017).

wa_layout-zebra = 'X'.

PERFORM grid_display TABLES itab.

ENDIF.

ENDFORM. " set_layout

&----


*& Form list_display

&----


FORM list_display TABLES p_itab .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

is_layout = wa_layout

it_fieldcat = it_fieldcat[]

it_sort = it_sort[]

i_save = 'U'

TABLES

t_outtab = itab

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.

ENDFORM. " list_display

&----


*& Form GRID_DISPLAY

&----


FORM grid_display TABLES p_itab .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

is_layout = wa_layout

it_fieldcat = it_fieldcat[]

it_sort = it_sort[]

it_events = it_event

TABLES

t_outtab = itab

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.

ENDFORM. " GRID_DISPLAY

&----


*& Form VALIDATE_SCREEN

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM validate_screen .

DATA: lv_vbeln LIKE vbak-vbeln.

IF NOT s_vbeln IS INITIAL.

SELECT vbeln

INTO lv_vbeln

UP TO 1 ROWS

FROM vbak

WHERE vbeln IN s_vbeln.

ENDSELECT.

IF sy-subrc <> 0.

MESSAGE e000 WITH 'INVALID SALES DOC'.

ENDIF.

ENDIF.

ENDFORM. " VALIDATE_SCREEN

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data .

DEFINE m_fieldcat.

add 1 to wa_fieldcat-col_pos.

wa_fieldcat-fieldname = &1.

wa_fieldcat-ref_tabname = 'VBAK'.

wa_fieldcat-do_sum = &2.

wa_fieldcat-cfieldname = &3.

append wa_fieldcat to it_fieldcat.

END-OF-DEFINITION.

DATA:

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv.

m_fieldcat 'ICON' '' ''.

m_fieldcat 'VBELN' '' ''.

m_fieldcat 'AUDAT' '' ''.

m_fieldcat 'VBTYP' '' ''.

m_fieldcat 'AUART' '' ''.

m_fieldcat 'AUGRU' '' ''.

m_fieldcat 'NETWR' 'C' 'WAERK'.

m_fieldcat 'WAERK' '' ''.

ENDFORM. " display_data[/code]

Former Member
0 Kudos
110

put the "icon" field in the fieldcatalog as 'X' and pass the corresponding value of the icon

Former Member
0 Kudos
110

look at sample program : BCALV_TREE_06 .. if UR looking

for the same ...

Former Member
0 Kudos
110

Hi

Do the following: (for diplaying the icon led - traffic light)

INCLUDE:<icon>.

TYPE-POOLS: slis.

types: begin of ty_abcd,

led type statusicon30,

end of ty_abcd.

In the fieldcatalog, make an entry for this led.

Former Member
0 Kudos
110

Hi,

Please refer to the SAP standard demo program BCALV_TREE_06.

Thanks,

Sriram Ponna.

Former Member
0 Kudos
110

Hi,

see this simple code.


TYPE-POOLS:slis,icon.

DATA:fcat type slis_t_fieldcat_alv.

DATA:BEGIN OF itab OCCURS 0,
     icon LIKE icon-name,
      matnr like mara-matnr,
      ernam like mara-ernam,
      ersda like mara-ersda,
      mtart like mara-mtart,
    END OF itab.

SELECT * from mara into CORRESPONDING FIELDS OF TABLE itab UP TO 20
rows.

LOOP AT itab.
  IF sy-tabix < 10.
    itab-icon = ICON_GREEN_LIGHT.
  else.
    itab-icon = ICON_RED_LIGHT.
  ENDIF.
  MODIFY itab.
  clear itab.
ENDLOOP.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
 EXPORTING
   I_PROGRAM_NAME               = sy-repid
   I_INTERNAL_TABNAME           = 'ITAB'
   I_INCLNAME                   = sy-repid
  CHANGING
    CT_FIELDCAT                  = fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                = sy-repid
   IT_FIELDCAT                       = fcat
  TABLES
    T_OUTTAB                          = itab.

rgds,

bharat.