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: 

Event in ALV

naren112
Explorer
0 Kudos
198

<b>Hi all ,

I want to write top of page in ALV report , I got the alv report working fine now plz tell how to do further coding for writing Top of page .

I am using function module .

Regards ,

Narender</b>

1 ACCEPTED SOLUTION

Former Member
0 Kudos
162

hi,

you can always search the forum, there are a lot of threads about this...but anyway, go thru this sample code..

data: SAT_EVENTS TYPE SLIS_T_EVENT.

FORM EVENTS .

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = SAT_EVENTS[].

READ TABLE SAT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO LS_EVENT.

IF SY-SUBRC = 0.

MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.

APPEND LS_EVENT TO SAT_EVENTS.

ENDIF.

ENDFORM. " EVENTS

FORM TOP_OF_PAGE.

DATA: T_HEADER TYPE SLIS_T_LISTHEADER,

WA_HEADER TYPE SLIS_LISTHEADER.

DATA: PLANT(4), PLANTN(30), PDAT LIKE MKPF-BUDAT, SLOC(4).

DATA: INFO(100).

DATA: GD_DATE(10), HD_DATE(10).

  • Title

WA_HEADER-TYP = 'H'.

WA_HEADER-INFO = 'This will come in top of page'.

APPEND WA_HEADER TO T_HEADER.

CLEAR WA_HEADER.

ENDFORM.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = T_HEADER

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SAT_REPID

IT_EVENTS = SAT_EVENTS[]

TABLES

T_OUTTAB = ITAB_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.

if helpful, reward

Sathish. R

9 REPLIES 9

Former Member
0 Kudos
162

Hi,

check this code.it will help u .

REPORT ZBHALV_LIST1.

TABLES:MARA.

SELECT-OPTIONS: MATNR FOR MARA-MATNR.

DATA:BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

ERSDA LIKE MARA-ERSDA,

MTART LIKE MARA-MTART,

MBRSH LIKE MARA-MBRSH,

END OF ITAB.

SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE MATNR

IN MATNR.

TYPE-POOLS SLIS.

DATA:FCAT TYPE slis_t_fieldcat_alv.

DATA:LAYOUT TYPE slis_layout_alv.

DATA:EVE TYPE slis_t_event WITH HEADER LINE.

DATA:HEAD TYPE slis_t_listheader WITH HEADER LINE.

DATA:SORT TYPE slis_t_sortinfo_alv WITH HEADER LINE.

SORT-UP = 'X'.

SORT-SPOS = 1.

SORT-FIELDNAME = 'ERSDA'.

SORT-tabname = 'MARA'.

APPEND SORT.

SORT-SPOS = 2.

SORT-FIELDNAME = 'MTART'.

SORT-tabname = 'MARA'.

APPEND SORT.

EVE-NAME = 'TOP_OF_PAGE'.

EVE-FORM = 'TOPOFPAGE'.

APPEND EVE.

EVE-NAME = 'TOP_OF_LIST'.

EVE-FORM = 'TOPOFLIST'.

APPEND EVE.

EVE-NAME = 'END_OF_LIST'.

EVE-FORM = 'ENDOFLIST'.

APPEND EVE.

LAYOUT-ZEBRA = 'X'.

LAYOUT-no_hline = 'X'.

LAYOUT-NO_VLINE = 'X'.

LAYOUT-window_titlebar = 'MATERIAL DETAILS'.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_INTERNAL_TABNAME = 'ITAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = SY-REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = FCAT

  • EXCEPTIONS

  • INCONSISTENT_INTERFACE = 1

  • PROGRAM_ERROR = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

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 = 'STATUS'

I_CALLBACK_USER_COMMAND = 'UCOMM'

  • I_STRUCTURE_NAME =

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = SORT[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = EVE[]

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 5

  • I_SCREEN_START_LINE = 5

  • I_SCREEN_END_COLUMN = 120

  • I_SCREEN_END_LINE = 25

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

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.

FORM TOPOFPAGE.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'MATERIALS'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[]

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

ENDFORM.

FORM TOPOFLIST.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'MATERIALS-LISTTOP'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[]

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

ENDFORM.

FORM ENDOFLIST.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'MATERIALS-LISTEND'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[]

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

ENDFORM.

FORM STATUS USING MYMENU.

SET PF-STATUS 'MENU'.

ENDFORM.

FORM UCOMM USING CODE STEXT.

CASE CODE.

WHEN 'ABC'.

WRITE:/ 'YOU HAVE CLICKED ON ABC'.

WHEN 'XYZ'.

WRITE:/ 'YOU HAVE CLICKED ON XYZ'.

ENDCASE.

ENDFORM.

regards,

bharat.

Former Member
0 Kudos
163

hi,

you can always search the forum, there are a lot of threads about this...but anyway, go thru this sample code..

data: SAT_EVENTS TYPE SLIS_T_EVENT.

FORM EVENTS .

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = SAT_EVENTS[].

READ TABLE SAT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO LS_EVENT.

IF SY-SUBRC = 0.

MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.

APPEND LS_EVENT TO SAT_EVENTS.

ENDIF.

ENDFORM. " EVENTS

FORM TOP_OF_PAGE.

DATA: T_HEADER TYPE SLIS_T_LISTHEADER,

WA_HEADER TYPE SLIS_LISTHEADER.

DATA: PLANT(4), PLANTN(30), PDAT LIKE MKPF-BUDAT, SLOC(4).

DATA: INFO(100).

DATA: GD_DATE(10), HD_DATE(10).

  • Title

WA_HEADER-TYP = 'H'.

WA_HEADER-INFO = 'This will come in top of page'.

APPEND WA_HEADER TO T_HEADER.

CLEAR WA_HEADER.

ENDFORM.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = T_HEADER

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SAT_REPID

IT_EVENTS = SAT_EVENTS[]

TABLES

T_OUTTAB = ITAB_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.

if helpful, reward

Sathish. R

p291102
Active Contributor
0 Kudos
162

HI,

REPORT YMS_ALVGRIDSAMPLE.

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

  • TABLES AND DATA DECLARATION.

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

*TABLES: mara,makt.",marc.

data syrepid like sy-repid.

data sydatum(10). " LIKE sy-datum.

data sypagno(3) type n.

  • WHEN USING MORE THAN ONE TABLE IN ALV WE NEEED TO DECLARE THE TYPE

  • GROUP (TYPE-POOLS--------->SLIS)

type-pools : slis.

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

  • INTERNAL TABLE DECLARATION.

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

  • INTERNAL TABLE TO HOLD THE VALUES FROM THE MARA TABLE

data: begin of t_mara occurs 0,

matnr like mara-matnr,

meins like mara-meins,

mtart like mara-mtart,

matkl like mara-matkl,

end of t_mara.

  • INTERNAL TABLE TO HOLD THE CONTENTS FROM THE EKKO TABLE

data : begin of t_marc occurs 0,

matnr like mara-matnr,

werks like marc-werks,

minbe like marc-minbe.

data: end of t_marc.

  • INTERNAL TABLE TO HOLD THE VALUES FROM MAKT TABLE.

data : begin of t_makt occurs 0,

matnr like mara-matnr,

maktx like makt-maktx,

spras like makt-spras,

end of t_makt.

  • INTERNAL TABLE WHICH ACTUALLY MERGES ALL THE OTHER INTERNAL TABLES.

data: begin of itab1 occurs 0,

matnr like mara-matnr,

meins like mara-meins,

maktx like makt-maktx,

spras like makt-spras,

werks like marc-werks,

minbe like marc-minbe,

end of itab1.

  • THE FOLLOWING DECLARATION IS USED FOR DEFINING THE FIELDCAT

  • AND THE LAYOUT FOR THE ALV.

  • HERE AS slis_t_fieldcat_alv IS A INTERNAL TABLE WITHOUT A HEADER LINE

  • WE EXPLICITELY DEFINE AN INTERNAL TABLE OF THE SAME STRUCTURE AS THAT

  • OF slis_t_fieldcat_alv BUT WITH A HEADER LINE IN THE DEFINITION.

  • THIS IS DONE TO MAKE THE CODE SIMPLER.

  • OTHERWISE WE MAY HAVE TO DEFINE THE STRUCTURE AS IN THE NORMAL SAP

  • PROGRAMS.

  • IN THE FIELDCATALOG TABLE WE ACTUALLY PASS THE FIELDS FROM ONE OR

  • MORE TABLES AND CREATE A STRUCTURE

  • IN THE LAYOUT STRUCTURE WE BASICALLY DEFINE THE FORMATTING OPTIONS

  • LIKE DISPLAY IN THE ZEBRA PATTERN ,THE HOTSPOT OPTIONS ETC.

data: fieldcatalog type slis_t_fieldcat_alv with header line,

fieldlayout type slis_layout_alv.

  • DECLARING THE EVENTTABLE INTERNL TABLE FOR USING EVENTS LIKE

  • TOP-OF-PAGE ETC.

data : eventstab type slis_t_event with header line.

  • DECLARING AN INTERNAL TABLE TO HOLD THE DATA FOR THE TOP-OF-PAGE

data : heading type slis_t_listheader with header line.

data : heading1 type slis_t_listheader with header line.

data : heading2 type slis_t_listheader with header line.

data : heading3 type slis_t_listheader with header line.

data : heading4 type slis_t_listheader with header line.

data : heading5 type slis_t_listheader with header line.

data : heading6 type slis_t_listheader with header line.

data : heading7 type slis_t_listheader with header line.

data : heading8 type slis_t_listheader with header line.

  • STRUCTURE TO PASS THE COLOR ATTRIBUTES FOR DISPLAY.

data : colorstruct type slis_coltypes.

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

  • INITIALIZATION. *

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

initialization.

syrepid = sy-repid.

sypagno = sy-pagno.

clear fieldcatalog.

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

  • START-OF-SELECTION. *

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

start-of-selection.

  • SUBROUTINE TO POPULATE THE COLORSTRUCT

perform fill_colorstruct using colorstruct.

  • SUBROUTINE TO POPULATE THE FIELDS OF THE FIELD CATALOGUE

perform populate_fieldcatalog.

  • SUBROUTINE TO SELECT DATA FROM VARIOUS TABLES AND POPULATE IT IN THE

  • INTERNAL TABLE.

perform selectdata_and_sort.

  • SUBROUTINE TO POPULATE THE LAYOUT STRUCTURE.

perform populate_layout using fieldlayout.

  • SUBROUTINE TO CALL THE FUNCTION MERGE TO ENSURE PROPER DISPLAY.

perform merge_fieldcatalog.

  • SUBROUTINE TO POPULATE THE EVENTSTAB.

perform fill_eventstab tables eventstab.

  • SUBROUTINE TO POPULATE THE HEADING TABLES.

perform fill_headingtable tables heading using 'HEADING'.

perform fill_headingtable tables heading1 using 'HEADING1'.

perform fill_headingtable tables heading2 using 'HEADING2'.

perform fill_headingtable tables heading3 using 'HEADING3'.

perform fill_headingtable tables heading4 using 'HEADING4'.

perform fill_headingtable tables heading5 using 'HEADING5'.

perform fill_headingtable tables heading6 using 'HEADING6'.

perform fill_headingtable tables heading7 using 'HEADING7'.

perform fill_headingtable tables heading8 using 'HEADING8'.

  • SUBROUTINE TO DISPLAY THE LIST.

perform display_alv_list.

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

  • FORMS

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

  • IN THIS SUBROUTINE WE POPULATE THE FIELDCATALOG TABLE WITH THE NAMES

  • OF THE TABLE,FIELDNAME,WHETHER IT IS KEY FIELD OR NOT,HEADING AND

  • COLUMN JUSTIFICATION.

form populate_fieldcatalog.

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'MATNR' 'X' .

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'MEINS' ' '.

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'MAKTX' ' ' .

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'MTART' ' ' .

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'MATKL' ' ' .

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'SPRAS' ' ' .

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'WERKS' ' ' .

perform fill_fields_of_fieldcatalog tables fieldcatalog

using 'ITAB1' 'MINBE' ' ' .

endform. " POPULATE_FIELDCATALOG

----


  • FORM FILL_FIELDS_OF_FIELDCATALOG *

----


  • ........ *

----


  • --> FIELDCATALOG *

  • --> P_TABNAME *

  • --> P_FIELDNAME *

  • --> P_KEY *

  • --> P_KEY *

----


form fill_fields_of_fieldcatalog tables fieldcatalog

structure fieldcatalog

using p_tabname

p_fieldname

p_key.

  • p_no_out.

fieldcatalog-tabname = p_tabname.

fieldcatalog-fieldname = p_fieldname.

fieldcatalog-key = p_key.

fieldcatalog-emphasize = '1234'.

*fieldcatalog-no_out = p_no_out.

append fieldcatalog.

endform. " FILL_FIELDSOFFIELDCATALOG

----


  • FORM POPULATE_LAYOUT *

----


  • ........ *

----


  • --> FIELDLAYOUT *

----


form populate_layout using fieldlayout type slis_layout_alv.

fieldlayout-f2code = '&ETA' .

fieldlayout-zebra = 'X'.

  • FOR THE WINDOW TITLE.

fieldlayout-window_titlebar = 'ALV with Events'.

fieldlayout-colwidth_optimize = 'X'.

fieldlayout-no_vline = ' '.

*fieldlayout-no_input = 'X'.

fieldlayout-confirmation_prompt = ''.

fieldlayout-key_hotspot = 'X'.

  • This removes the column headings if the flag is set to 'X'

fieldlayout-no_colhead = ' '.

*fieldlayout-hotspot_fieldname = 'MAKTX'.

fieldlayout-detail_popup = 'X'.

  • fieldlayout-coltab_fieldname = 'X'.

endform. " POPULATE_LAYOUT

----


  • FORM SELECTDATA_AND_SORT *

----


  • ........ *

----


form selectdata_and_sort.

select matnr meins mtart matkl from mara

into corresponding fields of t_mara

up to 500 rows .

select matnr maktx spras from makt

into corresponding fields of t_makt

where matnr = t_mara-matnr and

spras = sy-langu.

select matnr werks minbe from marc

into corresponding fields of t_marc

where matnr = t_mara-matnr.

append t_marc.

endselect.

append t_makt.

endselect.

append t_mara.

endselect.

perform populate_itab1.

sort itab1 by matnr.

endform. " SELECTDATA_AND_SORT

----


  • FORM MERGE_FIELDCATALOG *

----


  • ........ *

----


form merge_fieldcatalog.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = syrepid

i_internal_tabname = 'ITAB1'

  • i_structure_name = 'COLORSTRUCT'

  • I_CLIENT_NEVER_DISPLAY = 'X'

i_inclname = syrepid

changing

ct_fieldcat = fieldcatalog[]

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

endform. " MERGE_FIELDCATALOG

  • IN THIS FUNCTION THE MINIMUM PARAMETERS THAT WE NEED TO PASS IS AS

  • FOLLOWS:-

  • i_callback_program --> CALLING PROGRAM NAME

  • i_structure_name --> STRUCTURE NAME.

  • is_layout --> LAYOUT NAME.

  • it_fieldcat ---> BODY OF THE FIELD CATALOGUE INTERNAL TABLE

form display_alv_list.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

  • I_INTERFACE_CHECK = ' '

i_callback_program = syrepid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

i_structure_name = 'ITAB1'

is_layout = fieldlayout

it_fieldcat = fieldcatalog[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • THE FOLLOWING PARAMETER IS SET AS 'A' INORDER TO DISPLAY THE STANDARD

  • TOOL BAR

i_save = 'A'

  • IS_VARIANT = ' '

it_events = eventstab[]

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • 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 = itab1

exceptions

program_error = 1

others = 2.

endform. " DISPLAY_ALV_LIST

&----


*& Form POPULATE_ITAB1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form populate_itab1.

loop at t_mara.

loop at t_makt where matnr = t_mara-matnr.

loop at t_marc where matnr = t_mara-matnr.

move-corresponding t_mara to itab1.

move-corresponding t_makt to itab1.

move-corresponding t_marc to itab1.

append itab1.

endloop.

endloop.

endloop.

endform. " POPULATE_ITAB1

&----


*& Form FILL_EVENTSTAB

&----


  • text

----


  • -->P_EVENTSTAB text *

----


form fill_eventstab tables p_eventstab structure eventstab.

  • WHEN THE FOLLOWING FUNCTION IS CALLED THE SYSTEM POPULATES THE

  • INTERNAL TABLE EVENTSTAB WITH A LIST OF EVENTS NAME.

  • AS SHOWN BELOW WHEN USING I_LIST_TYPE = 0 THE FUNCTION RETURNS 14

  • EVENTS NAME.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = p_eventstab[]

exceptions

list_type_wrong = 1

others = 2.

  • BY CALLING THE ABOVE FUNCTION WE FIRST POPULATE THE EVENTSTAB WITH

  • THE PREDEFINED EVENTS AND THEN WE MOVE THE FORM NAME AS SHOWN BELOW.

  • WE ASSIGN A FORM NAME TO THE EVENT AS REQUIRED BY THE USER.

  • FORM NAME CAN BE ANYTHING.THE PERFORM STATEMENT FOR THIS FORM

  • IS DYNAMICALY CALLED.

read table p_eventstab with key name = slis_ev_top_of_page.

if sy-subrc = 0 .

move 'TOP_OF_PAGE' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_top_of_coverpage.

if sy-subrc = 0 .

move 'TOP_OF_COVERPAGE' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_end_of_coverpage .

if sy-subrc = 0 .

move 'END_OF_COVERPAGE' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_foreign_top_of_page.

if sy-subrc = 0 .

move 'FOREIGN_TOP_OF_PAGE' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_foreign_end_of_page.

if sy-subrc = 0 .

move 'FOREIGN_END_OF_PAGE' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_list_modify.

if sy-subrc = 0 .

move 'LIST_MODIFY' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_top_of_list.

if sy-subrc = 0 .

move 'TOP_OF_LIST' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_end_of_page.

if sy-subrc = 0 .

move 'END_OF_PAGE' to p_eventstab-form.

append p_eventstab.

endif.

read table p_eventstab with key name = slis_ev_end_of_list .

if sy-subrc = 0 .

move 'END_OF_LIST' to p_eventstab-form.

append p_eventstab.

endif.

endform. " FILL_EVENTSTAB

&----


*& Form FILL_HEADINGTABLE

&----


  • text

----


  • -->P_HEADING text *

----


form fill_headingtable tables p_heading structure heading

using tablename.

case tablename.

when 'HEADING'.

p_heading-typ = 'H'.

concatenate

' REPORT NAME:-' syrepid

' ABB Industry Pte Ltd' into p_heading-info.

append p_heading.

write sy-datum using edit mask '__/__/____' to sydatum.

concatenate

' DATE:-' sydatum ' USER: ' sy-uname 'PAGE NO:' sypagno

into p_heading-info.

append p_heading.

when 'HEADING1'.

p_heading-typ = 'H'.

p_heading-info = 'TOP-OF-COVER-PAGE'.

append p_heading.

when 'HEADING2'.

p_heading-typ = 'H'.

p_heading-info = 'END-OF-COVER-PAGE'.

append p_heading.

when 'HEADING3'.

p_heading-typ = 'H'.

p_heading-info = 'FOREIGN-TOP-OF-PAGE'.

append p_heading.

when 'HEADING4'.

p_heading-typ = 'H'.

p_heading-info = 'FOREIGN-END-OF-PAGE'.

append p_heading.

  • WHEN 'HEADING5'.

  • P_HEADING-TYP = 'H'.

  • P_HEADING-INFO = 'LIST-MODIFY'.

  • APPEND P_HEADING.

when 'HEADING6'.

p_heading-typ = 'H'.

p_heading-info = 'END-OF-PAGE'.

append p_heading.

when 'HEADING7'.

p_heading-typ = 'H'.

p_heading-info = 'END-OF-LIST'.

append p_heading.

when 'HEADING8'.

p_heading-typ = 'H'.

p_heading-info = 'TOP-OF-LIST'.

append p_heading.

endcase.

endform. " FILL_HEADINGTABLE

----


  • FORM TOP_OF_PAGE *

----


  • ........ *

----


form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading[]

exceptions

others = 1.

endform.

&----


*& Form FILL_COLORSTRUCT

&----


  • text

----


  • -->P_COLORSTRUCT text *

----


form fill_colorstruct using p_colorstruct type slis_coltypes .

p_colorstruct-heacolfir-col = 6.

p_colorstruct-heacolfir-int = 1.

p_colorstruct-heacolfir-inv = 1.

endform. " FILL_COLORSTRUCT

----


  • FORM TOP_OF_COVERPAGE *

----


  • ........ *

----


form top_of_coverpage.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading1[]

exceptions

others = 1.

endform.

----


  • FORM END_OF_COVERPAGE *

----


  • ........ *

----


form end_of_coverpage.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading2[]

exceptions

others = 1.

endform.

----


  • FORM FOREIGN_TOP_OF_PAGE *

----


  • ........ *

----


form foreign_top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading3[]

exceptions

others = 1.

endform.

----


  • FORM FOREIGN_END_OF_PAGE *

----


  • ........ *

----


form foreign_end_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading4[]

exceptions

others = 1.

endform.

----


  • FORM LIST_MODIFY *

----


  • ........ *

----


*FORM LIST_MODIFY.

  • CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

  • EXPORTING

  • IT_LIST_COMMENTARY = HEADING5[]

  • EXCEPTIONS

  • OTHERS = 1.

*ENDFORM.

----


  • FORM END_OF_PAGE *

----


  • ........ *

----


form end_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading6[]

exceptions

others = 1.

endform.

----


  • FORM END_OF_LIST *

----


  • ........ *

----


form end_of_list.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading7[]

exceptions

others = 1.

endform.

----


  • FORM TOP_OF_LIST *

----


  • ........ *

----


form top_of_list.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading8[]

exceptions

others = 1.

endform.

*--- End of Program

Thanks,

Sankar M

Former Member
0 Kudos
162

HI..,

<b>This is the case for ALV List display...</b>

data :

t_events type SLIS_T_EVENT,

w_event type slis_alv_event.

*Populating the events table.....

w_event-name = 'TOP_OF_PAGE'.

w_event-form = 'TOP_PAGE'.

append w_event to t_events.

call function 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = sy-repid

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'STABLE'

I_STRUCTURE_NAME = 'YCHVIEW_FLUGTERM'

  • IS_LAYOUT =

  • IT_FIELDCAT =

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_EVENTS = t_events

IT_EVENT_EXIT = t_event_exit

tables

t_outtab = t_flight

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

if sy-subrc <> 0.

endif.

form top_page.

write : 'This is the top of page'.

endform.

<b>

When u r using the Grid display u need to use another function module in the top_page form...</b>

data:

fs_top_page type slis_listheader,

t_top_page type slis_t_listheader.

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = sy-repid

I_CALLBACK_TOP_OF_PAGE = 'TOP_PAGE'

IT_FIELDCAT = t_fieldcat

tables

t_outtab = t_out_tab

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 top_page.

fs_top_page-typ = 'S'.

fs_top_page-info = 'Session : Z640_FPRICE'(015).

append fs_top_page to t_top_page.

fs_top_page-typ = 'S'.

fs_top_page-info = W_QID.

append fs_top_page to t_top_page.

<i> CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = t_top_page.</i>

ENDFORM. " Form top_page.

<b>

    • Reward all helpful answers..

sai ramesh</b>

ChandrashekharMahajan
Active Contributor
0 Kudos
162

Hi Narendar,

find the attached sample code for your ref. search for top-of-page.

report zus_alv_demo_grid .

tables: ekko.

type-pools: slis.

types: begin of t_ekko,

ebeln type ekpo-ebeln,

ebelp type ekpo-ebelp,

statu type ekpo-statu,

aedat type ekpo-aedat,

matnr type ekpo-matnr,

menge type ekpo-menge,

meins type ekpo-meins,

netpr type ekpo-netpr,

peinh type ekpo-peinh,

line_color(4) type c, "Used to store row color

end of t_ekko.

data: it_ekko type standard table of t_ekko initial size 0,

wa_ekko type t_ekko.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid.

  • Data declaration for EVENT and PRINT PARAMETER.

data: gt_events type slis_t_event,

gd_prntparams type slis_print_alv.

  • data declaration for sorting.

data : it_sortcat type slis_sortinfo_alv occurs 1,

wa_sort like line of it_sortcat.

data : i_list_comments type slis_t_listheader.

start-of-selection.

perform data_retrieval.

  • perform user_command.

perform build_fieldcatalog.

perform build_layout.

perform build_events.

perform build_print_params.

perform build_sortcat.

perform display_alv_report.

end-of-selection.

*TOP-OF-PAGE.

  • PERFORM top-of-page.

end-of-page.

*&----


*& Form build_fieldcatalog

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form build_fieldcatalog.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'EBELP'.

fieldcatalog-seltext_m = 'PO Item'.

fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'STATU'.

fieldcatalog-seltext_m = 'Status'.

fieldcatalog-col_pos = 2.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.

fieldcatalog-seltext_m = 'Item change date'.

fieldcatalog-col_pos = 3.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material Number'.

fieldcatalog-col_pos = 4.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.

fieldcatalog-seltext_m = 'PO quantity'.

fieldcatalog-col_pos = 5.

fieldcatalog-do_sum = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.

fieldcatalog-seltext_m = 'Order Unit'.

fieldcatalog-col_pos = 6.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-datatype = 'CURR'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'PEINH'.

fieldcatalog-seltext_m = 'Price Unit'.

fieldcatalog-col_pos = 8.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " build_fieldcatalog

*&----


*& Form build_layout

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • Set layout field for row attributes(i.e. color)

gd_layout-info_fieldname = 'LINE_COLOR'.

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for

*when double

  • "click(press f2)*

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

endform. " build_layout

*&----


*& Form data_retrieval

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form data_retrieval.

data: ld_color(1) type c.

select ebeln ebelp statu aedat matnr menge meins netpr

peinh from ekpo into table it_ekko.

*Populate field with color attributes

loop at it_ekko into wa_ekko.

  • Populate color variable with colour properties

  • Char 1 = C (This is a color property)

  • Char 2 = 3 (Color codes: 1 - 7)

  • Char 3 = Intensified on/off ( 1 or 0 )

  • Char 4 = Inverse display on/off ( 1 or 0 )

  • i.e. wa_ekko-line_color = 'C410'

ld_color = ld_color + 1.

  • Only 7 colours so need to reset color value

if ld_color = 8.

ld_color = 1.

endif.

concatenate 'C' ld_color '10' into wa_ekko-line_color.

  • wa_ekko-line_color = 'C410'.

modify it_ekko from wa_ekko.

endloop.

endform. " data_retrieval

*&----


*& Form display_alv_report

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

is_layout = gd_layout

i_callback_top_of_page = 'TOP-OF-PAGE'

i_callback_user_command = 'USER_COMMAND'

i_callback_pf_status_set = 'SET_PF_STATUS'

it_event = gt_events

is_print = gd_prntparams

it_fieldcat = fieldcatalog[]

it_sort = it_sortcat

i_save = 'X'

tables

t_outtab = it_ekko

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_ALV_REPORT

*&----


*& Form user_command

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


*&----


*& Form top-of-page

*&----


  • text

*----


  • --> p1 text

  • <-- p2 text

*----


form top-of-page.

*ALV Header declarations

data: t_header type slis_t_listheader,

wa_header type slis_listheader,

t_line like wa_header-info,

ld_lines type i,

ld_linesc(10) type c.

  • Title

wa_header-typ = 'H'.

wa_header-info = 'EKKO Table Report'.

append wa_header to t_header.

clear wa_header.

  • Date

wa_header-typ = 'S'.

wa_header-key = 'Date: '.

concatenate sy-datum+6(2) '.'

sy-datum+4(2) '.'

sy-datum(4) into wa_header-info."todays date

append wa_header to t_header.

clear: wa_header.

  • Total No. of Records Selected

describe table it_ekko lines ld_lines.

ld_linesc = ld_lines.

concatenate 'Total No. of Records Selected: ' ld_linesc

into t_line separated by space.

wa_header-typ = 'A'.

wa_header-info = t_line.

append wa_header to t_header.

clear: wa_header, t_line.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = t_header

i_logo = 'GANESH_LOGO'.

endform. " top-of-page

----


  • FORM user_command *

----


  • ........ *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


form user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case r_ucomm.

when '&IC1'.

if rs_selfield-fieldname = 'EBELN'.

read table it_ekko into wa_ekko index rs_selfield-tabindex.

set parameter id 'BES' field wa_ekko-ebeln.

call transaction 'ME23N' and skip first screen.

endif.

when 'ULHAS'.

if rs_selfield-fieldname = 'EBELN'.

read table it_ekko into wa_ekko index rs_selfield-tabindex.

set parameter id 'BES' field wa_ekko-ebeln.

call transaction 'ME23N' and skip first screen.

endif.

endcase.

endform.

----


  • FORM set_pf_status *

----


  • ........ *

----


  • --> RT_EXTAB *

----


form set_pf_status using rt_extab type slis_t_extab.

set pf-status 'ZNEWSTATUS'.

endform.

&----


*& Form build_events

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_events.

data: ls_event type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 0

importing

et_events = gt_events[]

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

read table gt_events with key name = slis_ev_end_of_page

into ls_event.

if sy-subrc = 0.

move 'END_OF_PAGE' to ls_event-form.

append ls_event to gt_events.

endif.

read table gt_events with key name = slis_ev_end_of_list

into ls_event.

if sy-subrc = 0.

move 'END_OF_LIST' to ls_event-form.

append ls_event to gt_events.

endif.

endform. " build_events

&----


*& Form build_print_params

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_print_params.

gd_prntparams-reserve_lines = '3'. "Lines reserved for footer

gd_prntparams-no_coverpage = 'X'.

endform. " build_print_params

----


  • FORM END_OF_PAGE *

----


  • ........ *

----


form end_of_page.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

write: sy-uline(50).

skip. write:/40 'Page:', sy-pagno .

endform.

----


  • FORM END_OF_LIST *

----


  • ........ *

----


form end_of_list.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

skip. write:/40 'Page:', sy-pagno .

endform.

&----


*& Form build_sortcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_sortcat.

wa_sort-spos = 1.

wa_sort-fieldname = 'EBELN'.

append wa_sort to it_sortcat.

wa_sort-spos = 2.

wa_sort-fieldname = 'EBELP'.

append wa_sort to it_sortcat.

endform. " build_sortcat

Regards,

Chandra

(Award points if helpful)

Former Member
0 Kudos
162

HI

try the following code n plz let me know if this is what u r looking 4.............

report yh_alv_pages.

type-pools: slis.

data: w_index type i value 1,

w_carrid type spfli-carrid..

data: fieldcat type slis_t_fieldcat_alv,

fieldcat_ln like line of fieldcat,

sortcat type slis_t_sortinfo_alv,

sortcat_ln like line of sortcat,

eventcat type slis_t_event,

eventcat_ln like line of eventcat,

fs_layout type slis_layout_alv,

t_layout like standard table

of fs_layout.

data:

fs_spfli type spfli.

data:

t_spfli like standard table

of fs_spfli.

select *

from spfli

into table t_spfli.

perform sort_cat.

perform build_eventcat.

perform start_list_viewer.

&----


*& Form BUILD_EVENTCAT

&----


  • text

----


form build_eventcat.

eventcat_ln-name = 'TOP_OF_PAGE'.

eventcat_ln-form = 'PAGE_HEADER'.

append eventcat_ln to eventcat.

eventcat_ln-name = 'END_OF_PAGE'.

eventcat_ln-form = 'PAGE_FOOTER'.

append eventcat_ln to eventcat.

endform. "BUILD_EVENTCAT

&----


*& Form page_header

&----


  • text

----


form page_header.

do.

read table t_spfli index w_index into fs_spfli.

add 1 to w_index.

if sy-subrc ne 0.

exit.

elseif w_carrid ne fs_spfli-carrid.

w_carrid = fs_spfli-carrid.

exit.

endif.

enddo.

write: w_carrid.

endform. "page_header

&----


*& Form page_footer

&----


  • text

----


form page_footer.

write:/ 'page_footer' color 4.

endform. "page_header

&----


*& Form sort_cat

&----


  • text

----


form sort_cat.

sortcat_ln-fieldname = 'CARRID'.

sortcat_ln-group = '*'.

sortcat_ln-up = 'X'.

append sortcat_ln to sortcat.

endform. "sort_cat

&----


*& Form START_LIST_VIEWER

&----


  • text

----


form start_list_viewer.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_callback_program = sy-repid

i_structure_name = 'SPFLI'

it_sort = sortcat

it_events = eventcat

tables

t_outtab = t_spfli

exceptions

program_error = 1

others = 2.

if sy-subrc ne 0.

write: / sy-subrc.

endif.

endform. "START_LIST_VIEWER

reward if helpful.

regards,

kiran kumar k

former_member533584
Contributor
0 Kudos
162

hai,

use function module <b>'REUSE_ALV_COMMENTARY_WRITE'</b>

REPORT YH649_ALV_TEST_LOGO.

TYPE-POOLS SLIS.

data T_LIST_COMMENTARY TYPE SLIS_T_LISTHEADER.

DATA FS_LIST_COMMENTARY LIKE LINE OF T_LIST_COMMENTARY.

FS_LIST_COMMENTARY-TYP = 'S'.

FS_LIST_COMMENTARY-KEY = 'ANANTH'.

FS_LIST_COMMENTARY-INFO = 'ANANTH KUMAR SUDANI'.

APPEND FS_LIST_COMMENTARY TO T_LIST_COMMENTARY.

DATA:

T_FLIGHT LIKE TABLE OF SFLIGHT,

T_EVENT TYPE SLIS_T_EVENT ,

FS_EVENT TYPE LINE OF SLIS_T_EVENT.

FS_EVENT-NAME = 'TOP_OF_PAGE'.

FS_EVENT-FORM = 'TOP'.

APPEND FS_EVENT TO T_EVENT.

CLEAR FS_EVENT.

SELECT *

FROM SFLIGHT

INTO TABLE T_FLIGHT UP TO 100 ROWS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_STRUCTURE_NAME = 'SFLIGHT'

I_CALLBACK_PROGRAM = 'YH649_ALV_TEST_LOGO'

  • IS_LAYOUT = IS_LAYOUT

IT_EVENTS = T_EVENT

  • IT_SORT = T_SORTCAT

  • IT_EVENT_EXIT = IT_EVENT_EXIT

TABLES

T_OUTTAB = T_FLIGHT

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 TOP.

CALL FUNCTION <b>'REUSE_ALV_COMMENTARY_WRITE'</b>

EXPORTING

IT_LIST_COMMENTARY = T_LIST_COMMENTARY

I_LOGO = 'ENJOYSAP_LOGO'

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

ENDFORM.

regards,

ananth

former_member673464
Active Contributor
0 Kudos
162

Hi narendra,

You can use events to trigger in alv using call bcak program and declaring the name of the event and the subroutine name.

use it_events for top of page triggering.

In subroutine use reuse_alv_commentary_write.

regards,

veeresh

Former Member
0 Kudos
162

hi

good

use the following process,

go to SE38

put BCALV* and press F4

you ll find lots of example related to ALV,test them and use them accordingly.

Thanks

mrutyun^