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: 

alv

Former Member
0 Kudos

how to write top-of -page in alv and can anyone give me the code for that program.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Manyavi,

Check out the below code

Sample ALV: Heading in ALV

With Compliments by: Ulhas Sonawane

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,

Chandru

8 REPLIES 8

Former Member
0 Kudos

hi Manyavi,

declare

DATA: T_LIST TYPE SLIS_T_LISTHEADER,

WA_LIST TYPE SLIS_LISTHEADER.

in 'REUSE_ALV_GRID_DISPLAY' mention

I_CALLBACK_PROGRAM = current program name

I_CALLBACK_TOP_OF_PAGE = mention a subroutie name( TOP_PAGE)

prepare the subroutine :

FORM TOP_PAGE.

CLEAR WA_LIST.

WA_LIST-TYP = 'H'.

WA_LIST-INFO = 'TOP OF PAGE'.

APPEND WA_LIST TO T_LIST.

WA_LIST-TYP = 'S'.

WA_LIST-KEY = 'NAME'.

WA_LIST-INFO = SY-REPID.

APPEND WA_LIST TO T_LIST.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = T_LIST

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

ENDFORM.

Reward if useful

Regards

ANUPAM

Former Member
0 Kudos

Hi Manyavi,

Check out the below code

Sample ALV: Heading in ALV

With Compliments by: Ulhas Sonawane

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,

Chandru

kesavadas_thekkillath
Active Contributor
0 Kudos

Only the top of page code is included ...reward if useful

DATA:IT_LIST_COMMENTS TYPE SLIS_T_LISTHEADER,

V_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE,

WK_EVENTS LIKE LINE OF V_EVENTS,

WK_LIST_COMMENTS LIKE LINE OF IT_LIST_COMMENTS.

CONSTANTS:C_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME

VALUE 'F_TOP_OF_PAGE'.

-


PERFORM BULID_EVENT.

Call FM

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

i_background_id = 'ALV_BACKGROUND'

IT_FIELDCAT = ALVFLD[]

IT_EVENTS = V_EVENTS[] <----


TABLES

T_OUTTAB = IT_STPO[].

IF SY-SUBRC <> 0.

ENDIF.

_____________

FORM BULID_EVENT .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = V_EVENTS[].

READ TABLE V_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO WK_EVENTS.

IF ( SY-SUBRC EQ 0 ).

MOVE C_FORMNAME_TOP_OF_PAGE TO WK_EVENTS-FORM.

MODIFY V_EVENTS FROM WK_EVENTS INDEX SY-TABIX.

ENDIF.

ENDFORM. " bulid_event

FORM F_TOP_OF_PAGE.

DATA:WK_PLAN(10) TYPE C.

CLEAR: IT_LIST_COMMENTS[].

WK_LIST_COMMENTS-TYP = TEXT-033. WK_LIST_COMMENTS-KEY = ''.

WK_LIST_COMMENTS-INFO = TEXT-002.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

WK_LIST_COMMENTS-TYP = TEXT-034. WK_LIST_COMMENTS-KEY = ''.

CONCATENATE TEXT-004 SO_MATNR INTO WK_LIST_COMMENTS-INFO SEPARATED

BY SPACE.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

WK_LIST_COMMENTS-TYP = TEXT-034. WK_LIST_COMMENTS-KEY = ''.

CONCATENATE TEXT-003 SO_WERKS INTO WK_LIST_COMMENTS-INFO SEPARATED

BY SPACE.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

WK_LIST_COMMENTS-TYP = TEXT-034. WK_LIST_COMMENTS-KEY = ''.

WK_PLAN = PA_PLNMG.

CONCATENATE TEXT-005 WK_PLAN INTO WK_LIST_COMMENTS-INFO SEPARATED

BY SPACE.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

I_LOGO = 'ENJOYSAP_LOGO'

IT_LIST_COMMENTARY = IT_LIST_COMMENTS.

ENDFORM. "F_TOP_OF_PAGE

Former Member
0 Kudos

HI,

data : eventstab type slis_t_event with header line.

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

Thanks

venkat

Former Member
0 Kudos

Hi

In order to insert a report heading in to the ALV grid you need to perform the following steps:

1. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include 'top-of-page' FORM

2. Create 'top-of-page' FORM

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

i_save = 'X'

tables

t_outtab = it_ekko

exceptions

program_error = 1

others = 2.

-


*

  • Form TOP-OF-PAGE *

----


  • ALV Report Header *

----


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 = 'Z_LOGO'.

endform.

Former Member
0 Kudos

Hi Manyavi,

Goto Se80 And package Slis And then see the programs. all the Programs with alv r there in that program.

Plzz reward points if it helps.

former_member402443
Contributor
0 Kudos

Hi Manyavi,

Check this example.

type-pools:slis.

data : it_fieldcat type slis_t_fieldcat_alv,

it_fieldcat1 type slis_t_fieldcat_alv.

data: begin of itab occurs 0,

vbeln like vbak-vbeln,

posnr like vbap-posnr,

end of itab.

data: begin of itab1 occurs 0,

vbeln like likp-vbeln,

posnr like lips-posnr,

vgbel like lips-vgbel,

vgpos like lips-vgpos,

end of itab1.

data: it_lips like itab1 occurs 0 with header line.

select vbeln posnr up to 1000 rows

from vbap

into table itab.

if sy-subrc = 0.

sort itab by vbeln .

select vbeln posnr vgbel vgpos into table

itab1 from lips for all entries in itab where vgbel = itab-vbeln

and vgpos = itab-posnr.

endif.

data: x_fieldcat type

slis_fieldcat_alv.

x_fieldcat-fieldname = 'VBELN'.x_fieldcat-tabname = 'ITAB'.

x_fieldcat-col_pos = 1.append x_fieldcat to it_fieldcat.

clear x_fieldcat.

x_fieldcat-fieldname = 'POSNR'.x_fieldcat-tabname = 'ITAB'.

x_fieldcat-col_pos = 1.append x_fieldcat to it_fieldcat.

clear x_fieldcat.

x_fieldcat-fieldname = 'VGBEL'.x_fieldcat-tabname = 'ITAB'.

x_fieldcat-col_pos = 1.append x_fieldcat to it_fieldcat.

clear x_fieldcat.

perform alv_grid_display.

&----


*& Form

*&----


**

*----


    • -->P_EXTAB

*----


form popup using p_extab type slis_t_extab.

set pf-status 'POPUP'.

endform.

*&----


**& Form

*&----


*----


    • -->R_UCOMM text* -->RS_SELFIELD

*----


form handle_user_command using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case r_ucomm.

when 'BACK' or 'CANC' or 'EXIT'.

leave to screen 0.

when '&IC1'.

set parameter id 'AUN' field rs_selfield-value.

call transaction 'VA03' and skip first screen.

when 'BUTTON'.

loop at it_fieldcat into x_fieldcat.

if x_fieldcat-fieldname = 'POSNR'.

x_fieldcat-no_out = 'X'.

modify it_fieldcat from x_fieldcat transporting no_out.

endif.

endloop.

rs_selfield-exit = 'X'.

perform alv_grid_display.

endcase.

endform.

"HANDLE_USER_COMMAND

&----


*& *text----


    • --> p1 text

  • <--

*----


form alv_grid_display .

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_callback_pf_status_set = 'POPUP'

i_callback_user_command = 'HANDLE_USER_COMMAND'

i_callback_top_of_page = 'TOP-OF-PAGE'

it_fieldcat = it_fieldcat

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

others = 2.

if

sy-subrc = 0.

endif.

endform. " alv_grid_display

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+10(15) = ' SY-REPID'.

*wa_header-info+21(10) = text-001.

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.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header.

endform.

Reward Points, if useful.

Regards,

Manoj Kumar

Former Member
0 Kudos

data:t_events TYPE slis_t_event,

t_events_ln LIKE LINE OF t_events,

c_form TYPE slis_formname VALUE 'TOP',

t_list_comments TYPE slis_t_listheader,

t_list_comments_ln LIKE LINE OF t_list_comments.

data:w_date(10) TYPE c,

w_time(10) TYPE c.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = t_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.

*

SORT t_events BY name form.

READ TABLE t_events WITH KEY slis_ev_top_of_page

INTO t_events_ln BINARY SEARCH.

IF sy-subrc = 0.

MOVE c_form TO t_events_ln-form.

MODIFY t_events FROM t_events_ln INDEX

sy-tabix TRANSPORTING form.

ENDIF.

&----


*& Form top

&----


  • text

----


FORM top.

WRITE sy-datum TO w_date MM/DD/YYYY.

WRITE sy-uzeit TO w_time .

CLEAR t_list_comments_ln.

t_list_comments_ln-typ = 'H'.

t_list_comments_ln-key = ''.

t_list_comments_ln-info = text-040.

APPEND t_list_comments_ln TO t_list_comments.

t_list_comments_ln-typ = 'S'.

t_list_comments_ln-key = text-041.

t_list_comments_ln-info = w_time.

APPEND t_list_comments_ln TO t_list_comments.

t_list_comments_ln-typ = 'S'.

t_list_comments_ln-key = text-042.

t_list_comments_ln-info = w_date.

APPEND t_list_comments_ln TO t_list_comments.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_list_comments

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

ENDFORM. "top

after this when calling function reuse_alv_grid_display give exporting parameter it_events = t_events[] in addition to usual parameters.

hope this is helpful.

only code for top of page is written.

reward points if useful.