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: 

Traffic Lights in ALV

Former Member
0 Kudos

Hi experts,

I am using below code to generate the traffic lights but in column header i am getting one button i want to replace that as Traffic lights. how to do this can any body tell me

*&----


"Includes

*&----


INCLUDE <icon>.

INCLUDE <symbol>.

*&----


*& Declaration part

*&----


"Types

TYPES:

BEGIN OF t_lights,

matnr TYPE mard-matnr,

werks TYPE mard-werks,

lgort TYPE mard-lgort,

lights TYPE char4, "Variable is needs to be declared with length 4 char

END OF t_lights.

"Work Areas

DATA:

w_lights TYPE t_lights.

"Internal tables

DATA:

i_lights TYPE STANDARD TABLE OF t_lights.

&----


  • ALV Declarations

----


  • Types Pools

TYPE-POOLS:

slis.

  • Types

TYPES:

t_fieldcat TYPE slis_fieldcat_alv,

t_events TYPE slis_alv_event,

t_layout TYPE slis_layout_alv.

  • Workareas

DATA:

w_fieldcat TYPE t_fieldcat,

w_events TYPE t_events,

w_layout TYPE t_layout.

  • Internal Tables

DATA:

i_fieldcat TYPE STANDARD TABLE OF t_fieldcat,

i_events TYPE STANDARD TABLE OF t_events.

&----


*& start of selection

&----


START-OF-SELECTION.

PERFORM get_data.

&----


*& end-of-selection.

&----


END-OF-SELECTION.

PERFORM build_fieldcatlog.

PERFORM build_layout.

PERFORM list_display.

&----


*& Form get_data

&----


FORM get_data .

SELECT matnr

werks

lgort

FROM mard

INTO CORRESPONDING FIELDS OF TABLE i_lights

UP TO 10 ROWS.

IF i_lights[] IS INITIAL.

"Dummy data

DO 10 TIMES.

w_lights-matnr = sy-index.

w_lights-werks = sy-index + 1.

w_lights-lgort = sy-index + 2.

APPEND w_lights TO i_lights.

CLEAR w_lights.

ENDDO.

ENDIF.

"Just pass 1=red or 2=yellow or 3=green to lights fields

LOOP AT i_lights INTO w_lights .

IF sy-tabix BETWEEN 1 AND 3.

w_lights-lights = '1'.

ELSEIF sy-tabix BETWEEN 4 AND 7.

w_lights-lights = '2'.

ELSEIF sy-tabix BETWEEN 8 AND 10.

w_lights-lights = '3'.

ENDIF.

MODIFY i_lights FROM w_lights INDEX sy-tabix TRANSPORTING lights.

ENDLOOP.

ENDFORM. " get_data

&----


*& Form build_fieldcatlog

&----


FORM build_fieldcatlog .

CLEAR:w_fieldcat,i_fieldcat[].

w_fieldcat-fieldname = 'MATNR'.

w_fieldcat-seltext_m = 'MATNR'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-fieldname = 'WERKS'.

w_fieldcat-seltext_m = 'WERKS'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-fieldname = 'LGORT'.

w_fieldcat-seltext_m = 'LGORT'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

ENDFORM. " build_fieldcatlog

&----


*& Form build_layout

&----


FORM build_layout .

w_layout-colwidth_optimize = 'X'.

w_layout-zebra = 'X'.

w_layout-lights_fieldname = 'LIGHTS'.

w_layout-lights_tabname = 'I_LIGHTS'.

ENDFORM. " build_layout

&----


*& Form list_display

&----


FORM list_display .

DATA:

l_program TYPE sy-repid.

l_program = sy-repid.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = l_program

is_layout = w_layout

it_fieldcat = i_fieldcat

TABLES

t_outtab = i_lights

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

Thanks,

Tharangini

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi!

Add this to your layout:

w_layout-lights_rollname = 'MATNR'.(I have added MATNR but you can create a data element with field name as 'Traffic Lights'.It can be of any type).

Add this to your fieldcatalog:

w_fieldcat-fieldname = 'LIGHTS'.

w_fieldcat-seltext_l = 'Traffic Lights'.

w_fieldcat-seltext_s = 'Traffic Lights'.

w_fieldcat-seltext_m = 'Traffic Lights'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

12 REPLIES 12

Former Member
0 Kudos

Hi!

Add this to your layout:

w_layout-lights_rollname = 'MATNR'.(I have added MATNR but you can create a data element with field name as 'Traffic Lights'.It can be of any type).

Add this to your fieldcatalog:

w_fieldcat-fieldname = 'LIGHTS'.

w_fieldcat-seltext_l = 'Traffic Lights'.

w_fieldcat-seltext_s = 'Traffic Lights'.

w_fieldcat-seltext_m = 'Traffic Lights'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

0 Kudos

Hi Sudeer,

If i am using that code in output i am getting 5 columns.

buttton matnr werks lgort trafficlights like this.

but i need like bellow.

matnr werks lgort trafficlights

Please help me how to do this.

Thanks,

Tharangini.

0 Kudos

Hi!

Can you try changing the FM name to 'REUSE_ALV_GRID_DISPLAY' with rest of the code remaining same.I tried the same and it is working fine.

0 Kudos

Hi sudeer,

If i use reuse_alv_grid_display in the header its comming exception i don't want that i need traffic lights.

Thanks,

Tharangini.

0 Kudos

Hi!

Did you add the fieldcatlog code:

w_fieldcat-fieldname = 'LIGHTS'.

w_fieldcat-seltext_l = 'Traffic Lights'.

w_fieldcat-seltext_s = 'Traffic Lights'.

w_fieldcat-seltext_m = 'Traffic Lights'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

and also make sure that you add the following to your layout:

w_layout-lights_rollname = 'MATNR'.(I have added MATNR but you can create a data element with field name as 'Traffic Lights'.It can be of any type).

It works for me!!!

0 Kudos

Hi sudeer,

Thanks a lot.Its working fine.i'll not forget to reward points.

now lights are comming in first column is it possible to get those lights in last.

Can you please help me for this problem also.

Thanks,

Tharangini.

0 Kudos

Hi!

Try this code.I have removed the previous code where you specify Lights in layout.I specified the lights column in fieldcatalog as Icon and passed the icon value instead of the no.s which you specified earlier.

*&----


"Includes

*&----


INCLUDE <icon>.

INCLUDE <symbol>.

*&----


*& Declaration part

*&----


"Types

TYPES:

BEGIN OF t_lights,

matnr TYPE mard-matnr,

werks TYPE mard-werks,

lgort TYPE mard-lgort,

lights(4),

END OF t_lights.

"Work Areas

DATA:

w_lights TYPE t_lights.

"Internal tables

DATA:

i_lights TYPE STANDARD TABLE OF t_lights.

TYPE-POOLS:

slis.

TYPES:

t_fieldcat TYPE slis_fieldcat_alv,

t_events TYPE slis_alv_event,

t_layout TYPE slis_layout_alv.

DATA:

w_fieldcat TYPE t_fieldcat,

w_events TYPE t_events,

w_layout TYPE t_layout.

DATA:

i_fieldcat TYPE STANDARD TABLE OF t_fieldcat,

i_events TYPE STANDARD TABLE OF t_events.

*&----


*& start of selection

*&----


START-OF-SELECTION.

PERFORM get_data.

*&----


*& end-of-selection.

*&----


END-OF-SELECTION.

PERFORM build_fieldcatlog.

PERFORM build_layout.

PERFORM list_display.

*&----


*& Form get_data

*&----


FORM get_data .

SELECT matnr

werks

lgort

FROM mard

INTO CORRESPONDING FIELDS OF TABLE i_lights

UP TO 10 ROWS.

IF i_lights[] IS INITIAL.

"Dummy data

DO 10 TIMES.

w_lights-matnr = sy-index.

w_lights-werks = sy-index + 1.

w_lights-lgort = sy-index + 2.

APPEND w_lights TO i_lights.

CLEAR w_lights.

ENDDO.

ENDIF.

"Just pass @0A@=red or @09@=yellow or @08@=green to lights fields

LOOP AT i_lights INTO w_lights .

IF sy-tabix BETWEEN 1 AND 3.

w_lights-lights = '@0A@'.

ELSEIF sy-tabix BETWEEN 4 AND 7.

w_lights-lights = '@09@'.

ELSEIF sy-tabix BETWEEN 8 AND 10.

w_lights-lights = '@08@'.

ENDIF.

MODIFY i_lights FROM w_lights INDEX sy-tabix TRANSPORTING lights.

ENDLOOP.

ENDFORM. " get_data

*&----


*& Form build_fieldcatlog

*&----


FORM build_fieldcatlog .

CLEAR:w_fieldcat,i_fieldcat[].

w_fieldcat-fieldname = 'MATNR'.

w_fieldcat-seltext_m = 'MATNR'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-fieldname = 'WERKS'.

w_fieldcat-seltext_m = 'WERKS'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-fieldname = 'LGORT'.

w_fieldcat-seltext_m = 'LGORT'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-fieldname = 'LIGHTS'.

w_fieldcat-icon = 'X'.

w_fieldcat-outputlen = 14.

w_fieldcat-seltext_l = 'Traffic Lights'.

w_fieldcat-seltext_s = 'Traffic Lights'.

w_fieldcat-seltext_m = 'Traffic Lights'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

ENDFORM. " build_fieldcatlog

*&----


*& Form build_layout

*&----


FORM build_layout .

w_layout-colwidth_optimize = 'X'.

w_layout-zebra = 'X'.

ENDFORM. " build_layout

*&----


*& Form list_display

*&----


FORM list_display .

DATA:

l_program TYPE sy-repid.

l_program = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = l_program

is_layout = w_layout

it_fieldcat = i_fieldcat

TABLES

t_outtab = i_lights

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

0 Kudos

Hi Sudeer,

Thanks a lot.my problem was solved.

Thank you so much.

Thanks,

Tharangini.

Former Member
0 Kudos

hi ,

Pls refer standard program BCALV_GRID_04 . for Traffic Lights in ALV .

Reward Points for help full annswers

Regards

Fareedas

former_member181995
Active Contributor
0 Kudos

Hi Kamatham,

1. Its simple

2. We have to use the layout of alv also.

and one extra field in the internal table.

3. Just copy paste in new program.

REPORT abc.

TYPE-POOLS : slis.

DATA : alvly TYPE slis_layout_alv.

DATA : alvfc TYPE slis_t_fieldcat_alv.

DATA : BEGIN OF itab OCCURS 0,

lt TYPE i,

matnr LIKE mara-matnr,

END OF itab.

END-OF-SELECTION.

itab-lt = 1.

APPEND itab.

itab-lt = 2.

APPEND itab.

itab-lt = 3.

APPEND itab.

itab-lt = 1.

APPEND itab.

itab-lt = 3.

APPEND itab.

itab-lt = 3.

APPEND itab.

itab-lt = 3.

APPEND itab.

*----


alvly-lights_fieldname = 'LT'.

alvly-lights_tabname = 'ITAB'.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'ITAB'

i_inclname = sy-repid

CHANGING

ct_fieldcat = alvfc.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

it_fieldcat = alvfc

is_layout = alvly

i_save = 'A'

TABLES

t_outtab = itab.

regards,

amit m.

0 Kudos

Hi jony,

I have checked ur program.but in heading i am getting Exception i don't want that i need heading as Traffic lights

Thanks,

Tharangini.

Former Member
0 Kudos

Hi Tharangini,

Try This...

REPORT ALV_LIGHTS.

TYPES: BEGIN OF ty_alv,

lights(1) TYPE c, "Exception, Holding the value of the lights

text(20) TYPE c, "some text

END OF ty_alv.

DATA: gs_alv TYPE ty_alv,

gt_alv TYPE TABLE OF ty_alv,

gr_alv TYPE REF TO cl_salv_table,

gr_columns TYPE REF TO cl_salv_columns_table.

START-OF-SELECTION.

gs_alv-lights = '1'. "Color red

gs_alv-text = 'RED SIGNAL'.

APPEND gs_alv TO gt_alv.

gs_alv-lights = '2'. "Color yellow

gs_alv-text = 'YELLOW SIGNAL'.

APPEND gs_alv TO gt_alv.

gs_alv-lights = '3'. "Color green

gs_alv-text = 'GREEN SIGNAL'.

APPEND gs_alv TO gt_alv.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = gr_alv

CHANGING

t_table = gt_alv.

gr_columns = gr_alv->get_columns( ).

gr_columns->set_exception_column( value = 'LIGHTS' ).

CALL METHOD gr_alv->display.

Regards,

Chitra