Application Development and Automation 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: 
Read only

ALV Example with sort,header,manual fieldcatalog

Former Member
0 Likes
1,241

&----


*& Report ZDEMO_ALVGRID *

*& *

&----


*& *

*& Example of a simple ALV Grid Report with grand total *

*& ................................... *

*& *

*& The basic requirement for this demo is to display a number of *

*& fields from the EKKO table. *

&----


REPORT zdemo_alvgrid .

TABLES: ekko.

type-pools: slis. "ALV Declarations

*Data Declaration

*----


TYPES: BEGIN OF t_ekko,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

netpr TYPE ekpo-netpr,

END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_ekko TYPE t_ekko.

CONSTANTS: FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_repid like sy-repid,

gd_layout type slis_layout_alv,

it_sort TYPE slis_t_sortinfo_alv,

t_sort TYPE slis_sortinfo_alv.

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

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

PERFORM sort_fields.

perform display_alv_report.

PERFORM TOP-OF-PAGE.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

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

fieldcatalog-seltext_m = 'PO Item'.

fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-do_sum = 'X'. "Display column total

fieldcatalog-datatype = 'CURR'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " BUILD_FIELDCATALOG

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


form display_alv_report.

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

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

it_sort = it_sort[]

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 DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

select ebeln ebelp netpr up to 10 rows from ekpo into table it_ekko.

endform. " DATA_RETRIEVAL

&----


*& 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 = 'Drivers not Assigned List'.

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

endform. " TOP-OF-PAGE

&----


*& Form SORT_FIELDS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form SORT_FIELDS .

t_sort-fieldname = 'EBELP'.

t_sort-spos = 1.

t_sort-up = 'X'.

APPEND t_sort TO it_sort.

CLEAR t_sort.

endform. " SORT_FIELDS

&----


*& Report ZDEMO_ALVGRID *

*& *

&----


*& *

*& Example of a simple ALV Grid Report with grand total *

*& ................................... *

*& *

*& The basic requirement for this demo is to display a number of *

*& fields from the EKKO table. *

&----


REPORT zdemo_alvgrid .

TABLES: ekko.

type-pools: slis. "ALV Declarations

*Data Declaration

*----


TYPES: BEGIN OF t_ekko,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

netpr TYPE ekpo-netpr,

END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_ekko TYPE t_ekko.

CONSTANTS: FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_repid like sy-repid,

gd_layout type slis_layout_alv,

it_sort TYPE slis_t_sortinfo_alv,

t_sort TYPE slis_sortinfo_alv.

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

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

PERFORM sort_fields.

perform display_alv_report.

PERFORM TOP-OF-PAGE.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

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

fieldcatalog-seltext_m = 'PO Item'.

fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-do_sum = 'X'. "Display column total

fieldcatalog-datatype = 'CURR'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " BUILD_FIELDCATALOG

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


form display_alv_report.

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

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

it_sort = it_sort[]

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 DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

select ebeln ebelp netpr up to 10 rows from ekpo into table it_ekko.

endform. " DATA_RETRIEVAL

&----


*& 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 = 'Drivers not Assigned List'.

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

endform. " TOP-OF-PAGE

&----


*& Form SORT_FIELDS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form SORT_FIELDS .

t_sort-fieldname = 'EBELP'.

t_sort-spos = 1.

t_sort-up = 'X'.

APPEND t_sort TO it_sort.

CLEAR t_sort.

endform. " SORT_FIELDS

2 REPLIES 2
Read only

Former Member
0 Likes
539

Hello,

See this example programs

BALV1F02

BALV1SEL

BALV1TOP

BALVBT01

BALVBT02

BALVBUFDEL

BALVEX01

BALVEX02

BALVEXTR

BALVHD01

BALVHD01_GROUP

BALVHM10

BALVHM12

BALVHT_EDITABLETEXT

BALVHT_HTML_FORM

BALVHT_HTMLINPUT

BALVHT_HTMLRAWTMPL

BALVHT_TAGSTREAM

BALVHT_UIFORM

BALVHT01

BALVHTMAINTENANCE

BALVHTTRANSLHTMPL

Read only

Former Member
0 Likes
539

What is your question???