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 Subtotal Text Using Classes

Former Member
0 Likes
387

Hi experts,

I am trying for alv subtotal text but i am not able to get the subtotal text. this is my program.

report ztest_alv.

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,

end of itab_t.

data: itab type table of 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 aebeln = bebeln.

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.

ls_sort-spos = 1.

ls_sort-fieldname = 'EBELN'.

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.

endform. " FILL_EVENT

&----


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

can you specify where it is required to modify..

2 REPLIES 2
Read only

Former Member
0 Likes
362

for this you need to do some thing different...

in local calss , you need a event for sub total text,

and set the handler for it, then sub total text will come.

FORM method_subtotal_text USING es_subtottxt_info TYPE lvc_s_stxt

ep_subtot_line TYPE REF TO data

e_event_data TYPE REF TO

cl_alv_event_data.

DATA ls_sflight LIKE sflight.

FIELD-SYMBOLS: <fs1> STRUCTURE sflight DEFAULT ls_sflight,

<fs2>.

IF es_subtottxt_info-criteria = 'PLANETYPE'.

ASSIGN ep_subtot_line->* TO <fs1>.

ASSIGN e_event_data->m_data->* TO <fs2>.

CONCATENATE es_subtottxt_info-keyword ': '

<fs1>-planetype INTO <fs2>.

ENDIF.

<b>rewards point for useful answer......</b>

thnaks ...

Abhay SIngh.

Read only

Former Member
0 Likes
362

Raghavendra,

I modified your code abit.

Just check it once.....

Observe the Bold code. and Now you will get the Subtotal text.

REPORT ZTEST_ALV .

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,

<b>d,</b> "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 aebeln = bebeln.

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.

<b>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.</b>

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.

<b>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'.

concatenate 'Subtotal for' I_LISTHEAD-EBELN into

I_SUBTOTAL-display_text_for_subtotal .

endif.

ENDFORM.</b>

&----


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

Regards

Vijay