ALV sum average subtotal...
Can anyone show me where in code of class CL_GUI_ALV_GRID are calculated:
sum, average, max, min.
I need to calculatete this values on a huge amount of data and I;m interesting how this is done in ALV.
Regards, Tomek
Hi Tomasz,
method GET_TOTALS of class CL_GUI_ALV_GRID says this:
method get_totals .
* not in use while import/export from memory has to be used for
* saving the internal tables. Therfore the function module
* LVC_TOTALS_GET is used.
endmethod.
For subtotals, take a look at method GET_GROUPLEVELS, line 65:
data: l_sumlevel type i,
l_sumlevel_unit type i.
call function 'LVC_SUMLEVEL_TRANSLATE'
changing
ct_sort = m_cl_variant->mt_sort
ct_grouplevels = m_cl_variant->mt_grouplevels
c_sumlevel_global = l_sumlevel
c_sumlevel_unit = l_sumlevel_unit.
Hope this helps,
R.
Similar Messages
-
Is there any functionality for AVERAGE in ALV, like do_sum, subtot?
Hi Experts,
In my_alv report, am doing sub/totals for prices, by using do_sum, subtot functions.........fine. But, I need to do/display the AVERAGE value for Discount % column?
Is there any functionality for AVERAGE in ALV, like do_sum, subtot?
thanqhi
check these links out
http://www.sapfans.com/forums/viewtopic.php?t=20386
http://www.sapfans.com/forums/viewtopic.php?t=85191
http://www.sapfans.com/forums/viewtopic.php?t=88401
http://www.sapfans.com/forums/viewtopic.php?t=17335
regards
vijay
reward points if helpful -
HI Guys
we have an business requirement to store data in average figures ,
The values are entered on the base member level but in reports we need to show average values on the parents level instead of sum
( by default in BPC values are sum in node level),it does not make sense to sum averages on parent nodes.
we managed it with excel formulas ,but we r facing the problem with dimensions which are in context.
(i tried using dim memeber formulas but AVG key word is not accepting the system in member formulas)
at last by using formula we managed the report but im worried abt that if there is no formulas ,how we will manage
pls suggest any solution to show average values on the node level in specific reportsHi Krao,
Please define what do you mean by average - arithmetic average or weighted average (has more business sense to my mind).
Also, please provide some samples, explaining dimensions used in average calculation.
In our case we use dimension member formulas to show average prices, discounts etc. in the reports.
B.R. Vadim -
ALV sums of lines depending on value of field of the line?
Hi,
We have an ALV and would like to get the sums depending on the value of a field of each line.
For example: imagine we have an ALV, and there are two kinds of lines: one have a counter=1, and others have a counter=2. Is it possible to receive two totals in the ALV, one for the lines that have counter=1, and one for the lines that have counter=2? And that when a filter is being applied, the sums change automatically?
Thx!Hi,
Please the below code which ill help to change the subtotal text, you need do manula total and replace with the wa of the subtotal with you calculated sum. In the below code i replaced a break point where you need to add your coding
*& Report Z_ALV_SUBTOTAL
REPORT Z_ALV_SUBTOTAL.
*& 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:
* INTERNAL TABLE TO STORE EKPO 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' ' ' ' ' ' ',
'01' '03' 'MATNR1' 'I_EKPO' 'L' 'Material No'(005) ' ' ' ' ' ' ' ',
'01' '04' 'WERKS' 'I_EKPO' 'L' 'Plant'(006) '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
" 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
" 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 = 'Materia l'(009).
BREAK-POINT.
here calucate the total and change the p_total
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_text -
Hi everybody,
I know that ALV has the subtotals function (application bar), but does someone knows if ALV classes or FM(REUSE_ALV...) have a way to define another formula (i.e. average of values in the group) instead sum of the group?
Thanks!
Flavio FurlanHi,
There is an option for Mean, Minimum and Maximum in the standard ALV. If you go to the Menu path Edit -> Calculate with respect to a column with numeric values, you can choose to display:
Mean (Average)
Minimum
Maximum
Cheers,
Bhanu -
ALV Report - Average and Grand total.
Hi,
Could you tell me in ALV, how i can calculate the average of a particular field and display it in the grand total row?
What is the property to display the grand total alone, without the subtotal?To force a grand total line, first you need to have a field in your internal table that can be totaled, when defining that field in your field catalog, you must set the flag for DO_SUM = 'X', you may also need to set the DATATYPE = 'QUAN'. Then the grand total line will show automatically.
Regards,
RIch Heilman -
On-click on ALV sum line to raise an event
Hello, ladies and gentlemen,
Happy New Year first of all.
I have a following problem: I have an ALV grid and in each line I have an icon, which one can on-click and something happens. That works fine. But now I was challenged to add a sum line which should support the same on-click event, but should process the data of all lines that belong to this SUM group in one batch.
Of course I can put in the "manual sum lines" - define groups that will support these sum lines and then add extra lines into the grid data. Unfortunatelly there is no way of telling which lines will belong to which group. I need the ALV standard summing so any user can define his own groups.
Has anybody ever tried such thing? I am using cl_gui_alv_grid OO ALV.
Thanks for any input,
cheers OttoHi Otto.
You can check the logic below. Please try to disable the sort functionality as done below in the ALV because the subtotals returned by the method get_subtotals is always sorted in ascending order.
report z335_alv_sel.
class lcl definition deferred.
type-pools: slis.
types:begin of t_data,
werks type werks_d,
labst type mard-labst,
end of t_data.
data :i_exclude type ui_functions,
i_fcat type slis_t_fieldcat_alv ,
i_sort type lvc_t_sort,
i_data type table of t_data,
i_cat type lvc_t_fcat,
wa_sort like line of i_sort,
wa_exclude type ui_func,
wa type t_data,
wa_cat type lvc_s_fcat,
cont type ref to cl_gui_custom_container,
grid type ref to cl_gui_alv_grid,
receiver type ref to lcl.
class lcl definition.
public section.
methods handle_click for event double_click of
cl_gui_alv_grid importing e_row
e_column.
endclass. "lcl DEFINITION
class lcl implementation.
method handle_click.
data:val(10) type n,
it type ref to data.
field-symbols: <ft_tab> type standard table,
<fs_tab> type any,
<ff_field> type any.
if e_row+0(1) = 'S'. "Subtotal
val = e_row+23(10).
call method grid->get_subtotals
importing
ep_collect01 = it.
assign it->* to <ft_tab>.
read table <ft_tab> assigning <fs_tab> index val.
if sy-subrc = 0.
assign component 1 of structure <fs_tab> to <ff_field>.
if <ff_field> is assigned.
loop at i_data into wa where werks = <ff_field>.
"Process your block Here
endloop.
endif.
endif.
endif.
endmethod. "handle_click
endclass. "lcl IMPLEMENTATION
start-of-selection.
call screen 100.
module fill_data output.
select werks labst from mard
into corresponding fields of table i_data
up to 1000 rows where labst > 0.
if sy-subrc = 0.
wa_cat-fieldname = 'WERKS'.
append wa_cat to i_cat.
clear wa_cat.
wa_cat-fieldname = 'LABST'.
wa_cat-do_sum = 'X'.
append wa_cat to i_cat.
clear wa_cat.
wa_sort-fieldname = 'WERKS'.
wa_sort-subtot = 'X'.
wa_sort-group = 'X'.
wa_sort-up = 'X'.
append wa_sort to i_sort.
wa_exclude = cl_gui_alv_grid=>mc_fc_sort .
append wa_exclude to i_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_sort_asc .
append wa_exclude to i_exclude.
wa_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc .
append wa_exclude to i_exclude.
endif.
endmodule. " fill_data OUTPUT
module display output.
if cont is initial .
create object cont
exporting
container_name = 'CONT1'.
create object grid
exporting
i_parent = cont.
call method grid->set_table_for_first_display
exporting
it_toolbar_excluding = i_exclude
changing
it_outtab = i_data[]
it_sort = i_sort[]
it_fieldcatalog = i_cat[].
create object receiver.
set handler receiver->handle_click for grid.
endif.
endmodule. "DISPLAY OUTPUT -
ALV sums using REUSE_ALV_LIST_DISPLAY
I am working in an old 4.0 system so I am using the function REUSE_ALV_LIST_DISPLAY to output my data, but I can't get teh ALV grid to include the totals button or indeed sum my values despite populating the field cat with 'Do_sum'.
Andy idead
ls_fieldcat-fieldname = 'KWMENG'.
ls_fieldcat-col_pos = '9'.
ls_fieldcat-ref_fieldname = 'KWMENG'.
ls_fieldcat-ref_tabname = 'GIT_DETAIL'.
ls_fieldcat-tabname = 'GIT_DETAIL'.
"ls_fieldcat-ddictxt = 'L'.
ls_fieldcat-outputlen = '14'.
ls_fieldcat-seltext_l = 'Order Qty'.
ls_fieldcat-do_sum = 'X'.
append ls_fieldcat to lit_fieldcat. clear ls_fieldcat.
* Displays the ALV grid
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = w_repid
it_fieldcat = lit_fieldcat[]
is_layout = x_layout
it_sort = lit_sort[]
i_callback_pf_status_set = w_status
i_callback_user_command = w_comm
i_save = 'X'
it_events = lit_event[]
i_grid_title = w_title
tables
t_outtab = git_detail[]
exceptions
program_error = 1
others = 2.To display the totals in the grid display add the following logic where you are populating the field catalog.
IF fldname = 'AMOUNT'.
wa_fcat-do_sum = 'X'.
ENDIF.
APPEND wa_fcat TO i_fieldcat.
CLEAR wa_fcat.
To display the subtotals in the grid display.
FORM populate_sort .
Sort on material
wa_sort-spos = '01' .
wa_sort-fieldname = 'MATNR'.
wa_sort-tabname = 'T_MAT'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort .
CLEAR wa_sort.
ENDFORM. " populate_sort
Get the ALV grid event and pass the form name to subtotal_text event.
FORM get_events .
CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE
'SUBTOTAL_TEXT'.
DATA: ls_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = it event
EXCEPTIONS
list_type_wrong = 0
OTHERS = 0.
Subtotal
READ TABLE it_event INTO ls_event
WITH KEY name = slis_ev_subtotal_text.
IF sy-subrc = 0.
MOVE c_formname_subtotal_text TO ls_event-form.
MODIFY it_event FROM ls_event INDEX sy-tabix.
ENDIF.
ENDFORM.
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.
ENDFORM. "subtotal_text
After this just pass it_event and it_sort to the ALV grid display.
Hope this helps you. -
HI
IN ALV'S HOW TO FIND THE SUB TOTAL, CODING TO FIND THE SUBTOTAL.
Edited by: Alvaro Tejada Galindo on Jan 11, 2008 4:09 PMHi Jyothsna,
Try the below code.
report zalv10.
type-pools: slis.
data: g_repid like sy-repid,
gs_print type slis_print_alv,
gt_list_top_of_page type slis_t_listheader,
gt_events type slis_t_event,
gt_sort type slis_t_sortinfo_alv,
gs_layout type slis_layout_alv,
gt_fieldcat type slis_t_fieldcat_alv,
fieldcat_ln like line of gt_fieldcat,
col_pos type i.
data: begin of itab,
field1(5) type c,
field2(5) type c,
field3(5) type p decimals 2,
end of itab.
data: begin of itab1 occurs 0.
include structure itab.
data: end of itab1.
data: begin of itab_fieldcat occurs 0.
include structure itab.
data: end of itab_fieldcat.
Print Parameters
parameters:
p_print as checkbox default , PRINT IMMEDIATE
p_nosinf as checkbox default X, NO SELECTION INFO
p_nocove as checkbox default , NO COVER PAGE
p_nonewp as checkbox default , NO NEW PAGE
p_nolinf as checkbox default X, NO PRINT LIST INFO
p_reserv type i. NO OF FOOTER LINE
initialization.
g_repid = sy-repid.
perform print_build using gs_print. Print PARAMETERS
start-of-selection.
TEST DATA
move TEST1 to itab1-field1.
move TEST1 to itab1-field2.
move 10.00 to itab1-field3.
append itab1.
move TEST2 to itab1-field1.
move TEST2 to itab1-field2.
move 20.00 to itab1-field3.
append itab1.
do 50 times.
append itab1.
enddo.
end-of-selection.
perform build.
perform eventtab_build changing gt_events.
perform comment_build changing gt_list_top_of_page.
perform call_alv.
form build.
DATA FIELD CATALOG
Explain Field Description to ALV
data: fieldcat_in type slis_fieldcat_alv.
clear fieldcat_in.
fieldcat_ln-fieldname = FIELD1.
fieldcat_ln-tabname = ITAB1.
*FIELDCAT_LN-NO_OUT = X. FIELD NOT DISPLAY, CHOOSE FROM LAYOUT
fieldcat_ln-key = . *SUBTOTAL* KEY
fieldcat_ln-no_out = .
fieldcat_ln-seltext_l = HEAD1.
append fieldcat_ln to gt_fieldcat.
clear fieldcat_in.
fieldcat_ln-fieldname = FIELD2.
fieldcat_ln-tabname = ITAB1.
fieldcat_ln-no_out = X.
fieldcat_ln-seltext_l = HEAD2.
append fieldcat_ln to gt_fieldcat.
clear fieldcat_in.
fieldcat_ln-fieldname = FIELD3.
fieldcat_ln-tabname = ITAB1.
fieldcat_ln-ref_fieldname = MENGE. <- REF FIELD IN THE DICTIONNARY
fieldcat_ln-ref_tabname = MSEG. <- REF TABLE IN THE DICTIONNARY
fieldcat_ln-no_out = .
fieldcat_ln-do_sum = X. SUM UPON DISPLAY
append fieldcat_ln to gt_fieldcat.
DATA SORTING AND *SUBTOTAL
*data: gs_sort type slis_sortinfo_alv.
clear gs_sort.
gs_sort-fieldname = FIELD1.
gs_sort-spos = 1.
gs_sort-up = X.
gs_sort-subtot = X. ****CRUCIAL STATEMENT*****
append gs_sort to gt_sort.
clear gs_sort.
gs_sort-fieldname = FIELD2.
gs_sort-spos = 2.
gs_sort-up = X.
GS_SORT-SUBTOT = X. ***THIS SHOULD NOT BE UNCOMENTED*
append gs_sort to gt_sort.
endform.
form call_alv.
ABAP List Viewer
call function REUSE_ALV_LIST_DISPLAY
exporting
I_INTERFACE_CHECK =
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
i_callback_program = g_repid
I_CALLBACK_PF_STATUS_SET =
I_CALLBACK_USER_COMMAND =
i_structure_name = ITAB1
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
it_sort = gt_sort[]
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = X
I_SAVE =
IS_VARIANT =
it_events = gt_events[]
IT_EVENT_EXIT =
is_print = gs_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 = itab1
exceptions
program_error = 1
others = 2.
endform.
HEADER FORM
form eventtab_build changing lt_events type slis_t_event.
constants:
gc_formname_top_of_page type slis_formname value TOP_OF_PAGE.
*GC_FORMNAME_END_OF_PAGE TYPE SLIS_FORMNAME VALUE END_OF_PAGE.
data: ls_event type slis_alv_event.
call function REUSE_ALV_EVENTS_GET
exporting
i_list_type = 0
importing
et_events = lt_events.
read table lt_events with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move gc_formname_top_of_page to ls_event-form.
append ls_event to lt_events.
endif.
define END_OF_PAGE event
READ TABLE LT_EVENTS WITH KEY NAME = SLIS_EV_END_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE GC_FORMNAME_END_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO LT_EVENTS.
ENDIF.
endform.
form comment_build changing gt_top_of_page type slis_t_listheader.
data: gs_line type slis_listheader.
clear gs_line.
gs_line-typ = H.
gs_line-info = HEADER 1.
append gs_line to gt_top_of_page.
clear gs_line.
gs_line-typ = S.
gs_line-key = STATUS 1.
gs_line-info = INFO 1.
append gs_line to gt_top_of_page.
gs_line-key = STATUS 2.
gs_line-info = INFO 2.
append gs_line to gt_top_of_page.
CLEAR GS_LINE.
GS_LINE-TYP = A.
GS_LINE-INFO = ACTION.
APPEND GS_LINE TO GT_TOP_OF_PAGE.
endform.
form top_of_page.
call function REUSE_ALV_COMMENTARY_WRITE
exporting
it_list_commentary = gt_list_top_of_page.
write: sy-datum, Page No, sy-pagno left-justified.
endform.
form end_of_page.
write at (sy-linsz) sy-pagno centered.
endform.
PRINT SETTINGS
form print_build using ls_print type slis_print_alv.
ls_print-print = p_print. PRINT IMMEDIATE
ls_print-no_print_selinfos = p_nosinf. NO SELECTION INFO
ls_print-no_coverpage = p_nocove. NO COVER PAGE
ls_print-no_new_page = p_nonewp.
ls_print-no_print_listinfos = p_nolinf. NO PRINT LIST INFO
ls_print-reserve_lines = p_reserv.
endform.
<REMOVED BY MODERATOR>
Thankyou,
Regards.
Edited by: Alvaro Tejada Galindo on Jan 11, 2008 4:10 PM -
Output in alv -- sum on the particular field
Dear Freinds,
I have developed a report using a ALV grid . The output i having the fields
as
orgunit orgdesc count name salary total salary.
1234 test1 raja 100 1200
2 rama 200 2400
300 3600 -> i want count 2 in this line
1235 test 2 1 rana 500 6000
500 6000 -> i want count 1 in this line
Can i give the Count 1 and 2 in the same row where the Totals --- 500 and 6000
and 300 and 3600 are being displayed int he above row ?
the user says he want to have the count in the down along witht he total's lline
the count is not a now a currency field i tried to sum it is not summing because it is
NUM data type.
As per the above data(sample data) we can see that Orgunit(1234) is having two employees hence the count was two . For the Orgunit(1235) we have only one employee the count was only one . Nowe my question is can i give the counts 2 in the first row and the count 1 in the second rown can give along with the total.........line ...
if so what i can do the change in the field cat.
When iam using in my field cat for getting the output as above
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 0.
ls_fieldcat-fieldname = 'ORGUNIT'.
ls_fieldcat-seltext_l = text-015. "'Orgunit'.
ls_fieldcat-key = 'X'.
ls_fieldcat-key_sel = 'X'.
ls_fieldcat-no_out = 'X'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 1.
ls_fieldcat-fieldname = 'ORGTEXT'.
ls_fieldcat-seltext_l = text-016. "'Orgdesc'.
ls_fieldcat-no_out = 'X'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 2.
ls_fieldcat-fieldname = 'COUNT'. ---This is data type Numc
ls_fieldcat-seltext_l = 'H.Count'.
ls_fieldcat-outputlen = 4.
ls_fieldcat-do_sum = 'X'. -
> it is not getting summed up
ls_fieldcat-datatype = 'NUMC'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 3.
ls_fieldcat-fieldname = 'STAFFNAME'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-seltext_l = 'Name'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SALARY'.
ls_fieldcat-seltext_m = 'Salary'.
ls_fieldcat-col_pos = 4.
ls_fieldcat-outputlen = 17.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-datatype = 'CURR'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TOTAL'.
ls_fieldcat-seltext_m = 'Total Salary'.
ls_fieldcat-col_pos = 5.
ls_fieldcat-outputlen = 17.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-datatype = 'CURR'.
APPEND ls_fieldcat TO fp_i_fieldcat.Dear Kiran,
iam seding the alv output which i got can you please correct my code
where i can give .........since my basic question was the Count which iam
getting in the below is 2 (data type NUM4) how can i do sum on this 2 or subtotal??
i want the count 2 to come in the total....line only ..can you please let me know what is the parameter i have to use ........i couldnt find the
Aggregation in my tool bar...
orgunit orgdesc count name salary total salary.
12345 test raja 100
space space 2 rama 200
300 -> i want count 2 in this line
1235 test 2 1 rana 500
500 6000 -> i want count 1 in this line
Can i give the Count 1 and 2 in the same row where the Totals --- 500 and 6000
and 300 and 3600 are being displayed int he above row ?
the user says he want to have the count in the down along witht he total's lline
the count is not a now a currency field i tried to sum it is not summing because it is
NUM data type.
As per the above data(sample data) we can see that Orgunit(1234) is having two employees hence the count was two . For the Orgunit(1235) we have only one employee the count was only one . Nowe my question is can i give the counts 2 in the first row and the count 1 in the second rown can give along with the total.........line ...
if so what i can do the change in the field cat.
When iam using in my field cat for getting the output as above
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 0.
ls_fieldcat-fieldname = 'ORGUNIT'.
ls_fieldcat-seltext_l = text-015. "'Orgunit'.
ls_fieldcat-key = 'X'.
ls_fieldcat-key_sel = 'X'.
ls_fieldcat-no_out = 'X'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 1.
ls_fieldcat-fieldname = 'ORGTEXT'.
ls_fieldcat-seltext_l = text-016. "'Orgdesc'.
ls_fieldcat-no_out = 'X'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 2.
ls_fieldcat-fieldname = 'COUNT'. ---This is data type Numc
ls_fieldcat-seltext_l = 'H.Count'.
ls_fieldcat-outputlen = 4.
ls_fieldcat-do_sum = 'X'. -
> it is not getting summed up
ls_fieldcat-datatype = 'NUMC'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-col_pos = 3.
ls_fieldcat-fieldname = 'STAFFNAME'.
ls_fieldcat-no_out = 'X'.
ls_fieldcat-seltext_l = 'Name'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SALARY'.
ls_fieldcat-seltext_m = 'Salary'.
ls_fieldcat-col_pos = 4.
ls_fieldcat-outputlen = 17.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-datatype = 'CURR'.
APPEND ls_fieldcat TO fp_i_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TOTAL'.
ls_fieldcat-seltext_m = 'Total Salary'.
ls_fieldcat-col_pos = 5.
ls_fieldcat-outputlen = 17.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-datatype = 'CURR'.
APPEND ls_fieldcat TO fp_i_fieldcat. -
ALV total and subtotaling problem
Hi,
I am unable to proceed in total and subtotal using ALV List Display.
Fico Scenario
For each change of Asset Location within same Asset Class:
Column Logic
Location Total Location wise do the Sum of the columns u201CAcquired Valueu201D, u201CSalv/168 Allow Sec 179u201D, Depreciable Basisu201D, u201CPrior Accum Depreciationu201D, u201CDepreciation This Runu201D, Current YTD Depreciationu201D, Current Accum Depreciationu201D and u201CNet Book Valueu201D
Code Done :
FORM summation .
DEFINE m_fieldcat.
add 1 to gs_fieldcat-col_pos.
gs_fieldcat-fieldname = &1.
gs_fieldcat-ref_tabname = 'gt_fieldcat1'.
gs_fieldcat-do_sum = &2.
gs_fieldcat-cfieldname = &3.
append gs_fieldcat to gt_fieldcat1.
END-OF-DEFINITION.
DEFINE m_sort.
add 1 to wa_sort-spos.
wa_sort-fieldname = &1.
wa_sort-up = 'X'.
wa_sort-subtot = &2.
append wa_sort to i_sort.
END-OF-DEFINITION.
m_fieldcat 'ANBTR' 'X' ''.
m_fieldcat 'SALV' 'X' ''.
m_fieldcat 'DEP_BASIC' 'X' ''.
m_fieldcat 'DEP_LAST' 'X' ''.
m_fieldcat 'DEP_CURRUN' 'X' ''.
m_fieldcat 'DEP_CURYTD' 'X' ''.
m_fieldcat 'DEP_ACC' 'X' ''.
m_fieldcat 'NET_BOOK' 'X' ''.
m_sort 'ANLKL' 'X'.
m_sort 'SALV' 'X'.
m_sort 'DEP_BASIC' 'X'.
m_sort 'DEP_LAST' 'X'.
m_sort 'DEP_CURRUN' 'X'.
m_sort 'DEP_CURYTD' 'X'.
m_sort 'DEP_ACC' 'X'.
m_sort 'NET_BOOK' 'X'.
gs_layout-cell_merge = 'X'.
ENDFORM. " SUMMATION
FORM alv_display .
PERFORM build_catlog.
PERFORM eventtab_field USING gs_event.
PERFORM comment_build USING gt_list_top_of_page[].
perform html_top_of_page using top. "TYPE REF TO cl_dd_document.
gv_repid = sy-repid.
gs_variant-report = gv_repid.
gs_layout-colwidth_optimize = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-info_fieldname = 'LINE_COLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gv_repid
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
is_layout = gs_layout
is_variant = gs_variant
it_events = gs_event[]
it_fieldcat = gt_fieldcat1[]
i_save = 'A'
TABLES
t_outtab = gt_output[]
EXCEPTIONS
program_error = 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.
ENDFORM. " ALV_DISPLAY
Any Help or Suggestions needed.
Better if guided with the code as m new to ALV Reports.Hi,
I am unable to proceed in total and subtotal using ALV List Display.
Fico Scenario
For each change of Asset Location within same Asset Class:
Column Logic
Location Total Location wise do the Sum of the columns u201CAcquired Valueu201D, u201CSalv/168 Allow Sec 179u201D, Depreciable Basisu201D, u201CPrior Accum Depreciationu201D, u201CDepreciation This Runu201D, Current YTD Depreciationu201D, Current Accum Depreciationu201D and u201CNet Book Valueu201D
Code Done :
FORM summation .
DEFINE m_fieldcat.
add 1 to gs_fieldcat-col_pos.
gs_fieldcat-fieldname = &1.
gs_fieldcat-ref_tabname = 'gt_fieldcat1'.
gs_fieldcat-do_sum = &2.
gs_fieldcat-cfieldname = &3.
append gs_fieldcat to gt_fieldcat1.
END-OF-DEFINITION.
DEFINE m_sort.
add 1 to wa_sort-spos.
wa_sort-fieldname = &1.
wa_sort-up = 'X'.
wa_sort-subtot = &2.
append wa_sort to i_sort.
END-OF-DEFINITION.
m_fieldcat 'ANBTR' 'X' ''.
m_fieldcat 'SALV' 'X' ''.
m_fieldcat 'DEP_BASIC' 'X' ''.
m_fieldcat 'DEP_LAST' 'X' ''.
m_fieldcat 'DEP_CURRUN' 'X' ''.
m_fieldcat 'DEP_CURYTD' 'X' ''.
m_fieldcat 'DEP_ACC' 'X' ''.
m_fieldcat 'NET_BOOK' 'X' ''.
m_sort 'ANLKL' 'X'.
m_sort 'SALV' 'X'.
m_sort 'DEP_BASIC' 'X'.
m_sort 'DEP_LAST' 'X'.
m_sort 'DEP_CURRUN' 'X'.
m_sort 'DEP_CURYTD' 'X'.
m_sort 'DEP_ACC' 'X'.
m_sort 'NET_BOOK' 'X'.
gs_layout-cell_merge = 'X'.
ENDFORM. " SUMMATION
FORM alv_display .
PERFORM build_catlog.
PERFORM eventtab_field USING gs_event.
PERFORM comment_build USING gt_list_top_of_page[].
perform html_top_of_page using top. "TYPE REF TO cl_dd_document.
gv_repid = sy-repid.
gs_variant-report = gv_repid.
gs_layout-colwidth_optimize = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-info_fieldname = 'LINE_COLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gv_repid
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
is_layout = gs_layout
is_variant = gs_variant
it_events = gs_event[]
it_fieldcat = gt_fieldcat1[]
i_save = 'A'
TABLES
t_outtab = gt_output[]
EXCEPTIONS
program_error = 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.
ENDFORM. " ALV_DISPLAY
Any Help or Suggestions needed.
Better if guided with the code as m new to ALV Reports. -
Hi, how can we do aaverage weightness in alv grid on grouped levels records.
EX:
level group 1 level group2 qty price average weightness
PL1 GR1 10 30 (10*30)/23
PL1 GR1 13 32 (13*32)/23
subtotal GR1 23 62 31,13
PL1 GR2 10 25 (10*25)/25
PL1 GR2 15 28 (15*28)/25
subtotal GR2 25 53 26,8
THANX.I think you will have to handle this in a program and populate new columns AVERAGE. I am afraid to say i did not find any functionality for AVERAGE in ALV.
ashish -
Hi,
I want to display the Total and Subtotal in Alv in Webdynpro Abap, and i am getting this Error( Access via 'NULL' object reference not possible) and also i have checked the Cardinality also. Please get me a Good Solution.I think your node( the node which is binded to data node of alv interface controller ) having collection cardinality of 1:1, if yes, then change it to 0:N,
i hope this will solve the issue.
If you still get the error, go to st22, open your error, go down that page (keep pressing pagedown button ), then you will find your code and there find this arrow >>>>> then let me know that code line.
Regards
Srinivas -
Having issue with a Sum/Average program
The issue I get when I run the command is, let's say I enter 4 numbers, 5, 7, 9, 16 then enter a 0 to end the count, the avg it gives me is 8.0 instead of the 9.25 it should be. Any insight would be greatly appreciated.
import java.util.Scanner;
public class StephenVanoverSumAverage
public static void main(String[] args)
Scanner keyboard = new Scanner(System.in);
double count = 0.0;
double sum = 0.0;
double num;
System.out.println("Enter a number (Type 0 to quit): ");
num = keyboard.nextInt();
while ( num !=0 )
System.out.println("Enter a number (Type 0 to quit): ");
num = keyboard.nextInt();
sum += num;
count++;
double average = sum / count;
System.out.printf("Average is " + average);
}Not quite, since the first number is discarded. The zero is included in the sum, but the first number entered is not. The count is incremented for the zero, true, but I think that is not the problem.
Still, the code could be cleaner with respect to both when the count is incremented, and what numbers are included in the sum.
{? -
How to delete trailing zeros after the decimal point in the ALV sum
Hello Expert,
In my alv output, I need to sum up one column, but in the sum result, I don't want to display zeros after the decimal point.
for example,
If the sum is 134.00, I only want to display 134 on the alv.
Does any expert have idea about it?
Thanks in advance,
best regards, JohnnyHi ,
Use following
SHIFT variable RIGHT/LEFT DELETING TRAILING '0'.
For more variations ,
just write SHIFT and press f4 , it will show you the information you need.
Hope this is helpful,
Regards,
Uma Dave
Maybe you are looking for
-
Large number of problems. HELP!!!!!!
my computer got a virus a few days ago so i got a new hard drive for it but i didnt back up my itunes library before installing the new hard drive. when i try transfer purchases from my ipod to itunes, nothing happens! i also bought another song afte
-
Im going to kill my self. (The signature was invalid)
"The binary you uploaded was invalid. The signature was invalid, or it was not signed with an Apple submission certificate." It´s like a week im trynig diffrent tutorial, forums. NOTHING. The only option I have now is ScreenSharing via iChat. Please
-
here's one for all you java gurus: //import java.util.*; public class RowsofTen //static Scanner console = new Scanner(System.in); public static void main (String[] args) int i, j; for ( i = 11; i <= 40; i++) for (j = i; j <=
-
Xml and hebrew, any ideas
Hi all I am a prityy much "novice" in xml / xsl but I did some simple stuff. when I add a small hebrew word to my xml I got an exception " javax.xml.transform.TransformerException: An invalid XML character (Unicode: 0xf8) was found in the element con
-
How you can change region color like in GB
In GB you can change the region color from orange to purple, by doing control/option/G/click. Orange tracks will not respond to tempo or pitch changes, until they are changed to purple. Is there a way to do the same in Logic? turn the blue regions in