2007 May 07 4:22 AM
i made a report printing output in ALV. i need to sum the amount field and display the total in the last row. i m able to do the sum but i want to write label
'Grand Total' before the total value. what shud i do to write a text for my grand total?
2007 May 07 4:55 AM
just check the data types of those two fields it can be sum or not you can do the sum for currency, qty or integer field..
regards
shiba dutta
i made a report printing output in ALV. i need to sum the amount field and display the total in the last row. i m able to do the sum but i want to write label
'Grand Total' before the total value. what shud i do to write a text for my grand total?
2007 May 07 4:39 AM
ilayout-totals_text = 'Grand total'. now pass this layout to fm reuse alv list display.
regards
shiba dutta
2007 May 07 4:51 AM
Thanks Shiba,
But i tried it, its nt working. actully i hav three colums say SNo, personnel No and amount. i did the total of amount. it prints the sum in the last row and in SNo, and personnel No. Columns it prints 0, 00000000 respectively, why is it so?
2007 May 07 4:40 AM
Hi Nidhi,
For that you will Create one Data Base Field like Grand Total. Then you have to pass the values into ALV Report through Internal Table.
Thanks.
2007 May 07 4:50 AM
Refer the following code:
<b>See the layout</b>
*&---------------------------------------------------------------------*
*& Report ZDEMO_ALVGRID *
*& *
*&---------------------------------------------------------------------*
*& *
*& Example of a simple ALV Grid Report *
*& ................................... *
*& *
*& The basic requirement for this demo is to display a number of *
*& fields from the EKKO table. *
*&---------------------------------------------------------------------*
REPORT zdemo_alvgrid .
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-do_sum = 'X' "Display column total
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
* gd_layout-totals_only = 'X'.
* gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
* gd_layout-zebra = 'X'.
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_ekko
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. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
endform. " DATA_RETRIEVAL
2007 May 07 4:55 AM
just check the data types of those two fields it can be sum or not you can do the sum for currency, qty or integer field..
regards
shiba dutta
2007 May 07 5:01 AM
i think u have set the do_sum parameters for all the fileds. Set the parameter do_sum for the fields to which u want to display totals.
set the gd_layout-total_text = 'Grand total'.
and pass it to reuse_alv_grid_display.
Regards,
Satish.
2007 May 07 5:12 AM
thank u 4 the reply,
bt i did the same thing, i set the layout n passed it to reuse fn. still its not displaying Grand Total.
2007 May 07 5:15 AM
sorry previously i dint mention one thing your grand total text will be displayed under the first column so your first column length should be enough to display the text . i.e. at least your first column in the alv should be 12 or greater than it.
try for the first column in fieldcat-outputlen = 12.
regards
shiba dutta
2007 May 07 5:49 AM
2007 May 07 6:07 AM
TRY IN LIST DISPLAY (REUSE_ALV_LIST_DISPLAY) AND PASS THE ILAYOUT TO THE PARAMETER IS_LAYOUT JUST DGO THROUGH THIS SAMPLE CODE.
type-pools : slis.
tables : ekpo.
data : itab like ekpo occurs 0 with header line.
data : wfieldcat type slis_fieldcat_alv,
ifieldcat type slis_T_fieldcat_alv,
ILAYOUT TYPE SLIS_LAYOUT_ALV.
select * from ekpo into table itab up to 10 rows.
WFIELDCAT-FIELDNAME = 'EBELN'.
WFIELDCAT-SELTEXT_L = 'PO No'.
WFIELDCAT-OUTPUTLEN = 12.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'MENGE'.
WFIELDCAT-SELTEXT_L = 'Qty'.
WFIELDCAT-OUTPUTLEN = 15.
WFIELDCAT-DO_SUM = 'X'.
APPEND WFIELDCAT TO IFIELDCAT.
CLEAR WFIELDCAT.
ILAYOUT-TOTALS_TEXT = 'Grand total'.
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 = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_STRUCTURE_NAME = 'EKPO'
IS_LAYOUT = ILAYOUT
IT_FIELDCAT = IFIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_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-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
REGARDS
SHIBA DUTTA
2007 May 07 1:38 PM
hi Shiba,
i tried it in LIST display. In that it is getting displayed. but in GRID it is not..
why it is so??
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |