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: 

displaying traffic lights in alv grid report?

Former Member
0 Kudos

Hi everyone,

I have an alv grid report.I m using the FM reuse_alv_grod_display to display my alv report.I am passing the fieldcatalogue automatically.I m getting the output perfectly.Now i have to add traffic lights to that alv report.

Since i m passing the fieldcatalogue automatically i m confused to display the traffic lights?

any suggestions please?

Thank you.

11 REPLIES 11

Former Member
0 Kudos

How are you populating your field catalog? There must be code written somewhere. You need to add a new column to your final internal table for Traffic lights and populate values in the same. you need to populate this field in your field catalog.

Refer to this topic

Message was edited by:

Ashish Gundawar

0 Kudos

Hi Ashish,

Thanks for the reply.I m populating the fieldcatalogue like this

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = I_GRID-PROGRAM

I_INTERNAL_TABNAME = 'I_HEADER'

I_STRUCTURE_NAME = ZIOHEADER

I_CLIENT_NEVER_DISPLAY = 'X'

CHANGING

CT_FIELDCAT = I_GRID-FIELDCAT.

0 Kudos

Try this SAP standard Demo report object - BCALV_GRID_04. It is using OOPS ALV but you can use the same logic.

0 Kudos

Hi D P,

You can not use this FM as you will have to add field ICON for displaying the traffic light in your final output table and this FM can be used in that case only when all the fields of the output table is from Data dictionary(You can check it in its documentation also) so go for manual population of field catalog as i have suggested you in the last post.

<b>Reward point</b> if problem solved else reply this thread i will send you the whole code that i developed in my requirement.

Regards,

Mukesh Kumar

0 Kudos

Hi mukesh

Thanks for the reply i can't go for manual field catalogue.I m passing a customised structure zioheader which is customised from standard ioheader strucutre to the field catalogue.It has more than 250 fields.I m also getting the data from logical database.

So is there any other option?

Former Member

Hi D P,

Add icon field to your final internal table

TYPES : BEGIN OF t_out,

icon TYPE icon-id, "Status

matnr TYPE qals-matnr, "Material

werk TYPE qals-werk, "Plant

END OF t_out.

Declare the colors

*----


  • Constants

*----


CONSTANTS: c_green TYPE icon-id VALUE '@08@',

c_yellow TYPE icon-id VALUE '@09@',

c_red TYPE icon-id VALUE '@0A@'.

Put the conditions like this for color

IF g_yellow EQ 'X'.

MOVE c_yellow TO wa_out-icon.

ELSEIF g_red EQ 'X'.

MOVE c_red TO wa_out-icon.

ELSE.

MOVE c_green TO wa_out-icon.

ENDIF.

APPEND wa_out TO p_out.

Fieldcatalog

FORM populate_fieldcat USING p_table TYPE c.

**status

CLEAR wa_fieldcat.

wa_fieldcat-tabname = p_table.

wa_fieldcat-fieldname = 'ICON'.

wa_fieldcat-seltext_l = text-010.

wa_fieldcat-outputlen = 15.

wa_fieldcat-icon = 'X'.

APPEND wa_fieldcat TO i_fieldcat.

ENDFORM. " populate_fieldcat

Former Member
0 Kudos

Hi D P,

First of all write : INCLUDE <ICON> in ur program.

Declare a field in the internal table used for display for icon display ad ICON-ID.

Pass the values @5C@, @5D@ and @5B@ according to the condition.

In the fieldcatalog make the icon field as X.

(or)

data: result(2).

assign ICON_GREEN_LIGHT to .

if result = 'OK'.

assign ICON_GREEN_LIGHT to .

else.

assign ICON_RED_LIGHT to .

endif.

write: as icon.

The name of the traffic light field is supplied in the layout-excp_fname used by method set_table_for_first_display.

The name of the trafic lights should be filled in field lights_fieldname of is_layout parameter

Reward if helpful.

Regards,

Harini.S

Former Member
0 Kudos

*&----


*& Report YGS_ALV_BOM *

*& *

&----


*& *

*& *

&----


REPORT YGS_ALV_BOM .

TABLES : MAST,STKO,STPO.

TYPE-POOLS: SLIS.

TYPES : BEGIN OF TY_MAST,

CHECK_BOX,

MATNR TYPE MAST-MATNR,

WERKS TYPE MAST-WERKS,

STLAN TYPE MAST-STLAN,

STLNR TYPE MAST-STLNR,

STLAL TYPE MAST-STLAL,

END OF TY_MAST.

TYPES : BEGIN OF TY_STKO,

STLTY TYPE STKO-STLTY,

STLNR TYPE STKO-STLNR,

STLAL TYPE STKO-STLAL,

STKOZ TYPE STKO-STKOZ,

BMENG TYPE STKO-BMENG,

BMEIN TYPE STKO-BMEIN,

END OF TY_STKO.

TYPES : BEGIN OF TY_STPO,

LIGHTS,

STLTY TYPE STPO-STLTY,

STLNR TYPE STPO-STLNR,

STLKN TYPE STPO-STLKN,

STPOZ TYPE STPO-STPOZ,

IDNRK TYPE STPO-IDNRK,

MENGE TYPE STPO-MENGE,

MEINS TYPE STPO-MEINS,

END OF TY_STPO.

DATA : IT_MAST TYPE TABLE OF TY_MAST,

WA_MAST TYPE TY_MAST,

IT_STKO TYPE TABLE OF TY_STKO,

WA_STKO TYPE TY_STKO,

IT_STPO TYPE TABLE OF TY_STPO,

WA_STPO TYPE TY_STPO.

DATA : lt_fieldcat TYPE slis_t_fieldcat_alv,

ls_layout TYPE slis_layout_alv,

ls_event TYPE slis_alv_event,

lt_event TYPE slis_t_event,

it_sortinfo type slis_t_sortinfo_alv,

ls_header TYPE slis_listheader,

lt_header TYPE slis_t_listHEADER.

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

SELECT-OPTIONS : S_MATNR FOR MAST-MATNR.

START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM BUILD_FIELDCAT USING LT_FIELDCAT.

PERFORM BUILD_LAYOUT.

END-OF-SELECTION.

PERFORM DISPLAY_DATA.

&----


*& Form GET_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form GET_DATA .

REFRESH : IT_MAST.

SELECT MATNR

WERKS

STLAN

STLNR

FROM MAST

INTO CORRESPONDING FIELDS OF TABLE IT_MAST

WHERE MATNR IN S_MATNR.

endform. " GET_DATA

&----


*& Form BUILD_FIELDCAT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form BUILD_FIELDCAT USING LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA : L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

REFRESH : LT_FIELDCAT.

L_FIELDCAT-COL_POS = 1.

L_FIELDCAT-FIELDNAME = 'MATNR'.

L_FIELDCAT-TABNAME = 'IT_MAST'.

L_FIELDCAT-REF_FIELDNAME = 'MATNR'.

L_FIELDCAT-REF_TABNAME = 'MAST'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

L_FIELDCAT-COL_POS = 2.

L_FIELDCAT-FIELDNAME = 'WERKS'.

L_FIELDCAT-TABNAME = 'IT_MAST'.

L_FIELDCAT-REF_FIELDNAME = 'WERKS'.

L_FIELDCAT-REF_TABNAME = 'MAST'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

L_FIELDCAT-COL_POS = 3.

L_FIELDCAT-FIELDNAME = 'STLNR'.

L_FIELDCAT-TABNAME = 'IT_MAST'.

L_FIELDCAT-REF_FIELDNAME = 'STLNR'.

L_FIELDCAT-REF_TABNAME = 'MAST'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

endform. " BUILD_FIELDCAT

&----


*& Form BUILD_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form BUILD_LAYOUT .

CLEAR LS_LAYOUT.

LS_LAYOUT-BOX_FIELDNAME = 'CHECK_BOX'.

LS_LAYOUT-BOX_TABNAME = 'IT_MAST'.

endform. " BUILD_LAYOUT

&----


*& Form DISPLAY_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form DISPLAY_DATA .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

  • I_STRUCTURE_NAME =

IS_LAYOUT = LS_LAYOUT

IT_FIELDCAT = LT_FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = IT_MAST

  • 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. " DISPLAY_DATA

FORM PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'YSTATUS' OF PROGRAM SY-REPID

EXCLUDING RT_EXTAB.

ENDFORM.

********************************************************************

FORM USER_COMMAND USING RF_UCOMM TYPE SY-UCOMM

SELFIELD TYPE SLIS_SELFIELD.

CASE RF_UCOMM.

WHEN '&NEXT'.

PERFORM GET_DATA_BOM .

PERFORM BUILD_FIELDCAT_BOM USING LT_FIELDCAT.

PERFORM BUILD_LAYOUT_BOM.

PERFORM DISPLAY_DATA_BOM.

ENDCASE.

ENDFORM.

*&----


*

*& Form GET_DATA_BOM

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form GET_DATA_BOM .

CLEAR : WA_STPO,

WA_MAST.

REFRESH : IT_STPO.

DATA : IT_CHECK TYPE TABLE OF TY_MAST.

LOOP AT IT_MAST INTO WA_MAST.

IF WA_MAST-CHECK_BOX EQ 'X'.

APPEND WA_MAST TO IT_CHECK.

ENDIF.

ENDLOOP.

SELECT STLTY

STLNR

STLKN

VGKNT

IDNRK

MENGE

MEINS

FROM STPO

INTO CORRESPONDING FIELDS OF TABLE IT_STPO

FOR ALL ENTRIES IN IT_CHECK

WHERE IDNRK EQ IT_CHECK-MATNR.

CLEAR WA_STPO.

LOOP AT IT_STPO INTO WA_STPO.

SELECT SINGLE * FROM MAST WHERE MATNR EQ WA_STPO-IDNRK.

IF SY-SUBRC = 0.

WA_STPO-LIGHTS = '2'.

ELSE.

WA_STPO-LIGHTS = '1'.

ENDIF.

MODIFY IT_STPO FROM WA_STPO.

ENDLOOP.

endform. " GET_DATA_BOM

*&----


*

*& Form BUILD_FIELDCAT_BOM

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

**----


**

form BUILD_FIELDCAT_BOM USING LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA : L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

REFRESH : LT_FIELDCAT.

L_FIELDCAT-COL_POS = 1.

L_FIELDCAT-FIELDNAME = 'STLTY'.

L_FIELDCAT-TABNAME = 'IT_STPO'.

L_FIELDCAT-REF_FIELDNAME = 'STLTY'.

L_FIELDCAT-REF_TABNAME = 'STPO'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

L_FIELDCAT-COL_POS = 2.

L_FIELDCAT-FIELDNAME = 'STLNR'.

L_FIELDCAT-TABNAME = 'IT_STPO'.

L_FIELDCAT-REF_FIELDNAME = 'STLNR'.

L_FIELDCAT-REF_TABNAME = 'STPO'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

L_FIELDCAT-COL_POS = 3.

L_FIELDCAT-FIELDNAME = 'STLKN'.

L_FIELDCAT-TABNAME = 'IT_STPO'.

L_FIELDCAT-REF_FIELDNAME = 'STLKN'.

L_FIELDCAT-REF_TABNAME = 'STPO'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

L_FIELDCAT-COL_POS = 4.

L_FIELDCAT-FIELDNAME = 'IDNRK'.

L_FIELDCAT-TABNAME = 'IT_STPO'.

L_FIELDCAT-REF_FIELDNAME = 'IDNRK'.

L_FIELDCAT-REF_TABNAME = 'STPO'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

L_FIELDCAT-COL_POS = 5.

L_FIELDCAT-FIELDNAME = 'MENGE'.

L_FIELDCAT-TABNAME = 'IT_STPO'.

L_FIELDCAT-REF_FIELDNAME = 'MENGE'.

L_FIELDCAT-REF_TABNAME = 'STPO'.

APPEND L_FIELDCAT TO LT_FIELDCAT.

endform. " BUILD_FIELDCAT_BOM

*&----


*

*& Form BUILD_LAYOUT_BOM

*&----


  • text

*----


  • --> p1 text

*<-- p2 text

*----


form BUILD_LAYOUT_BOM .

CLEAR : LS_LAYOUT.

LS_LAYOUT-LIGHTS_FIELDNAME = 'LIGHTS'.

LS_LAYOUT-LIGHTS_TABNAME = 'IT_STPO'.

endform. " BUILD_LAYOUT_BOM

&----


*& Form DISPLAY_DATA_BOM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form DISPLAY_DATA_BOM .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'USER_COMMAND_BOM'

I_CALLBACK_TOP_OF_PAGE = 'TOP9'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

I_BACKGROUND_ID = 'ALV_BACKGROUND'

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = LS_LAYOUT

IT_FIELDCAT = LT_FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = IT_STPO

  • 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. " DISPLAY_DATA_BOM

FORM TOP9 .

CLEAR LS_HEADER.

REFRESH LT_HEADER.

LS_HEADER-TYP = 'H'.

LS_HEADER-INFO = 'BILL OF MATERIALS'.

APPEND LS_HEADER TO LT_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = LT_HEADER

I_LOGO = 'ENJOYSAP_LOGO'

  • I_END_OF_LIST_GRID =

.

ENDFORM.

FORM USER_COMMAND_BOM USING RF_UCOMM_BOM LIKE SY-UCOMM

SEL_FIELD TYPE SLIS_SELFIELD.

CASE RF_UCOMM_BOM.

WHEN '&IC1'.

SET PARAMETER ID 'MAT' FIELD WA_STPO-IDNRK.

SET PARAMETER ID 'WRK' FIELD WA_MAST-WERKS.

SET PARAMETER ID 'CSA' FIELD WA_MAST-STLAN.

CALL TRANSACTION 'CS03' AND SKIP FIRST SCREEN.

ENDCASE.

For adding a button in application tool bar,

1. Goto SE80

2. Select function group and give SALV

3. expand the GUI STATUS drop down and right click on STANDARD

4. Copy -->Copy that to ur Z* program

5. Go to change mode and add a button in application bar

let say '&VA02'.

6 Save and activate it in ur program

7. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'

8. FORM PF_STATUS using RT_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS 'STANDARD' EXCLUDING RT_EXTAB.

ENDFORM. "PF_STATUS

9 FORM USER_COMMAND using RT_UCOMM type SY-UCOMM

RT_FIELD type SLIS_SELFIELD.

READ TABLE IT_FINAL INDEX RT_FIELD-TABINDEX.

CASE RT_UCOMM.

WHEN '&VA02'.

SET PARAMETER ID 'AUN' FIELD IT_FINAL-VBELN.

CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.

ENDCASE.

ENDFORM. "USER_COMMAND

it wil help u.

Regards,

Zakir.

former_member188829
Active Contributor
0 Kudos

Wrong post

Edited by: VISHNU on Feb 7, 2008 11:48 AM

Former Member
0 Kudos

hi dp,

look at the program i made... se the bold part you will be able to impelment lights easily,

-


DECLARING TYPES POOL *

-


All the definitions of internal tables, structures and constants

are declared in a type-pool called SLIS.

type-pools: slis.

-


TABLES *

-


tables: vbak,vbap,kna1.

-


TYPES *

-


*&--defining types for TABLE VBAK

types: begin of t_vbak,

vbeln type vbeln_va, "sales document

kunnr type kunag,

erdat type erdat,

auart type auart,

netwr type netwr_ak,

waerk type waerk,

vkorg type vkorg,

vtweg type vtweg,

spart type spart,

name1 type name1_gp,

stras type stras_gp,

ort01 type ort01_gp,

pstlz type pstlz,

regio type regio,

land1 type land1_gp,

telf1 type telf1,

end of t_vbak.

*&--Defining types for TABLE VBAP

types: begin of t_vbap,

vbeln type vbeln_va,

posnr type posnr_va,

matnr type matnr,

maktx type maktx,

end of t_vbap.

*&--MERGED FINAL SALES TABLE

types: begin of t_sales_final,

vbeln type vbeln_va,

kunnr type kunag,

posnr type posnr_va,

erdat type erdat, "date of creation

auart type auart,

netwr type netwr_ak,

waerk type waerk,

vkorg type vkorg,

vtweg type vtweg,

spart type spart,

name1 type name1_gp,

v_lights type c,

stras type stras_gp,

ort01 type ort01_gp,

pstlz type pstlz,

regio type regio,

land1 type land1_gp,

telf1 type telf1,

matnr type matnr,

maktx type maktx,

end of t_sales_final.

defining wrokarea and IT.

-


WORK AREA DECLARATION *

-


*&---work area for Internal Tables

data: wa_vbak type t_vbak.

data: wa_vbap type t_vbap.

data: wa_sales_final type t_sales_final.

*&--work area for layout

data: wa_layout type slis_layout_alv.

-


INTERNAL TABLES DECLARATION *

-


*&---Internal tables without Header Line.

data : i_vbak type standard table of t_vbak,

i_vbap type standard table of t_vbap,

i_sales_final type standard table of t_sales_final.

*&---Internal table for field catalog

data : i_fieldcat type slis_t_fieldcat_alv,

*&---Internal table for the sorting sequence.

i_sortinfo type slis_t_sortinfo_alv,

*&---Internal table for the event catalog.

i_eventcat type slis_t_event,

*&---Internal table for the top of page event

i_listheader type slis_t_listheader.

-


VARIABLE DECLARATION *

-


data : v_progname like sy-repid, "Program name(system defined)

v_gridtitle type lvc_title. "Grid Title

-


INITIALIZATION EVENT *

-


initialization.

v_progname = sy-repid.

refresh:i_vbak,

i_vbap,

i_sales_final,

i_fieldcat,

i_sortinfo,

i_eventcat,

i_listheader.

clear: wa_vbak,

wa_vbap,

wa_sales_final,

wa_layout.

-


SELECTION SCREEN *

-


SCREEN FOR ENTERING INFORMATION

selection-screen begin of block b1 with frame title text-001.

select-options: r_vbeln for wa_vbak-vbeln obligatory.

select-options: r_erdat for wa_vbak-erdat obligatory.

selection-screen end of block b1 .

-


AT SELECTION SCREEN *

-


at selection-screen.

perform zf_validate_sales_doc_no.

perform zf_validate_date.

-


START OF SELECTION EVENT

-


start-of-selection.

perform zf_populate_header.

perform zf_populate_detail.

perform zf_append_sales_final.

-


END OF SELECTION EVENT

-


end-of-selection.

*If Internal Table Is Populated Then Only Display Alv Report.

if i_sales_final is not initial.

Prepare fieldcatalog .

perform zf_build_fieldcat using i_fieldcat.

MODIFY the records IN the internal TABLE for the traffic lights.

perform zf_modify_final.

build event catalogue

perform zf_eventcat using i_eventcat.

build sorting

perform zf_sorting using i_sortinfo.

&---Build Listheader for TOP OF PAGE EVENT.

perform zf_build_listheader using i_listheader.

&---Build layout.

perform zf_layout.

&---Initializating Grid Title

perform zf_build_grid_title.

&---Display alv grid.

perform zf_display_alv_grid.

else.

*If Table is not Populated ie Records Does not exist

message 'Record Does Not Exist' type 'S'.

endif.

&----


*& Form zf_validate_sales_doc_no

&----


text

-


--> p1 text

<-- p2 text

-


form zf_validate_sales_doc_no .

select single vbeln into wa_vbak-vbeln from vbak where vbeln in r_vbeln .

if sy-subrc <> 0.

message i101.

endif.

endform. " zf_validate_sales_doc_no

&----


*& Form zf_validate_date

&----


text

-


--> p1 text

<-- p2 text

-


form zf_validate_date .

if date is future

if r_erdat-low >= sy-datum.

message e102.

elseif r_erdat-high >= sy-datum.

message e103.

endif.

endform. " zf_validate_date

&----


*& Form zf_populate_header

&----


text

-


--> p1 text

<-- p2 text

-


form zf_populate_header .

select vbeln

kunnr

erdat

auart

netwr

waerk

vkorg

vtweg

spart

into table i_vbak from vbak where vbeln in r_vbeln.

if sy-subrc <> 0.

message 'RECORD DOES NOT EXIST' type 'E'.

endif.

sort i_vbak by vbeln.

*&--LOGIC TO GET FIELDS FROM TABLE KNA1 INTO INTERNAL TABLE I_VBAK

loop at i_vbak into wa_vbak.

select single name1 stras ort01 pstlz regio land1 telf1 into (wa_vbak-name1,

wa_vbak-stras,

wa_vbak-ort01,

wa_vbak-pstlz,

wa_vbak-regio,

wa_vbak-land1,

wa_vbak-telf1)

from kna1

where kunnr = wa_vbak-kunnr.

modifying it_header.

modify i_vbak from wa_vbak.

clear wa_vbak.

endloop.

endform. " zf_populate_header

&----


*& Form zf_populate_detail

&----


text

-


--> p1 text

<-- p2 text

-


form zf_populate_detail .

if i_vbak[] is not initial.

select vbeln

posnr

matnr

into table i_vbap from vbap

for all entries in i_vbak where vbeln = i_vbak-vbeln.

endif.

sort i_vbap by vbeln.

sort i_vbap by posnr.

*&--LOGIC TO GET FIELDS FROM TABLE MAKT INTO INTERNAL TABLE I_VBAP

loop at i_vbap into wa_vbap.

select single maktx into (wa_vbap-maktx)

from makt where matnr = wa_vbap-matnr and spras = sy-langu.

modifying it_header.

modify i_vbap from wa_vbap.

clear wa_vbap.

endloop.

endform. " zf_populate_detail

&----


*& Form zf_append_sales_final

&----


text

-


--> p1 text

<-- p2 text

-


form zf_append_sales_final .

sort i_vbak by vbeln.

sort i_vbap by vbeln posnr.

loop at i_vbak into wa_vbak.

move-corresponding wa_vbak to wa_sales_final.

read table i_vbap with key vbeln = wa_vbak-vbeln

binary search transporting no fields.

loop at i_vbap into wa_vbap from sy-tabix.

if wa_vbap-vbeln <> wa_vbak-vbeln.

exit.

endif.

move-corresponding wa_vbap to wa_sales_final.

append wa_sales_final to i_sales_final.

endloop.

endloop.

endform. " zf_append_sales_final

&----


*& Form zf_build_fieldcat

&----


text

-


-->P_I_FIELDCAT text

-


form zf_build_fieldcat using p_i_fieldcat type slis_t_fieldcat_alv.

data: l_fieldcat type slis_fieldcat_alv. "local Workarea used

clear l_fieldcat.

FOR LIGHT IN COLUMN

clear l_fieldcat.

l_fieldcat-col_pos = '1'. " POSITION OF THE COLUMN.

l_fieldcat-fieldname = 'V_LIGHTS'.

" FIELD FOR WHICH CATALOG ID FILLED.

*We are passing final internal table 'I_FINAL' to l_fieldcat(local

*variable

l_fieldcat-tabname = 'I_SALES_FINAL'.

" INTERNAL TABLE TO WHICH THE FIELD BELONGS TO.

l_fieldcat-just = 'C'. " FOR JUSTIFICATION.

l_fieldcat-outputlen = 20.

" TO DEFINE OUTPUT LENGTH OF THE COLUMN.

append l_fieldcat to p_i_fieldcat.

FIRST COLUMN ********************************

l_fieldcat-col_pos = '2'. " POSITION OF THE COLUMN

l_fieldcat-fieldname = 'VBELN'. " FIELD FOR WHICH CATALOG ID FILLED

l_fieldcat-tabname = 'I_SALES_FINAL'. " INTERNAL TABLE BELONGS TO

l_fieldcat-key = 'X'. " SO THAT this field is not scrollable hiddable.

l_fieldcat-just = 'L'. " FOR JUSTIFICATION

*l_fieldcat-hotspot = 'X'. " MARK THIS field as hotsopt

l_fieldcat-lzero = 'X'. " OUTPUT WITH leading zeros.

l_fieldcat-seltext_l = 'Sales Document'. " long text for header.

l_fieldcat-seltext_m = 'Sales Doc'. " medium text for header.

l_fieldcat-seltext_s = 'Sales Doc'. " sort text for header.

l_fieldcat-outputlen = 20. " SET THE output length.

l_fieldcat-ref_tabname = 'VBAK'. " FOR F1 & F4 help as

append l_fieldcat to p_i_fieldcat.

clear l_fieldcat.

**************************SECOND COLUMN ********************************

*l_fieldcat-col_pos = '3'. " POSITION OF THE COLUMN

l_fieldcat-row_pos = '2'. " POSITION OF THE COLUMN

l_fieldcat-fieldname = 'POSNR'. " FIELD FOR WHICH CATALOG ID FILLED

l_fieldcat-tabname = 'I_SALES_FINAL'. " INTERNAL TABLE BELONGS TO

l_fieldcat-key = 'X'. " SO THAT this field is not scrollable hiddable.

l_fieldcat-just = 'L'. " FOR JUSTIFICATION

l_fieldcat-hotspot = 'X'. " MARK THIS field as hotsopt

l_fieldcat-lzero = 'x'. " OUTPUT WITH leading zeros.

l_fieldcat-seltext_l = 'Sales Document Item'. " long text for header.

l_fieldcat-seltext_m = 'Sales Document Item'. " medium text for header.

l_fieldcat-seltext_s = 'Sales Document Item'. " sort text for header.

l_fieldcat-outputlen = 20. " SET THE output length.

l_fieldcat-ref_tabname = 'VBAP'. " FOR F1 & F4 help as

append l_fieldcat to p_i_fieldcat.

clear l_fieldcat.

endform. " zf_build_fieldcat

&----


*& Form zf_eventcat

&----


text

-


-->P_I_EVENTCAT text

-


form zf_eventcat using p_i_eventcat type slis_t_event.

data: l_eventcat type slis_alv_event.

clear l_eventcat.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = p_i_eventcat

exceptions

list_type_wrong = 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.

TOP OF PAGE FORM

clear l_eventcat.

read table p_i_eventcat into l_eventcat with key

name = slis_ev_top_of_page.

"(COMPONENT "NAME"of structure)

if sy-subrc = 0. "if success

move 'ZF_TOP_OF_PAGE' to l_eventcat-form.

"matches name and moves form to workarea and modifies table

modify p_i_eventcat from l_eventcat index sy-tabix

transporting form.

endif.

PF_STATUS_SET FORM

clear l_eventcat.

read table p_i_eventcat into l_eventcat with key

name = slis_ev_pf_status_set.

if sy-subrc = 0.

move 'ZF_PF_STATUS_SET' to l_eventcat-form.

modify p_i_eventcat from l_eventcat index sy-tabix

transporting form.

.

endif.

USER_COMMAND FORM

clear l_eventcat.

read table p_i_eventcat into l_eventcat with key

name = slis_ev_user_command.

if sy-subrc = 0.

move 'ZF_USER_COMMAND' to l_eventcat-form.

modify p_i_eventcat from l_eventcat index sy-tabix

transporting form.

endif.

endform. " zf_eventcat

&----


*& Form zf_sorting

&----


text

-


-->P_I_SORTINFO text

-


form zf_sorting using p_i_sortinfo.

endform. " zf_sorting

&----


*& Form zf_build_listheader

&----


text

-


-->P_I_LISTHEADER text

-


form zf_build_listheader using p_i_listheader type slis_t_listheader.

data: l_listheader type slis_listheader.

refresh p_i_listheader.

clear l_listheader.

HEADER

l_listheader-typ = 'H'.

l_listheader-info = 'FUJITSU CONSULTING INDIA LTD.'.

append l_listheader to p_i_listheader.

SELECTION

l_listheader-typ = 'S'.

l_listheader-key = 'Date:'.

l_listheader-info = sy-datum.

append l_listheader to p_i_listheader.

ACTION

l_listheader-typ = 'A'.

*l_listheader-key =

l_listheader-info = 'SALES ORDER ALV REPORT By Rohan Malik'.

append l_listheader to p_i_listheader.

endform. " zf_build_listheader

&----


*& Form zf_build_grid_title

&----


text

-


--> p1 text

<-- p2 text

-


form zf_build_grid_title .

v_gridtitle = 'List of Purchase Order'.

endform. " zf_build_grid_title

&----


*& Form zf_display_alv_grid

&----


text

-


--> p1 text

<-- p2 text

-


form zf_display_alv_grid .

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = v_progname

i_grid_title = v_gridtitle

is_layout = wa_layout

it_fieldcat = i_fieldcat

it_sort = i_sortinfo

it_events = i_eventcat

IMPORTING

E_EXIT_CAUSED_BY_CALLER =

ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = i_sales_final

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. " zf_display_alv_grid

&----


*& Form zf_top_of_page

&----


text

-


--> p1 text

<-- p2 text

-


form zf_top_of_page .

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = i_listheader

i_logo = 'ENJOYSAP_LOGO'

I_END_OF_LIST_GRID =

.

endform. " zf_top_of_page

&----


*& Form zf_user_command

&----


text

-


--> p1 text

<-- p2 text

-


form zf_user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield .

case r_ucomm. "FCODE

when 'VA03'.

read table i_sales_final into wa_sales_final index rs_selfield-tabindex.

set parameter id 'AUN' field rs_selfield-value.

call transaction 'VA03' and skip first screen .

message i102 with rs_selfield-value .

when '&IC1'. "for hotspot with VBELN, POSNR, MATNR, KUNNR.

if rs_selfield-fieldname = 'MATNR'.

set parameter id 'MAT' field rs_selfield-value.

call transaction 'MM03' and skip first screen.

return.

message i103 with rs_selfield-value .

endif.

if rs_selfield-fieldname = 'VBELN'.

set parameter id 'AUN' field rs_selfield-value.

call transaction 'VA03' and skip first screen.

return.

message i104 with rs_selfield-value .

.

endif.

endcase.

endform. " zf_user_command

&----


*& Form ZF_PF_STATUS_SET

&----


text

-


--> p1 text

<-- p2 text

-


form zf_pf_status_set using rt_extab type slis_t_extab.

set pf-status 'Z11_RM_ALV_SO'.

endform. " ZF_PF_STATUS_SET

&----


*& Form zf_layout

&----


text

-


--> p1 text

<-- p2 text

-


form zf_layout .

wa_layout-zebra = 'X'.

wa_layout-lights_fieldname = 'V_LIGHTS'.

wa_layout-lights_tabname = 'I_SALES_FINAL'.

" 1, 2 or 3 for red, yellow and green respectively.

endform. " zf_layout

&----


*& Form zf_modify_final

&----


text

-


--> p1 text

<-- p2 text

-


form zf_modify_final .

CODE TO EXECUTE LIGHTS

*start of loop

loop at i_sales_final into wa_sales_final.

*giving conditions and modifying as we want to change many rows

if wa_sales_final-netwr <= 10000.

wa_sales_final-v_lights = '1'.

modify i_sales_final from wa_sales_final transporting v_lights.

elseif wa_sales_final-netwr > 10000 and wa_sales_final-netwr <= 100000.

wa_sales_final-v_lights = '2'. " Exception.

modify i_sales_final from wa_sales_final transporting v_lights.

else.

wa_sales_final-v_lights = '3'. " Exception.

modify i_sales_final from wa_sales_final transporting v_lights.

endif.

endloop.

reward point s if helpful

rohan malik

YuanWang
Advisor
Advisor

Don't use is_layout when call FM  REUSE_ALV_GRID_DISPLAY.

Just set the value that you want to display as traffic light to constant ICON_RED_LIGHT (or green or yellow), which is of char4.

In this way, the header 'Exception' is not shown. Instead, the column name itself is shown.


TYPES: BEGIN OF ty_message,

          icon        TYPE char4,

          message TYPE string,

END OF ty_message.


    ls_message-icon = ICON_RED_LIGHT" red Traffic Light

     APPEND ls_message TO lt_message

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

   EXPORTING

     i_callback_program            = sy-repid

*    is_layout                          = ls_layout

     i_callback_user_command  = 'USER_COMMAND'

     it_fieldcat                           = lt_fieldcat

   TABLES

     t_outtab                             = lt_message

   EXCEPTIONS

     program_error                     = 1

     OTHERS                            = 2.