2007 Nov 23 5:48 AM
How to display a text heading in Top of Page in ALV..
How to work in top of page in ALV...Cananyone tell me how to proceed..Plz give code reference
2007 Nov 23 5:50 AM
Hi,
Refer this code
data : it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
it_events TYPE slis_t_event,
it_header TYPE slis_t_listheader.
&----
*& Form sub_create_events *
&----
This form will display the ALV Events *
----
FORM sub_create_events .
*--Local Work Area
DATA: lwa_event TYPE slis_alv_event. "Work area for Events
*--Call Function to display the events for the ALV
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 1
IMPORTING
et_events = it_events.
*--Sort by Name
SORT it_events BY name.
*--Clear
CLEAR lwa_event.
READ TABLE it_events INTO lwa_event WITH KEY name =
slis_ev_top_of_page
BINARY SEARCH.
IF sy-subrc = 0.
MOVE c_top_of_page TO lwa_event-form.
MODIFY it_events FROM lwa_event TRANSPORTING form WHERE
name = slis_ev_top_of_page.
ENDIF.
*--Clear
CLEAR : lwa_event.
ENDFORM. "sub_create_events
&----
*& Form sub_top_of_page *
&----
This form is to build the Page Header *
----
FORM sub_top_of_page .
*--Local Variable
DATA : lv_title(120) TYPE c, " Title
lv_month(30) TYPE c,
lv_mont(30) TYPE c,
lv_bud(16) TYPE c.
*--Local Work Area
DATA : lwa_line TYPE slis_listheader. " Hold list header
CONCATENATE p_month 'to' s_hmonth INTO lv_month SEPARATED BY space.
IF NOT s_hmonth IS INITIAL.
lv_mont = lv_month.
ELSE.
lv_mont = p_month.
ENDIF.
*--Title Display
lwa_line-typ = 'H'. " header
lv_title = sy-title.
lwa_line-info = lv_title.
APPEND lwa_line TO it_header.
CLEAR lwa_line.
*--Month Display
lwa_line-typ = 'S'. " Item
WRITE: lv_mont TO lv_month.
lwa_line-key = text-024.
lwa_line-info = lv_month.
APPEND lwa_line TO it_header.
*--Budget Display
lwa_line-typ = 'S'. " Item
WRITE: p_bud TO lv_bud.
lwa_line-key = text-025.
lwa_line-info = lv_bud.
APPEND lwa_line TO it_header.
CLEAR: lwa_line,
lv_mont.
*--This funcation module will display the top of the page
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_header.
*--Free
FREE : it_header.
ENDFORM. "sub_top_of_page
Regards,
Prashant
How to display a text heading in Top of Page in ALV..
How to work in top of page in ALV...Cananyone tell me how to proceed..Plz give code reference
2007 Nov 23 5:50 AM
Hi,
Refer this code
data : it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
it_events TYPE slis_t_event,
it_header TYPE slis_t_listheader.
&----
*& Form sub_create_events *
&----
This form will display the ALV Events *
----
FORM sub_create_events .
*--Local Work Area
DATA: lwa_event TYPE slis_alv_event. "Work area for Events
*--Call Function to display the events for the ALV
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 1
IMPORTING
et_events = it_events.
*--Sort by Name
SORT it_events BY name.
*--Clear
CLEAR lwa_event.
READ TABLE it_events INTO lwa_event WITH KEY name =
slis_ev_top_of_page
BINARY SEARCH.
IF sy-subrc = 0.
MOVE c_top_of_page TO lwa_event-form.
MODIFY it_events FROM lwa_event TRANSPORTING form WHERE
name = slis_ev_top_of_page.
ENDIF.
*--Clear
CLEAR : lwa_event.
ENDFORM. "sub_create_events
&----
*& Form sub_top_of_page *
&----
This form is to build the Page Header *
----
FORM sub_top_of_page .
*--Local Variable
DATA : lv_title(120) TYPE c, " Title
lv_month(30) TYPE c,
lv_mont(30) TYPE c,
lv_bud(16) TYPE c.
*--Local Work Area
DATA : lwa_line TYPE slis_listheader. " Hold list header
CONCATENATE p_month 'to' s_hmonth INTO lv_month SEPARATED BY space.
IF NOT s_hmonth IS INITIAL.
lv_mont = lv_month.
ELSE.
lv_mont = p_month.
ENDIF.
*--Title Display
lwa_line-typ = 'H'. " header
lv_title = sy-title.
lwa_line-info = lv_title.
APPEND lwa_line TO it_header.
CLEAR lwa_line.
*--Month Display
lwa_line-typ = 'S'. " Item
WRITE: lv_mont TO lv_month.
lwa_line-key = text-024.
lwa_line-info = lv_month.
APPEND lwa_line TO it_header.
*--Budget Display
lwa_line-typ = 'S'. " Item
WRITE: p_bud TO lv_bud.
lwa_line-key = text-025.
lwa_line-info = lv_bud.
APPEND lwa_line TO it_header.
CLEAR: lwa_line,
lv_mont.
*--This funcation module will display the top of the page
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_header.
*--Free
FREE : it_header.
ENDFORM. "sub_top_of_page
Regards,
Prashant
2007 Nov 23 5:52 AM
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
2007 Nov 23 5:52 AM
Hi Mahesh,
Go thru this BLOG
/people/community.user/blog/2007/05/07/alignment-of-data-in-top-of-page-in-alv-grid
Regards,
2007 Nov 23 5:52 AM
HI
see this sample program where you can understand very easily how we can handle TOP-OF-pAGE
LOGO inserting and text
REPORT ztest_alv_logo.
TYPE-POOLS : slis.
*ALV Formatting tables /structures
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: gt_events TYPE slis_t_event.
DATA: gs_layout TYPE slis_layout_alv.
DATA: gt_page TYPE slis_t_listheader.
DATA: gs_page TYPE slis_listheader.
DATA: v_repid LIKE sy-repid.
*ALV Formatting work area
DATA: w_fieldcat TYPE slis_fieldcat_alv.
DATA: w_events TYPE slis_alv_event.
DATA: gt_bsid TYPE TABLE OF bsid WITH HEADER LINE.
INITIALIZATION.
PERFORM build_events.
PERFORM build_page_header.
START-OF-SELECTION.
*perform build_comment. "top_of_page - in initialization at present
SELECT * FROM bsid INTO TABLE gt_bsid UP TO 10 ROWS.
*perform populate_for_fm using '1' '3' 'BUKRS' '8' 'GT_BSID' 'Whee'.
*USING = Row, Column, Field name, display length, table name, heading
*OR
PERFORM build_fieldcat.
gs_layout-zebra = 'X'.
*top of page event does not work without I_callback_program
v_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_structure_name = 'BSID'
* i_background_id = 'ALV_BACKGROUND'
i_grid_title = 'This is the grid title'
* I_GRID_SETTINGS =
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
it_events = gt_events[]
TABLES
t_outtab = gt_bsid.
************************************************************************
* Form..............: populate_for_fm
* Description.......: Populates fields for function module used in ALV
************************************************************************
FORM populate_for_fm USING p_row
p_col
p_fieldname
p_len
p_table
p_desc.
w_fieldcat-row_pos = p_row. "Row Position
w_fieldcat-col_pos = p_col. "Column Position
w_fieldcat-fieldname = p_fieldname. "Field name
w_fieldcat-outputlen = p_len. "Column Lenth
w_fieldcat-tabname = p_table. "Table name
w_fieldcat-reptext_ddic = p_desc. "Field Description
w_fieldcat-input = '1'.
APPEND w_fieldcat TO gt_fieldcat.
CLEAR w_fieldcat.
ENDFORM. " populate_for_fm
*&---------------------------------------------------------------------*
*& Form build_events
*&---------------------------------------------------------------------*
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.
READ TABLE gt_events
WITH KEY name = slis_ev_user_command
INTO ls_event.
IF sy-subrc = 0.
MOVE slis_ev_user_command TO ls_event-form.
APPEND ls_event TO gt_events.
ENDIF.
READ TABLE gt_events
WITH KEY name = slis_ev_top_of_page
INTO ls_event.
IF sy-subrc = 0.
MOVE slis_ev_top_of_page TO ls_event-form.
APPEND ls_event TO gt_events.
ENDIF.
ENDFORM. " build_events
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* When user command is called it uses 2 parameters. The itab
* passed to the ALV is in whatever order it currently is on screen.
* Therefore, you can read table itab index rs_selfield-tabindex to get
* all data from the table. You can also check r_ucomm and code
* accordingly.
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
READ TABLE gt_bsid INDEX rs_selfield-tabindex.
* error checking etc.
SET PARAMETER ID 'KUN' FIELD gt_bsid-kunnr.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* Your own company logo can go here if it has been saved (OAOR)
* If the logo is larger than the size of the headings in gt_page,
* the window will not show full logo and will have a scroll bar. Thus,
* it is a good idea to have a standard ALV header if you are going to
* use logos in your top of page.
*&---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = gt_page
i_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form build_fieldcat
*&---------------------------------------------------------------------*
*Many and varied fields are available here. Have a look at documentation
*for FM REUSE_ALV_LIST_DISPLAY and REUSE_ALV_FIELDCATALOG_MERGE
*----------------------------------------------------------------------*
FORM build_fieldcat.
w_fieldcat-fieldname = 'BUDAT'.
w_fieldcat-seltext_m = 'Dte pst'.
w_fieldcat-ddictxt(1) = 'M'.
w_fieldcat-edit = 'x'.
* Can change the position of fields if you do not want them in order
* of the DDIC or itab
* w_fieldcat-row_pos = '1'.
* w_fieldcat-col_pos = '10'.
APPEND w_fieldcat TO gt_fieldcat.
CLEAR w_fieldcat.
ENDFORM. " build_fieldcat
*&---------------------------------------------------------------------*
*& Form build_page_header
*&---------------------------------------------------------------------*
* gt_page is used in top of page (ALV subroutine - NOT event)
* *H = Header, S = Selection, A = Action
*----------------------------------------------------------------------*
FORM build_page_header.
* For Headers, Key is not printed and is irrelevant. Will not cause
* a syntax error, but is not used.
gs_page-typ = 'H'.
gs_page-info = 'Header 1'.
APPEND gs_page TO gt_page.
gs_page-typ = 'H'.
gs_page-info = 'Header 2'.
APPEND gs_page TO gt_page.
* For Selections, the Key is printed (bold). It can be anything up to 20
* bytes. It gets printed in order of code here, not by key value.
gs_page-typ = 'S'.
gs_page-key = 'And the winner is:'.
gs_page-info = 'Selection 1'.
APPEND gs_page TO gt_page.
gs_page-typ = 'S'.
gs_page-key = 'Runner up:'.
gs_page-info = 'Selection 2'.
APPEND gs_page TO gt_page.
* For Action, Key is also irrelevant.
gs_page-typ = 'A'.
gs_page-info = 'Action goes here'.
APPEND gs_page TO gt_page.
ENDFORM. " build_page_header
2007 Nov 26 12:50 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |