alv - how can i make a subtotal to a line ? ? ?

Question: i use:

data: grid type ref to cl_gui_alv_grid,
layout type lvc_s_layo,
fieldcat type lvc_t_fcat,
g_container type scrfname
value 'BCALV_GRID_DEMO_0100_CONT1',
grid1 type ref to cl_gui_alv_grid,


also i use:

call method grid1->set_table_for_first_display



now, i want that specific line of the internal table will be subtotal line

how can i do this ? ? ? ? ?

i searched on the forum and i didn't find the answer.

Answer:
Have you changed anything to the field catalog like setting the SUM indicator?? The help on ALV OO style is great, over 100 pages and it got all fields /settings / events explained
_________________
Only sheep and Tuly Idiots need a leader

Answer:
my forms that i use field-catalog:

*&---------------------------------------------------------------------*
*& Form alv
*&---------------------------------------------------------------------*
form alv .

perform create_alv_list using 'total_persg_persk'
it_struc_persg_persk[].

perform add_column using 'DESC_PERSG' text-001.
optimize_width.
perform add_column using 'DESC_PERSK' text-003.
optimize_width.
perform add_column using 'SUM' text-004.
optimize_width.

perform display_alv_list.

endform. " alv
*&--------------------------------------------------------------------*
*& Form create_alv_list
*&--------------------------------------------------------------------*
form create_alv_list using tb_sname type dd02l-tabname
tb_tn type table.

tb_structure_name = tb_sname.
assign tb_tn to <tb_tabname>.

endform. "create_alv_list
*&--------------------------------------------------------------------*
*& Form add_column
*&--------------------------------------------------------------------*
form add_column using fieldname like wa_fcat-fieldname
text_l like wa_fcat-scrtext_l.

if open_column = 'X'.
wa_fcat-just = 'R'.
append wa_fcat to fieldcat.
endif.
open_column = 'X'.
clear wa_fcat.

move fieldname to wa_fcat-fieldname.
move text_l to wa_fcat-scrtext_l.

endform. "add_column


now, what should i do to my field-catalog to add subtotal ? ? ?

Answer:
To sum a column, put "X" in field "DO_SUM" in fieldcat.

See, that was easy!


_________________
The Doc
Magna Grand Docot of the Tuly Idiot Order

2007 Basic Rules

Answer:
i add:

*&--------------------------------------------------------------------*
*& Form add_column
*&--------------------------------------------------------------------*
form add_column using fieldname like wa_fcat-fieldname
text_l like wa_fcat-scrtext_l.

if open_column = 'X'.
if fieldname = 'SUM'.
wa_fcat-do_sum = 'X'.
endif.
wa_fcat-just = 'R'.
append wa_fcat to fieldcat.
endif.
open_column = 'X'.
clear wa_fcat.

move fieldname to wa_fcat-fieldname.
move text_l to wa_fcat-scrtext_l.

endform. "add_column



i still don't get subtotal why ? ? ? ?

Answer:
This works for me:-

1.
PERFORM do_build USING
'DMBTR' 'X' sp sp sp sp sp sp sp sp.

2.
FORM do_build USING p1 p2 p3 p4 p5 p6 p7 p8 p9 p10.

DATA: ls_fieldcat TYPE lvc_t_fcat WITH HEADER LINE.

LOOP AT alv_fieldcat INTO ls_fieldcat WHERE fieldname EQ p1.
ls_fieldcat-do_sum = p2.
ls_fieldcat-outputlen = p3.
ls_fieldcat-hotspot = p4.
ls_fieldcat-coltext = p5.
ls_fieldcat-key = p6.
ls_fieldcat-emphasize = p7.
ls_fieldcat-col_pos = p8.
ls_fieldcat-no_out = p10.

MODIFY alv_fieldcat FROM ls_fieldcat.
ENDLOOP.

ENDFORM. " do_build

3.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT grid
EXPORTING i_parent = g_custom_container.

CALL METHOD grid->set_table_for_first_display
EXPORTING
i_save = 'A'
is_variant = v_variant
i_structure_name = 'ZINDIATAX01'
is_layout = alv_layout
CHANGING
it_fieldcatalog = alv_fieldcat[]
it_sort = alv_sort[]
it_outtab = tab_data.

CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click FOR grid.

CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_hotspot_click FOR grid.
ENDIF.

You are summing the column with the value in it aren't you???


_________________
The Doc
Magna Grand Docot of the Tuly Idiot Order

2007 Basic Rules

Answer:
looks, i have a problem.

i have an internal table that has subtotal lines and at the end total.

i only want to loop at the internal table and when i arrive to subtotal line

( i hav indicator to know subtotal line )

i want to mark the line and also make sy-uline above the line and

under the line how do i do this ? ? ?

Answer:
No, no, no...

Let ALV grid do the summing for you. Remove the subtotals from your internal table, then add the DO_SUM flag to the value columns, and sit back...

You will get totals for each of the value columns, all summed up automatically by currency...

Viola (big violin )


_________________
The Doc
Magna Grand Docot of the Tuly Idiot Order

2007 Basic Rules

Answer:
can i control the subtotal line ? ? ?

the subtotal display in last line and i want to add text.

also, i want to decide which line should be display the subtotal

up bottom middle of the report.

how can i do this ? ? ?

Answer:
If you want to do everything manually then use the sort table "IT_SORT" of structure: LVC_T_SORT

e.g.
alv_sort-spos = 1.
alv_sort-fieldname = 'LIFNR'.
alv_sort-up = 'X'.
APPEND alv_sort. CLEAR alv_sort.
alv_sort-spos = 2.
alv_sort-fieldname = 'MONAT'.
alv_sort-up = 'X'.
alv_sort-subtot = 'X'.
APPEND alv_sort. CLEAR alv_sort.

This example sorts by vendor and period with a subtotal after period (by currency).
_________________
The Doc
Magna Grand Docot of the Tuly Idiot Order

2007 Basic Rules

Answer:
i use:

it_sort of structure: LVC_T_SORT

i sort my internal table.

now,

how can i add a break to each subtotal i mean

( add horizontal line above and below the subtotal ) ? ? ?
Copyright ?2007 - 2008 www.jt77.com