Skip to Content

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

ALV

Hi Group,

I am creating standard report output templet for ABAP report using ALV using the following code.When I am putting common code in the include so that I can include

for all the programs to show the common header and footer I am getting errors.Can you please suggest.

Here I am attaching the detailed code.

REPORT ZSAMPLE .

TABLES : MARAV.

type-pools : slis. "ALV Declarations

include ZSAMPLE_INC.

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

g_start_time type sy-uzeit.

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

gt_events type slis_t_event,

gd_prntparams type slis_print_alv,

x_events type slis_alv_event,

it_events type slis_t_event.

select-options:s_matnr for marav-matnr.

initialization.

*v_repid = sy-repid.

s_matnr-low = '1000'.

s_matnr-sign = 'I'.

s_matnr-option = 'EQ'.

S_matnr-high = '5000'.

append s_matnr.

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

*Start-of-selection.

START-OF-SELECTION.

g_start_time = sy-uzeit.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

perform build_events.

perform build_print_params.

perform display_alv_report tables fieldcatalog

it_marav

using sy-repid

gd_layout

gt_events

gd_prntparams

wa_marav

.

&----


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

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

endform. " BUILD_LAYOUT

&----


*& 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 USER_COMMAND *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

ENDFORM. "user_command

&----


*& Form BUILD_EVENTS

&----


  • Build events table

----


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_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

&----


  • Setup print parameters

----


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:/'User :' , sy-uname.

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

endform. "end_of_page

&----


*& Form END_OF_LIST

&----


form end_of_list.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c,

v_time(10) type c.

skip.

concatenate sy-uzeit(2) '.'

sy-uzeit+2(2) '.'

sy-uzeit+4(2) INTO v_time.

write:/'User :' ,8 sy-uname, 30 'Report ID :' , 44

sy-repid ,69 'Page:',75 sy-pagno .

type-pools : slis.

*ALV data declarations

data: t_fieldcatalog type slis_t_fieldcat_alv with header line,

p_gd_tab_group type slis_t_sp_group_alv,

p_gd_layout type slis_layout_alv,

p_gd_repid like sy-repid,

p_gt_events type slis_t_event,

p_gd_prntparams type slis_print_alv,

p_x_events type slis_alv_event,

p_it_events type slis_t_event.

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,

v_logo(30) type c,

ld_lines type i,

ld_linesc(10) type c,

v_data(15) type c,

v_time(15) type c,

v_title(20) type c.

data: v_space(2) value ' ',

v_head(20) value ' ',

v_head1(10) value ' '.

data: i_int_tab type standard table of rsparams initial size 0.

v_logo = 'ABAP report'.

format color COL_GROUP.

format intensified input off.

print-control font 2 lpi 5.

write:/25 v_logo color 7,

/22 sy-title .

write:/ 'Date :', sy-datum, 62 'Run Time :', sy-uzeit.

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