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: 

To get Grand Total text not sub total text in ALV

Former Member
0 Kudos

I am getting Sub total text, but I am not getting Grand Total Text in ALV report.

I am using FM : Reuse_alv_grid_display.

Can anybody suggest me how to do ?

thanks

kumar n

4 REPLIES 4

Former Member
0 Kudos

[;

[http://sap.niraj.tripod.com/id64.html]

former_member188685
Active Contributor
0 Kudos

Check the sample code.

You have to use the dummy field, and event Sub_total_text check the sample code.

REPORT ZTEST_ALV_TEXT .
type-pools : slis.

types : begin of itab_t,
ebeln like ekpo-ebeln,
lifnr like ekko-lifnr,
ekorg like ekko-ekorg,
ekgrp like ekko-ekgrp,
werks like ekpo-werks,
ebelp like ekpo-ebelp,
matnr like ekpo-matnr,
menge like ekpo-menge,
netpr like ekpo-netpr,
d, "Dummy field to fire the Subtotal text event
end of itab_t.

data: itab type table of itab_t.
data: tab type itab_t.
data : itab1 like eket occurs 0 with header line.

data: t_fcat type slis_t_fieldcat_alv,
it_sort type slis_t_sortinfo_alv,
t_events type slis_t_event,
listhead type slis_t_listheader,
ls_layout type slis_layout_alv.

start-of-selection.

select a~ebeln
a~lifnr
a~ekorg
a~ekgrp
b~werks
b~ebelp
b~matnr
b~menge
b~netpr
up to 100 rows
into corresponding fields of table itab
from ekko as a inner join ekpo as b
on a~ebeln = b~ebeln.

end-of-selection.

perform fill_fcat using t_fcat.

perform fill_event using t_events.

perform fill_layout.

perform display.

&--------------------------------------------------------------------
*& Form fill_fcat
&--------------------------------------------------------------------


text 
---------------------------------------------------------------------

-->P_T_FCAT text 
---------------------------------------------------------------------
form fill_fcat using p_t_fcat type slis_t_fieldcat_alv.

data : lfcat type slis_fieldcat_alv,

colpos type i value '0'.

data : ls_sort type slis_sortinfo_alv.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EBELN'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EBELN'.
lfcat-ref_tabname = 'EKKO'.
lfcat-hotspot = 'X'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'LIFNR'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'LIFNR'.
lfcat-ref_tabname = 'EKKO'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EKORG'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EKORG'.
lfcat-ref_tabname = 'EKKO'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EKGRP'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EKGRP'.
lfcat-ref_tabname = 'EKKO'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'WERKS'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'WERKS'.
lfcat-ref_tabname = 'EKPO'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'EBELP'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EBELP'.
lfcat-ref_tabname = 'EKPO'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'MATNR'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'MATNR'.
lfcat-ref_tabname = 'EKPO'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'MENGE'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'MENGE'.
lfcat-ref_tabname = 'EKPO'.
lfcat-do_sum = 'X'.
append lfcat to p_t_fcat.
clear lfcat.

colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'NETPR'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'NETPR'.
lfcat-ref_tabname = 'EKPO'.
lfcat-do_sum = 'X'.
append lfcat to p_t_fcat.
clear lfcat.


colpos = colpos + 1.
lfcat-col_pos = colpos.
lfcat-fieldname = 'D'.
lfcat-tabname = 'ITAB'.
lfcat-ref_fieldname = 'EBELN'.
lfcat-ref_tabname = 'EKKO'.
lfcat-no_out = 'X'.
append lfcat to p_t_fcat.
clear lfcat.

ls_sort-spos = 1.
ls_sort-fieldname = 'EBELN'.
ls_sort-tabname = 'ITAB'.
ls_sort-up = 'X'.
ls_sort-group = 'UL'.


append ls_sort to it_sort.
clear ls_sort.

ls_sort-spos = 2.
ls_sort-fieldname = 'D'.
ls_sort-tabname = 'ITAB'.
ls_sort-up = 'X'.
ls_sort-group = 'UL'.
ls_sort-subtot = 'X'.

append ls_sort to it_sort.
endform. " fill_fcat

&--------------------------------------------------------------------
*& Form fill_event
&--------------------------------------------------------------------


text 
---------------------------------------------------------------------

-->P_T_EVENTS text 
---------------------------------------------------------------------
form fill_event using p_t_events type slis_t_event.

data : ls_event type slis_alv_event.

call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = p_t_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 p_t_events with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move 'TOP_OF_PAGE' to ls_event-form.
append ls_event to p_t_events.
endif.

read table p_t_events with key name = SLIS_EV_SUBTOTAL_TEXT
into ls_event.
if sy-subrc = 0.
move 'SUBTOTAL' to ls_event-form.
append ls_event to p_t_events.
endif.

endform. " FILL_EVENT
FORM SUBTOTAL USING I_LISTHEAD STRUCTURE tab
I_SUBTOTAL TYPE SLIS_SUBTOT_TEXT.

*criteria type slis_fieldname,

keyword like dd03p-reptext, 
criteria_text(255) type c, 
max_len like dd03p-outputlen, 
display_text_for_subtotal(255) type c, 
if I_SUBTOTAL-criteria = 'D'.
I_SUBTOTAL-display_text_for_subtotal = 'Sub total'.

endif.

ENDFORM.
&--------------------------------------------------------------------
*& Form TOP_OF_PAGE
&--------------------------------------------------------------------

text 
---------------------------------------------------------------------
form top_of_page.

data : s_listhead type slis_listheader.

clear s_listhead.
s_listhead-typ = 'H'.
s_listhead-info = 'SIMPLE REPORT'.
append s_listhead to listhead.

s_listhead-typ = 'S'.
s_listhead-key = 'EBELN'.
s_listhead-info = 'ALV'.
append s_listhead to listhead.

call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = listhead
i_logo = 'ENJOYSAP_LOGO'


I_END_OF_LIST_GRID = 
.
endform. "TOP_OF_PAGE

&---------------------------------------------------------------------
*& Form fill_layout
&---------------------------------------------------------------------

text 
----------------------------------------------------------------------

-->P_S_LAYOUT text 
----------------------------------------------------------------------
form fill_layout .

ls_layout-zebra = 'X'.
ls_layout-detail_popup = 'X'.
ls_layout-key_hotspot = 'X'.
ls_layout-window_titlebar = 'Dharma'.
ls_layout-detail_titlebar = 'Jasti'.
ls_layout-totals_text = 'GRAND TOTAL'.
ls_layout-subtotals_text = 'SUB'.

endform. " fill_layout

&---------------------------------------------------------------------
*& Form display
&---------------------------------------------------------------------

text 
----------------------------------------------------------------------

--> p1 text 
<-- p2 text 
----------------------------------------------------------------------
form display .

call function 'REUSE_ALV_LIST_DISPLAY'
exporting

I_INTERFACE_CHECK = ' ' 
I_BYPASSING_BUFFER = 
I_BUFFER_ACTIVE = ' ' 
i_callback_program = sy-repid
i_callback_pf_status_set = 'STATUS'
i_callback_user_command = 'USER_COMMAND'

I_STRUCTURE_NAME = 
is_layout = ls_layout
it_fieldcat = t_fcat

IT_EXCLUDING = 
IT_SPECIAL_GROUPS = 
it_sort = it_sort[]

IT_FILTER = 
IS_SEL_HIDE = 
I_DEFAULT = 'X' 
I_SAVE = ' ' 
IS_VARIANT = 
it_events = t_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 = itab

EXCEPTIONS 
PROGRAM_ERROR = 1 
OTHERS = 2 
.
if sy-subrc 0.

MESSAGE ID SY-MSGI D TYPE SY-MSGTY NUMBER SY-MSGNO 
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
endif.
endform. " display

&--------------------------------------------------------------------
*& Form status
&--------------------------------------------------------------------

text 
---------------------------------------------------------------------

-->EXTAB text 
---------------------------------------------------------------------
form status using extab type slis_t_extab.
set pf-status 'PFSA' excluding extab.
endform. "STATUS

&--------------------------------------------------------------------
*& Form user_command
&--------------------------------------------------------------------

text 
---------------------------------------------------------------------

-->R_UCOMM text 


-->RS_SELFIELDtext 
---------------------------------------------------------------------
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.

when '&ETA'.
select * from eket into corresponding fields of itab1
where ebeln = rs_selfield-value.
write:/ itab1-ebeln,
itab1-ebelp,
itab1-etenr,
itab1-eindt,
itab1-menge.
endselect.

when 'BACK' or 'EXIT' or 'CANC'.
leave .
endcase.

endform. "USER_COMMAND

Former Member
0 Kudos

Hi,

set totals_text in LAYOUT (Parameter IS_LAYOUT of REUSE_ALV_LIST_DISPLAY)

Regards, Dieter

GauthamV
Active Contributor
0 Kudos

hi,

check this sample prog.

REPORT ZGM_ALV_SUBTOTAL_TEXT .

*& Table declaration

&----


TABLES: ekko.

&----


*& Type pool declaration

&----


TYPE-POOLS: slis. " Type pool for ALV

&----


*& Selection screen

&----


SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.

&----


*& Type declaration

&----


  • Type declaration for internal table to store EKPO data

TYPES: BEGIN OF x_data,

ebeln TYPE char30, " Document no.

ebelp TYPE ebelp, " Item no

matnr TYPE matnr, " Material no

matnr1 TYPE matnr, " Material no

werks TYPE werks_d, " Plant

werks1 TYPE werks_d, " Plant

ntgew TYPE entge, " Net weight

gewe TYPE egewe, " Unit of weight

END OF x_data.

&----


*& Internal table declaration

&----


DATA:

i_ekpo TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,

  • Internal table for storing field catalog information

i_fieldcat TYPE slis_t_fieldcat_alv,

  • Internal table for Top of Page info. in ALV Display

i_alv_top_of_page TYPE slis_t_listheader,

  • Internal table for ALV Display events

i_events TYPE slis_t_event,

  • Internal table for storing ALV sort information

i_sort TYPE slis_t_sortinfo_alv,

i_event TYPE slis_t_event.

&----


*& Work area declaration

&----


DATA:

wa_ekko TYPE x_data,

wa_layout TYPE slis_layout_alv,

wa_events TYPE slis_alv_event,

wa_sort TYPE slis_sortinfo_alv.

&----


*& Constant declaration

&----


CONSTANTS:

c_header TYPE char1

VALUE 'H', "Header in ALV

c_item TYPE char1

VALUE 'S'.

&----


*& Start-of-selection event

&----


START-OF-SELECTION.

  • Select data from ekpo

SELECT ebeln " Doc no

ebelp " Item

matnr " Material

matnr " Material

werks " Plant

werks " Plant

ntgew " Quantity

gewei " Unit

FROM ekpo

INTO TABLE i_ekpo

WHERE ebeln IN s_ebeln

AND ntgew NE '0.00'. IF sy-subrc = 0.

SORT i_ekpo BY ebeln ebelp matnr .

ENDIF.

  • To build the Page header

PERFORM sub_build_header. "* To prepare field catalog

PERFORM sub_field_catalog. "* Perform to populate the layout structure

PERFORM sub_populate_layout."* Perform to populate the sort table.

PERFORM sub_populate_sort."* Perform to populate ALV event

PERFORM sub_get_event.

END-OF-SELECTION.

  • * Perform to display ALV report

PERFORM sub_alv_report_display.

&----


*& Form sub_build_header

&----


  • To build the header

----


  • No Parameter

----


FORM sub_build_header .

  • Local data declaration

DATA: l_system TYPE char10 , "System id

l_r_line TYPE slis_listheader, "Hold list header

l_date TYPE char10, "Date

l_time TYPE char10, "Time

l_success_records TYPE i, "No of success records

l_title(300) TYPE c. " Title

  • Title Display

l_r_line-typ = c_header. " header

l_title = 'Test report'(001).

l_r_line-info = l_title.

APPEND l_r_line TO i_alv_top_of_page.

CLEAR l_r_line.

  • * Run date Display

CLEAR l_date.

l_r_line-typ = c_item. " Item

WRITE: sy-datum TO l_date MM/DD/YYYY.

l_r_line-key = 'Run Date :'(002).

l_r_line-info = l_date.

APPEND l_r_line TO i_alv_top_of_page.

CLEAR: l_r_line,

l_date.ENDFORM. " sub_build_header

&----


*& Form sub_field_catalog

&----


  • Build Field Catalog

----


  • No Parameter

----


FORM sub_field_catalog .

  • Build Field Catalog

PERFORM sub_fill_alv_field_catalog USING: '01' '01' 'EBELN'

'I_EKPO' 'L'

'Doc No'(003) ' ' ' ' ' ' ' ', '01' '02' 'EBELP' 'I_EKPO' 'L'

'Item No'(004) 'X' 'X' ' ' ' ', '01' '03' 'MATNR' 'I_EKPO' 'L'

'Material No'(005) 'X' 'X' ' ' ' ', '01' '03' 'MATNR1' 'I_EKPO'

'L'

'Material No'(005) ' ' ' ' ' ' ' ',

'01' '04' 'WERKS' 'I_EKPO' 'L'

'Plant'(006) 'X' 'X' ' ' ' ', '01' '04' 'WERKS1' 'I_EKPO' 'L'

'Plant'(006) ' ' ' ' ' ' ' ', '01' '05' 'NTGEW' 'I_EKPO' 'R'

'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'.ENDFORM.

" sub_field_catalog*&----


"----


*

*& Form sub_fill_alv_field_catalog

&----


*& For building Field Catalog

&----


*& p_rowpos Row position

*& p_colpos Col position

*& p_fldnam Fldname

*& p_tabnam Tabname

*& p_justif Justification

*& p_seltext Seltext

*& p_out no out

*& p_tech Technical field

*& p_qfield Quantity field

*& p_qtab Quantity table

&----


FORM sub_fill_alv_field_catalog USING p_rowpos TYPE sycurow

p_colpos TYPE sycucol

p_fldnam TYPE fieldname

p_tabnam TYPE tabname

p_justif TYPE char1

p_seltext TYPE dd03p-scrtext_l

p_out TYPE char1

p_tech TYPE char1

p_qfield TYPE slis_fieldname

p_qtab TYPE slis_tabname.

  • Local declaration for field

  • catalog

DATA: wa_lfl_fcat TYPE slis_fieldcat_alv.

wa_lfl_fcat-row_pos = p_rowpos. "Row

wa_lfl_fcat-col_pos = p_colpos. "Column

wa_lfl_fcat-fieldname = p_fldnam. "Field Name

wa_lfl_fcat-tabname = p_tabnam. "Internal Table Name

wa_lfl_fcat-just = p_justif. "Screen Justified

wa_lfl_fcat-seltext_l = p_seltext. "Field Text

wa_lfl_fcat-no_out = p_out. "No output

wa_lfl_fcat-tech = p_tech. "Technical field

wa_lfl_fcat-qfieldname = p_qfield. "Quantity unit

wa_lfl_fcat-qtabname = p_qtab .

"Quantity table

IF p_fldnam = 'NTGEW'.

wa_lfl_fcat-do_sum = 'X'.

ENDIF.

APPEND wa_lfl_fcat TO i_fieldcat.

CLEAR wa_lfl_fcat.

ENDFORM.

" sub_fill_alv_field_catalog*&----


"----


*

*& Form sub_populate_layout

&----


  • Populate ALV layout

----


  • No Parameter

----


FORM sub_populate_layout . CLEAR wa_layout.

wa_layout-colwidth_optimize = 'X'.

" Optimization of Col width

ENDFORM. " sub_populate_layout*&----


"----


*

*& Form sub_populate_sort

&----


  • Populate ALV sort table

----


  • No Parameter

----


FORM sub_populate_sort .

  • Sort on material

wa_sort-spos = '01' .

wa_sort-fieldname = 'MATNR'.

wa_sort-tabname = 'I_EKPO'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO i_sort .

CLEAR wa_sort.

  • Sort on plant

wa_sort-spos = '02'.

wa_sort-fieldname = 'WERKS'.

wa_sort-tabname = 'I_EKPO'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO i_sort .

CLEAR wa_sort.

ENDFORM.

" sub_populate_sort*&----


"----


*

*& Form sub_get_event

&----


  • Get ALV grid event and pass the form name to subtotal_text

  • event

----


  • No Parameter

----


FORM sub_get_event .

CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE

'SUBTOTAL_TEXT'. DATA: l_s_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 4

IMPORTING

et_events = i_event

EXCEPTIONS

list_type_wrong = 0

OTHERS = 0.

  • Subtotal

READ TABLE i_event INTO l_s_event

WITH KEY name = slis_ev_subtotal_text.

IF sy-subrc = 0.

MOVE c_formname_subtotal_text TO l_s_event-form.

MODIFY i_event FROM l_s_event INDEX sy-tabix.

ENDIF.ENDFORM.

" sub_get_event*&----


"----


*

*& Form sub_alv_report_display

&----


  • For ALV Report Display

----


  • No Parameter

----


FORM sub_alv_report_display .

DATA: l_repid TYPE syrepid .

l_repid = sy-repid .

  • This function module for displaying the ALV

  • report

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = l_repid

i_callback_top_of_page = 'SUB_ALV_TOP_OF_PAGE'

is_layout = wa_layout

it_fieldcat = i_fieldcat

it_sort = i_sort

it_events = i_event

i_default = 'X'

i_save = 'A'

TABLES

t_outtab = i_ekpo

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE i000 WITH 'Error in ALV report display'(055).

ENDIF.

ENDFORM.

" sub_alv_report_display*&----


"----


*

  • FORM sub_alv_top_of_page

----


  • Call ALV top of page

----


  • No parameter

----


FORM sub_alv_top_of_page. "#EC CALLED*

*To write header for the ALV

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = i_alv_top_of_page.

ENDFORM.

"alv_top_of_page*&----


"----


*

*& Form subtotal_text

&----


  • Build subtotal text

----


  • P_total Total

  • p_subtot_text Subtotal text info

----


FORM subtotal_text CHANGING

p_total TYPE any

p_subtot_text TYPE slis_subtot_text.

  • Material level sub total

IF p_subtot_text-criteria = 'MATNR'.

p_subtot_text-display_text_for_subtotal

= 'Material level total'(009).

ENDIF.

  • Plant level sub total

IF p_subtot_text-criteria = 'WERKS'.

p_subtot_text-display_text_for_subtotal = 'Plant level total'(010).

ENDIF.

ENDFORM. "subtotal_textSelection screen: