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 form routine not getting executed

Former Member
0 Kudos
365

Hi all,

I am using REUSE_ALV_LIST_DISPLAY for displaying my output internal table. I have filled field catalogue with the required fields, and IT sort table with the field for which i want to do subtotal. I am getting the expected output( subtotal row).

FORM sort .

*For sorting and subtotal

wa_sort-spos = 1.

wa_sort-fieldname = 'ZUONR'.

wa_sort-tabname = 'IT_OUTPUT'.

wa_sort-subtot = 'X'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

ENDFORM.

I have filled events with 'TOP_OF_PAGE' and 'SUBTOTAL_TEXT' with corresponding form routines.

Here is my SUBTOTAL_TEXT subroutine.

FORM subtotal_text CHANGING

p_total TYPE any

p_subtot_text TYPE slis_subtot_text.

  • Assignment level sub total

IF p_subtot_text-criteria = 'ZUONR'.

p_subtot_text-display_text_for_subtotal

= 'Publication level subtotal'.

ENDIF.

ENDFORM .

When i execute my report, Top of page events get executed and header gets populated in the output correctly, but subtotal texts do not gets populated. I have debugged the program and kept break-points in the subtotal texts subroutine, but it is not called.

Can anyone plz guide me??? Correct me If I am wrong anywhere.

Thank you very much,

Swathi.

Edited by: swathi Chandra on Dec 28, 2010 6:05 PM

12 REPLIES 12
Read only

Former Member
0 Kudos
230

Hi Swathi,

Please find below link to sample code for auto calculating the sub total in ALV , and you can pass the text for subtotal as per requirement :-

[http://wiki.sdn.sap.com/wiki/display/ABAP/ALVStandardSumTotalOr+Subtotal]

Thanks,

Rupali

Read only

0 Kudos
230

Hi Rupali,

Thanks for your quick responde.

The code posted in the link doesnt solve my problem. I could able to get the total and subtotal.

I am facing problem in case of Subtotal text.

Ex: Output display

Assignment City Industry key Customer Debit Credit Balance Remarks ---Column header

TH CHENNAI A001-ACCREDITED 500000022 0.00 32,000.00 32,000.00 --- Output internal table entry

  • TH CHENNAI A001-ACCREDITED 500000022 0.00 32,000.00 32,000.00 --- Subtotal of Customer

    • TH CHENNAI A001-ACCREDITED 0.00 32,000.00 32,000.00 --- Subtotal of Industry key

      • TH CHENNAI 0.00 32,000.00 32,000.00 --- Subtotal of City

I require output like this.

Assignment City Industry key Customer Debit Credit Balance Remarks

TH CHENNAI A001-ACCREDITED 500000022 0.00 32,000.00 32,000.00 --- Output internal table entry

Subtotal of Customer 0.00 32,000.00 32,000.00 --- Subtotal of Customer

Subtotal of Industry 0.00 32,000.00 32,000.00 --- Subtotal of Industry key

Subtotal of City 0.00 32,000.00 32,000.00 --- Subtotal of City

Pease provide me solution or rectify my code if it is wrong.

It will be much helpful to me.

Thanks,

Swathi.

Edited by: swathi Chandra on Dec 29, 2010 10:31 AM

Edited by: swathi Chandra on Dec 29, 2010 10:37 AM

Read only

0 Kudos
230

Hi Swathi,

Use END_OF_LIST event for this.

FORM get_events.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it_events.

READ TABLE it_events WITH KEY name = slis_ev_end_of_list INTO wa_events.

IF sy-subrc = 0.

MOVE 'SUBTOTAL_TEXT' TO wa_events-form.

MODIFY it_events FROM wa_events INDEX sy-tabix.

ENDIF.

ENDFORm.

In form SUBTOTAL_TEXT...ENDFORm display the text you want by write statement.

sequence should be :-

1) call field cat

2) Call perform say get_events which will contain code as shown above.

3) call ALV LIST display

Thanks,

Rupali

Edited by: Rupali Punekar on Dec 29, 2010 8:00 AM

Read only

0 Kudos
230

Hi,

My code sequence is same as u mentioned,

Fill field catalogue

Fill IT_SORT table for subtotal

Fill events table with top of page and subtotal text subroutines

Call ALV list for display

Ps:- I have implemented Subroutines for TOP_OF_PAGE and SUBTOTAL_TEXT events.

But subtotal event is not getting triggered even if i fill EVENTS parameter in ALV fm with appropriate subroutine.

"Use END_OF_LIST event for this."

I could not get this. can u explain in detail??

Why should i use END_OF_LIST event??

Thanks,

Swathi.

Read only

0 Kudos
230

Hi Swathi,

I have written sample code using END_OF_LIST and it is working as per the requirement.

Sample code :-

{wa_sort-fieldname = 'QAUN1'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it_events.

READ TABLE it_events WITH KEY

name = slis_ev_end_of_list INTO wa_events.

IF sy-subrc = 0.

MOVE 'SUBTOTAL_TEXT' TO wa_events-form.

MODIFY it_events FROM wa_events INDEX sy-tabix.

ENDIF.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_callback_user_command = c_f_user_command

is_layout = it_layout

it_fieldcat = t_fieldcat

it_events = it_events

TABLES

t_outtab = t_detail.

IF sy-subrc EQ 0.

ENDIF.

form SUBTOTAL_TEXT.

write :'This is my total'.

endform .}

Thnaks,

Rupali

Read only

0 Kudos
230

Please check whether its working in program BCALV_TEST_GRID_EVENTS. mark the checkbox and check it

Read only

kesavadas_thekkillath
Active Contributor
0 Kudos
230

Did the debugger control enter the subroutine ???

Read only

Former Member
0 Kudos
230

This message was moderated.

Read only

0 Kudos
230

Hi keshav,

No, debugger is not entering the subroutine. I Could not track the reason why it is not entering.

Hi prabhakar,

In my initial post i have posted my subtotal_text subroutine code.

I have cross-checked with your code. It is simlar only.

Please do guide me,

Thank you all,

Swathi.

Read only

0 Kudos
230

Hi Swathi,

How are you calling events ?

Pls try FM 'REUSE_ALV_EVENTS_GET' .

Thanks,

Rupali

Read only

0 Kudos
230

ITOUTPUT is a ctructure with fields ZUONR, ORT01, BRSCH, KUNNR, DEBIT amount and CREDIT amount.

Here is my code.

&----


START-OF-SELECTION.

PERFORM fill_catalogue.

PERFORM sort.

PERFORM prepare_event_table.

PERFORM call_alv.

END-OF-SELECTION.

&----


FORM fill_catalogue .

---

do_sum is set for debit and credit fields.

---

ENDFORM. " FILL_CATALOGUE

&----


FORM sort .

*For sorting and subtotal

wa_sort-spos = 1.

wa_sort-fieldname = 'ZUONR'.

wa_sort-tabname = 'IT_OUTPUT'.

wa_sort-subtot = 'X'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

wa_sort-spos = 2.

wa_sort-fieldname = 'ORT01'.

wa_sort-tabname = 'IT_OUTPUT'.

wa_sort-subtot = 'X'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

ENDFORM. " SORT

&----


FORM prepare_event_table .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

IMPORTING

et_events = it_event.

READ TABLE it_event INTO wa_event

WITH KEY name = slis_ev_top_of_page .

wa_event-form = slis_ev_top_of_page .

MODIFY it_event FROM wa_event INDEX sy-tabix .

READ TABLE it_event INTO wa_event

WITH KEY name = slis_ev_end_of_list .

wa_event-form = slis_ev_end_of_list .

MODIFY it_event FROM wa_event INDEX sy-tabix .

READ TABLE it_event INTO wa_event

WITH KEY name = slis_ev_subtotal_text .

wa_event-form = slis_ev_subtotal_text .

MODIFY it_event FROM wa_event INDEX sy-tabix .

ENDFORM. "prepare_event_table

&----


FORM call_alv .

*Function Module call to generate ALV

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' "GRID

EXPORTING

i_callback_program = sy-repid

it_fieldcat = it_fieldcat[]

is_layout = ls_layout

it_sort = it_sort[]

it_events = it_event[]

i_save = 'A'

TABLES

t_outtab = it_output.

IF sy-subrc <> 0. "#EC *

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " CALL_ALV

&----


Here are my event subroutines

&----


FORM subtotal_text CHANGING

p_total TYPE any

p_subtot_text TYPE slis_subtot_text.

BREAK-POINT.

  • Material level sub total

IF p_subtot_text-criteria = 'ZUONR'.

p_subtot_text-display_text_for_subtotal

= 'Publication level subtotal'.

ENDIF.

ENDFORM . "subtotal_text

&----


FORM end_of_list.

CLEAR g_page_cnt.

ENDFORM. "END_OF_LIST

&----


FORM top_of_page.

DATA: l_line_size TYPE sylinsz. " Line size

DATA: st_list_top_of_page TYPE slis_t_listheader.

DATA: text TYPE string.

CONCATENATE 'Date: '(021) sy-datum6(2) '.' sy-datum4(2) '.' sy-datum+0(4) INTO text.

l_line_size = 140.

WRITE AT l_line_size text.

NEW-LINE.

g_page_cnt = g_page_cnt + 1.

l_line_size = 140.

WRITE AT l_line_size 'Page no:'(022).

l_line_size = l_line_size + 8.

WRITE AT l_line_size g_page_cnt.

  • Display list header

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

i_logo = space

it_list_commentary = st_list_top_of_page.

ENDFORM. " top_of_page

&----


Thanks,

Swathi.

Read only

0 Kudos
230

Hi all,

I could able to resolve the issue by myself. I have debugged the code.

The change i had done is, For the field you want sub total, Add the same entry in LT_FIELDCAT with same data and set the field NO_OUT as 'X'.

Ex:

ls_fieldcat-fieldname = 'ZUONR'.

ls_fieldcat-tabname = 'IT_OUTPUT'.

ls_fieldcat-col_pos = '1'.

ls_fieldcat-seltext_l = 'Publication'(002).

ls_fieldcat-emphasize = 'C111'.

ls_fieldcat-no_out = 'X'.

APPEND ls_fieldcat TO it_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'ZUONR'.

ls_fieldcat-tabname = 'IT_OUTPUT'.

ls_fieldcat-col_pos = '1'.

ls_fieldcat-seltext_l = 'Publication'(002).

ls_fieldcat-emphasize = 'C111'.

APPEND ls_fieldcat TO it_fieldcat.

CLEAR ls_fieldcat.

If the first entry is added in field catalogue, that makes the subtotal tex visible (NO_OUT = 'X'). but column will not be visible in the output list. So, add second entry no_out as space to get output list with this column.

Thank you all,

I am closing the thread.