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: 

Top of page in ALV

Former Member
0 Kudos
109

hi all,

how do we handle top-of-page in ALV using function module?

Thanks,

Rakesh.

6 REPLIES 6

Former Member
0 Kudos
73

In Fm 'Reuse_alv_grid_display' under exporting we have a parameter by name ' I_CALLBACK_TOP_OF_PAGE '.

assign I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

write an event TOP_OF_PAGE in ur report program.

Under this event u can write ur Display heading of ALV or other displays.

or use.

REUSE_ALV_COMMENTARY_WRITE

Awrd points if useful

bhupal

Former Member
0 Kudos
73

former_member402443
Contributor
0 Kudos
73

Hi Rakesh,

Check this code yaar.

This is gives you an idea of how to handle Top of page in alv grid.

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
73

hi Rakesh,

This is kiran kumar.G. i will send some code for u.plz check it once.In That we have to see Events form

and REUSE_ALV_COMMENTRY_WRITE .BLOCK ur problem is solved..ok..

code:

&----


*& Report ZALV_LISTDISP_INTERACTIVE *

*& *

&----


*& DEVELOPER : KIRAN KUMAR.G *

*& PURPOSE : DISPLAYING A PURCHASE ORDER INFORMATION

*& CREATION DATE : 2/11/2007

&----


REPORT zalv_listdisp_interactive .

----


  • Tables

----


TABLES : ekko, "Purchasing Document Header

ekpo. "Purchasing Document Item

----


  • Type pools

----


TYPE-POOLS: slis.

----


  • Internal Tables

----


DATA: BEGIN OF gt_header OCCURS 0,

ebeln LIKE ekko-ebeln, " Purchasing Document Number

bukrs LIKE ekko-bukrs, " Company Code

bstyp LIKE ekko-bstyp, " Purchasing Document Category

bsart LIKE ekko-bsart, " Purchasing Document LIKE

aedat LIKE ekko-aedat, " Date on which the recordwascreate

ernam LIKE ekko-ernam, " Name of Person who Created Object

lifnr LIKE ekko-lifnr, " Vendor's account number

spras LIKE ekko-spras, " Language Key

ekorg LIKE ekko-ekorg, " Purchasing Organization

ekgrp LIKE ekko-ekgrp, " Purchasing group

END OF gt_header.

DATA: BEGIN OF gt_item OCCURS 0,

matnr LIKE ekpo-matnr, "Material Number

werks LIKE ekpo-werks, "Plant

lgort LIKE ekpo-lgort, "Storage location

matkl LIKE ekpo-matkl, "Material group

menge LIKE ekpo-menge, "Purchase order quantity

meins LIKE ekpo-meins, "Order unit

netpr LIKE ekpo-netpr, "Net price in purchasing document

kunnr LIKE ekpo-kunnr, "Customer Number 1

END OF gt_item.

----


  • Global Structures

----


DATA: it_header TYPE slis_t_listheader, "For Headings

wa_header TYPE slis_listheader,

it_fieldcat TYPE slis_t_fieldcat_alv, "Structure Defintion

wa_fieldcat TYPE slis_fieldcat_alv,

it_fieldcat1 TYPE slis_t_fieldcat_alv,

wa_fieldcat1 TYPE slis_fieldcat_alv,

wa_layout TYPE slis_layout_alv, "Layout

it_events TYPE slis_t_event, "For Events

wa_events TYPE slis_alv_event.

----


  • Selection Screen

----


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

SELECT-OPTIONS : s_ebeln FOR ekko-ebeln.

SELECTION-SCREEN: END OF BLOCK b1.

----


  • Initialization

----


INITIALIZATION.

PERFORM initial.

----


  • Fetch Data

----


START-OF-SELECTION.

PERFORM fetch_data.

END-OF-SELECTION.

  • Bulid fieldcatalog

PERFORM fieldcat.

  • Change fieldcatalog

PERFORM fieldcat_change.

  • Events Triggering

PERFORM place_events.

  • Layout.

PERFORM layout.

----


  • Display Data

----


SORT gt_header BY ebeln.

PERFORM display_list.

&----


*& Form initial

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM initial .

s_ebeln-sign = 'I'.

s_ebeln-option = 'BT'.

s_ebeln-low = '3000000090'.

s_ebeln-high = '3000000166'.

APPEND s_ebeln.

ENDFORM. " initial

&----


*& Form fetch_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fetch_data .

REFRESH gt_header. "Clear the Body of Internal Table

CLEAR gt_header. "Clear Header Line

SELECT ebeln

bukrs

bstyp

bsart

aedat

ernam

lifnr

spras

ekorg

ekgrp

FROM ekko

INTO TABLE gt_header

WHERE ebeln IN s_ebeln.

ENDFORM. " fetch_data

&----


*& Form display_list

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_list .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

i_callback_program = sy-cprog

  • I_CALLBACK_PF_STATUS_SET = ' '

i_callback_user_command = 'USERCOMMAND'

  • I_STRUCTURE_NAME =

is_layout = wa_layout

it_fieldcat = it_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

it_events = 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 = gt_header

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_list

&----


*& Form place_events

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM place_events .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

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

CLEAR wa_events. "Clear Header Line

READ TABLE it_events INTO wa_events WITH KEY name = 'TOP_OF_PAGE'.

IF sy-subrc = 0.

wa_events-form = 'HEADING'.

MODIFY it_events FROM wa_events INDEX sy-tabix.

ENDIF.

CLEAR wa_events. "Clear Header Line

READ TABLE it_events INTO wa_events WITH KEY name = 'END_OF_LIST'.

IF sy-subrc = 0.

wa_events-form = 'PAGEDOWN'.

MODIFY it_events FROM wa_events INDEX sy-tabix.

ENDIF.

CLEAR wa_events. "Clear Header Line

READ TABLE it_events INTO wa_events WITH KEY name = 'USER_COMMAND'.

IF sy-subrc = 0.

wa_events-form = 'USERCOMMAND'.

MODIFY it_events FROM wa_events INDEX sy-tabix.

ENDIF.

ENDFORM. " place_events

&----


*& Form layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM layout .

CLEAR wa_layout. "Clear Header Line

wa_layout-zebra = 'X'. "Zebra Lines in the Output

wa_layout-colwidth_optimize = 'X'. "Optimize the Column Width

ENDFORM. " layout

&----


*& Form heading

&----


  • text

----


FORM heading.

WRITE:/6 'THIS REPORT DISPLAYS THE PURCHASE ORDER DETAILS'.

WRITE:/6 'CLICK ON PURCHASE DOC NO FIELD(INTERACTIVE LIST)'.

ENDFORM. "heading

&----


*& Form fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fieldcat .

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-cprog

i_internal_tabname = 'GT_HEADER'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

i_inclname = sy-cprog

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

ct_fieldcat = it_fieldcat

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.

ENDFORM. " fieldcat

&----


*& Form fieldcat_change

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fieldcat_change .

LOOP AT it_fieldcat INTO wa_fieldcat.

CASE wa_fieldcat-fieldname.

WHEN 'EBELN'.

wa_fieldcat-hotspot = 'X'.

ENDCASE.

MODIFY it_fieldcat FROM wa_fieldcat INDEX sy-tabix.

ENDLOOP.

ENDFORM. " fieldcat_change

&----


*& Form pagedown

&----


  • text

----


FORM pagedown.

WRITE:/35 'HAVE A NICE DAY...' COLOR 4.

ENDFORM. "pagedown

&----


*& Form usercommand

&----


  • text

----


  • -->UCOMM text

  • -->SELFIELD text

----


FORM usercommand USING ucomm LIKE sy-ucomm selfield TYPE slis_selfield.

READ TABLE gt_header INDEX selfield-tabindex.

CASE selfield-sel_tab_field.

WHEN 'GT_HEADER-EBELN'.

REFRESH : gt_item.

CLEAR : gt_item.

SELECT matnr

werks

lgort

matkl

menge

meins

netpr

kunnr

FROM ekpo

INTO TABLE gt_item

WHERE ekpo~ebeln EQ gt_header-ebeln.

*Build a Field Catalog

PERFORM fieldcat1.

*For Heading in the Interactive List

PERFORM heading1.

*Display Interactive Data

PERFORM display_data1.

ENDCASE.

ENDFORM. "usercommand

&----


*& Form fieldcat1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fieldcat1 .

REFRESH : it_fieldcat1.

CLEAR : wa_fieldcat1.

wa_fieldcat1-col_pos = '1'. "Column Postion

wa_fieldcat1-fieldname = 'MATNR'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal Table

wa_fieldcat1-key = 'X'. "Blue Color

wa_fieldcat1-seltext_l = 'MATERIAL NO'. "Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

wa_fieldcat1-col_pos = '2'. "Column Postion

wa_fieldcat1-fieldname = 'WERKS'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal Table

wa_fieldcat1-seltext_l = 'PLANT'. "Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

wa_fieldcat1-col_pos = '3'. "Column Postion

wa_fieldcat1-fieldname = 'LGORT'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal Table

wa_fieldcat1-seltext_l = 'STORAGE LOCATION'."Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

wa_fieldcat1-col_pos = '4'. "Column Postion

wa_fieldcat1-fieldname = 'MATKL'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal Table

wa_fieldcat1-seltext_l = 'MATERIAL GRP'. "Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

wa_fieldcat1-col_pos = '5'. "Column Postion

wa_fieldcat1-fieldname = 'MENGE'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal TAble

wa_fieldcat1-seltext_l = 'PO QUANTITY'. "Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

wa_fieldcat1-col_pos = '6'. "Column Pos tion

wa_fieldcat1-fieldname = 'MEINS'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal TAble

wa_fieldcat1-seltext_l = 'BASE UNIT MEASURE'."Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

wa_fieldcat1-col_pos = '7'. "Column Postion

wa_fieldcat1-fieldname = 'NETPR'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal Table

wa_fieldcat1-seltext_l = 'NET PRICE'. "Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

wa_fieldcat1-col_pos = '8'. "Column Postion

wa_fieldcat1-fieldname = 'KUNNR'. "Field Name

wa_fieldcat1-tabname = 'GT_ITEM'. "Internal Table

wa_fieldcat1-seltext_l = 'CUSTOMER NO'. "Display Text Screen

APPEND wa_fieldcat1 TO it_fieldcat1.

CLEAR wa_fieldcat1.

ENDFORM. " fieldcat1

&----


*& Form heading1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM heading1 .

REFRESH : it_header.

CLEAR : wa_header.

wa_header-typ = 'H'.

wa_header-info = 'THIS IS AN INTERACTIVE LIST'.

APPEND wa_header TO it_header.

ENDFORM. " heading1

&----


*& Form top

&----


  • text

----


FORM top.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = it_header

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

ENDFORM. "top

&----


*& Form display_data1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data1 .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = sy-cprog

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

i_callback_top_of_page = 'TOP'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

  • IS_LAYOUT =

it_fieldcat = it_fieldcat1

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

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_data1

Award Points if helpful.Kiran Kumar.G

Former Member
0 Kudos
73

hi,

try this code:-

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = G_PROGNAME

I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE' " Check here

IT_FIELDCAT = G_T_FIELDCAT

IT_EVENTS = IT_EVENTS

TABLES

T_OUTTAB = G_T_DETAIL

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_OF_PAGE USING CL_DD TYPE REF TO CL_DD_DOCUMENT. "#EC *

CALL METHOD CL_DD->UNDERLINE.

ENDFORM.

[/code]

RoySayak
Active Participant
0 Kudos
73

if u use I_CALL_BACK_TOP_OF_PAGE = 'TOP_PAGE'

u've to maintain I_CALLBACK_PROGRAM_NAME = current program name..

& u've to create a subroutine named TOP_PAGE. that subroutine will be triggered for printing top of page.

to print top of page u've to use FM RESUE_ALV_COMMENTARY_WRITE.

& u have to paas the texts in an int tab whose type is SLIS_T_LISTHEADER.

FORM TOP_PAGE.

DATA: T_GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,

WA_LS_LINE TYPE SLIS_LISTHEADER.

WA_LS_LINE-TYP = 'H'.

WA_LS_LINE-INFO = SY-TITLE.

APPEND WA_LS_LINE TO P_T_GT_LIST_TOP_OF_PAGE.

CLEAR WA_LS_LINE.

WA_LS_LINE-TYP = 'S'.

WA_LS_LINE-KEY = 'FLIGHT REPORT'.

WA_LS_LINE-INFO = SY-REPID.

APPEND WA_LS_LINE TO P_T_GT_LIST_TOP_OF_PAGE.

CLEAR WA_LS_LINE.

WA_LS_LINE-TYP = 'S'.

WA_LS_LINE-KEY = 'DATE:'.

WRITE SY-DATUM TO WA_LS_LINE-INFO.

APPEND WA_LS_LINE TO P_T_GT_LIST_TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = T_GT_LIST_TOP_OF_PAGE

.

ENDFORM.

Small but to the point answer is always the most useful i think...

REWARD IF USEFUL.

THANKS

SAYAK