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: 

Add a row after Total row in ALV report

former_member249594
Participant
0 Kudos

Hi Experts,

I have a report is displayed by ALV format(not use function module to display it but use Class cl_gui_custom_container),I want to add a row after the total row. for example,

Customer amount1 amount2 amount3

10000 1,234 1,000 2,000

10001 4,000 2,000 1,000

10002 1,300 1,000 3,000

11000 1,200 4,000 3,000

Total: 7,734 8,000 9,000

Ratio% 31.27 32.34 36.39

the row of 'Total' is calculated by fieldcat-do_sum = 'X' But after the Total row we need a Ratio row to display the ratio. Yes we can calculate the total amout and ratio and then append it into the output itab, but we don't like this solution.We want to keep the total function in the ALV report.Any experts can poit me a direction. Thanks in advance.

Joe

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Joe,

Can we add a button and in its action we can add a new row (ratio), is it ok for you? if so let me know , I think I can help you!

Regards

Antony Thomas

5 REPLIES 5

Former Member
0 Kudos

You could have an arbitrary field and use this to subtotal. Your ratio would then appear below the "subtotal" line but you will still have a "grand total" line which would look messy.

I would have another ALV grid underneath the first. Switch off all the buttons so it looks like a single line and use this to display your ratios (would be a separate Internal table though)

Hope that helps

0 Kudos

Hi Alistair,

Your second idea is very interesting,I will try to do it later. Thanks very much.

Joe

Former Member
0 Kudos

Hi Joe,

Can we add a button and in its action we can add a new row (ratio), is it ok for you? if so let me know , I think I can help you!

Regards

Antony Thomas

0 Kudos

Hi Antony,

Thanks for your help and I can get your idea. Which Method we sould use to add a new row?APPEND_ROWS of CL_GUI_ALV_GRID. This is my first time to use OOP ALV.

Joe

0 Kudos

Djoe,

First you need to handle the user command,in order to capture the button action. For this you need to implment a class, i am attaching sample codes here

In top include write the following code

CLASS lcl_event_handler DEFINITION .

PUBLIC SECTION .

METHODS:

handle_toolbar FOR EVENT toolbar " To add new functional buttons to the ALV toolbar

OF cl_gui_alv_grid

IMPORTING e_object,

handle_user_command FOR EVENT user_command " To implement user commands

OF cl_gui_alv_grid

IMPORTING e_ucomm .

PRIVATE SECTION.

ENDCLASS. " Lcl_event_handler DEFINITION

Now <b>Class implementation</b>

CLASS lcl_event_handler IMPLEMENTATION .

METHOD handle_toolbar. " Handle Toolbar

PERFORM f9500_handle_toolbar USING e_object.

ENDMETHOD . " Handle_toolbar

METHOD handle_user_command . " Handle User Command

PERFORM f9600_handle_user_command USING e_ucomm .

ENDMETHOD.

ENDCLASS . " lcl_event_handler IMPLEMENTATION

FORM f9600_handle_user_command USING p_e_ucomm TYPE sy-ucomm.

CONSTANTS:c_newl(4) TYPE c

VALUE 'NEWL', " New line

c_copy(4) TYPE c

VALUE 'COPY', " Copy

c_corr(4) TYPE c

VALUE 'CORR'. " Correction

CASE p_e_ucomm .

WHEN c_newl.

  • Create a new line

PERFORM f9610_insert_new_line.

ENDFORM. " f9600_handle_user_command

FORM f9610_insert_new_line .

*Data Declarations

DATA: lt_rows TYPE lvc_t_row, " Itab for row property

ls_rows TYPE lvc_s_row, " Work area for row

lv_cntid TYPE i. " Counter

DATA: gv_index TYPE sy-index.

CLEAR gs_last.

CALL METHOD gr_alvgrid->get_selected_rows

IMPORTING

et_index_rows = lt_rows.

READ TABLE lt_rows INTO ls_rows INDEX 1.

IF sy-subrc EQ 0.

gv_index = ls_rows-index + 1.

ELSE.

gv_index = 1.

ENDIF.

DESCRIBE TABLE gt_last LINES lv_cntid.

lv_cntid = lv_cntid + 1.

gs_last-cntid = lv_cntid.

INSERT gs_last INTO gt_last INDEX gv_index.

LOOP AT gt_last INTO gs_last FROM gv_index TO gv_index.

  • Make the new line editable

PERFORM f9611_style.

ENDLOOP.

CALL METHOD gr_alvgrid->refresh_table_display

EXCEPTIONS

finished = 1

OTHERS = 2.

ENDFORM. " f9610_insert_new_line

You can ask questions doubts if any!

regards

Antony Thomas