Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ALV Header

HI Group,

when I am creating ALV templet for the reports I created header and footers.In both I created some information like

in Header:

Report

date

time

these information I need in the same line ,when I am using concatenate statement separated by space it is not leaving the space in between the space I need to keep 2 tab spaces in between each field,I also used CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,but it is also not working.In the footer also I need to create user name on left hand edge and page number on the right hand edge .Please suggest

I am using this code

TABLES: MARAV.

type-pools: slis. "ALV Declarations

*Data Declaration

TYPES: BEGIN OF t_marav,

matnr like marav-matnr,

maktx like marav-maktx,

matkl like marav-matkl,

ntgew like marav-ntgew,

gewei like marav-gewei,

END OF t_marav.

DATA: it_marav TYPE STANDARD TABLE OF t_marav INITIAL SIZE 0,

wa_marav TYPE t_marav.

DATA: gt_events type slis_t_event,

gd_prntparams type slis_print_alv.

data: v_spaces(10) value ' '.

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

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

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

perform display_alv_report.

  • perform build_events.

  • perform build_print_params.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material number'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'X'.

fieldcatalog-key = 'X'.

  • fieldcatalog-do_sum = 'X'.

  • fieldcatalog-no_zero = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MAKTX'.

fieldcatalog-seltext_m = 'Material Des'.

fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MATKL'.

fieldcatalog-seltext_m = 'Material group '.

fieldcatalog-col_pos = 2.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NTGEW'.

fieldcatalog-seltext_m = 'Net weight'.

fieldcatalog-col_pos = 3.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'GEWEI'.

fieldcatalog-seltext_m = 'weight unit '.

fieldcatalog-col_pos = 4.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • gd_layout-totals_only = 'X'.

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

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

endform. " BUILD_LAYOUT

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


form display_alv_report.

data: GT_EVENTS TYPE SLIS_T_EVENT,

WA_EVENT LIKE LINE OF GT_EVENTS .

CLEAR: WA_EVENT.

WA_EVENT-NAME = 'END_OF_PAGE'.

WA_EVENT-FORM = 'FOOTER' .

APPEND WA_EVENT TO GT_EVENTS.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

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

i_callback_html_end_of_list = 'END_OF_LIST_HTML'

  • i_grid_title = outtext

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

  • it_events = gt_events

  • is_print = gd_prntparams

i_save = 'X'

  • is_variant = z_template

tables

t_outtab = it_marav

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 DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

select matnr maktx matkl ntgew gewei

up to 10 rows

from marav

into table it_marav.

endform. " DATA_RETRIEVAL

&----


*& Form top-of-page

&----


  • text

----


Form top-of-page.

DATA SEPARATOR(10) VALUE space.

*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,

v_date(20) type c.

  • Title

wa_header-typ = 'H'.

wa_header-info = 'Southern Water'.

append wa_header to t_header.

clear wa_header.

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

sy-datum+4(2) '.'

sy-datum(4) INTO v_date.

  • Title

wa_header-typ = 'S'.

wa_header-key = 'Report '.

Concatenate sy-repid 'Date : '

v_date into wa_header-info

SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

  • wa_header-info = sy-repid.

append wa_header to t_header.

clear wa_header.

  • wa_header-typ = 'S'.

  • wa_header-key = 'Report Des '.

  • wa_header-info = 'ABAP Report templet'.

  • append wa_header to t_header.

  • clear wa_header.

*

*

  • wa_header-typ = 'S'.

  • wa_header-key = 'SYS ID : '.

  • wa_header-info = sy-sysid.

  • append wa_header to t_header.

  • clear wa_header.

*

  • wa_header-typ = 'S'.

  • wa_header-key = 'Client '.

  • wa_header-info = sy-mandt.

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

wa_header-typ = 'S'.

wa_header-key = 'Run Time '.

CONCATENATE sy-uzeit(2) '.'

sy-uzeit+4(2) '.'

sy-uzeit+2(2) INTO wa_header-info.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = 'User ID '.

wa_header-info = sy-uname.

append wa_header to t_header.

clear wa_header.

*

  • Total No. of Records Selected

describe table it_marav 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 = 'logo.gif'.

*

endform. "top-of-page

FORM end_of_list_html USING end TYPE REF TO cl_dd_document.

DATA: ls_text TYPE sdydo_text_element,

l_grid TYPE REF TO cl_gui_alv_grid,

f(14) TYPE c VALUE 'SET_ROW_HEIGHT'.

data: v_footer type sdydo_text_element.

data: v_pagno type n.

v_pagno = sy-pagno.

  • adds test (via variable)

CALL METHOD end->add_text

EXPORTING

text = ls_text

sap_emphasis = 'strong'.

concatenate sy-uname 'Report' v_pagno into v_footer SEPARATED BY v_spaces. "c_tab.

  • CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

condense v_footer.

CALL METHOD end->add_text

EXPORTING

text = v_footer.

ENDFORM. "end_of_list_html.

Tags:
Not what you were looking for? View more on this topic or Ask a question