‎2009 Jul 23 1:36 PM
HI ALL
settting the attribute do_sum = 'X' how can i use in alv .
and please tell me place of 'X' what can i write "field number" or "field name " or any thing else please tell me.
in my alv i can write ls_fieldcat-do-sum = &3, how it will work .
thanks
‎2009 Jul 23 1:54 PM
Use as below in fieldcatalog. This will sum the column DMBTR(Amount).
WA_FIELDCAT-COL_POS = 1.
WA_FIELDCAT-FIELDNAME = 'DMBTR'.
WA_FIELDCAT-TABNAME = 'GT_FINAL'.
WA_FIELDCAT-SELTEXT_M = 'Amount'.
WA_FIELDCAT-DO_SUM = 'X'.
APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.
‎2009 Jul 23 1:44 PM
‎2009 Jul 23 1:48 PM
Hi ,
Please check the below one.
REPORT zalv_grid1.
REPORT z_alv_demo_total_text.
TYPES: BEGIN OF ty_mara,
srno TYPE char40, " Storing the total text
matnr TYPE matnr, " Material
ersda TYPE ersda, " Creation date
ernam TYPE ernam, " Created by
laeda TYPE laeda, " Last change date
aenam TYPE aenam, " Last change by
vpsta TYPE vpsta, " Maintenance status
brgew TYPE brgew, " Gross weight
ntgew TYPE ntgew, " Net weight
gewei TYPE gewei, " Weight Unit
END OF ty_mara.
type declaration for table storing temp. DATA
types: BEGIN OF ty_mara_tmp,
matnr TYPE matnr, " Material
ersda TYPE ersda, " Creation date
ernam TYPE ernam, " Created by
laeda TYPE laeda, " Last change date
aenam TYPE aenam, " Last change by
vpsta TYPE vpsta, " Maintenance status
brgew TYPE brgew, " Gross weight
ntgew TYPE ntgew, " Net weight
gewei TYPE gewei, " Weight Unit
END OF ty_mara_tmp.
internal table for storing final data
data: i_mara type standard table of ty_mara initial size 0.
work area for final table
data: w_mara type ty_mara.
Internal table for storing temp. data
DATA: i_mara_tmp TYPE STANDARD TABLE OF ty_mara_tmp INITIAL SIZE 0.
DATA: w_mara_tmp TYPE ty_mara_tmp.
object variable for alv grid
data: oref1 type ref to cl_gui_alv_grid.
field catalog table for alv grid
data: fieldcat type lvc_t_fcat.
workarea for field catalog table
data: w_field type lvc_s_fcat.
internal table for storing info.
for alv grid
data: i_sort2 type standard table of lvc_s_sort initial size 0.
workarea for sort table
data: wa_sort2 type lvc_s_sort.
workarea for alv layout
data: wa_layout type lvc_s_layo.
START-OF-SELECTION.
fetch data
select matnr " Material
ersda " Creation date
ernam " Created by
laeda " Last change date
aenam " Last change by
vpsta " Maintenance status
brgew " Gross weight
ntgew " Net weight
gewei " Weight Unit
from mara
into table i_mara_tmp
up to 100 rows.
CHECK sy-subrc = 0.* populate final table
loop at i_mara_tmp into w_mara_tmp.
storing the total text need to be displayed in
ALV
w_mara-srno = 'Total weight (Gross & Net)'.
w_mara-matnr = w_mara_tmp-matnr.
w_mara-ersda = w_mara_tmp-ersda.
w_mara-ernam = w_mara_tmp-ernam .
w_mara-laeda = w_mara_tmp-laeda.
w_mara-aenam = w_mara_tmp-aenam.
w_mara-vpsta = w_mara_tmp-vpsta.
w_mara-brgew = w_mara_tmp-brgew.
w_mara-ntgew = w_mara_tmp-ntgew.
w_mara-gewei = w_mara_tmp-gewei.
APPEND w_mara TO i_mara.
ENDLOOP.
Calling the screen to display ALV
CALL SCREEN 100.
&----
*& Module STATUS_0100 OUTPUT
&----
Display ALV report
----
MODULE status_0100 OUTPUT.
IF oref1 IS INITIAL.
create alv grid object
In this case we have not created any custom container in the screen,
Instead of that dummy container name is passed
ADVANTAGE: we can run this report in background without any problem
create object oref1
exporting
i_parent = cl_gui_custom_container=>screen0
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.
CHECK sy-subrc = 0.* preparing the field catalog
ZDEMO: Defined in DDIC, it's structure is same as TYPE ty_mara
defined in the program
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZDEMO'
changing
ct_fieldcat = fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
IF sy-subrc = 0.
LOOP AT fieldcat INTO w_field.
IF w_field-fieldname = 'BRGEW' OR
w_field-fieldname = 'NTGEW'.
Summation for Gross & Net weight
w_field-do_sum = 'X'.
MODIFY fieldcat FROM w_field TRANSPORTING do_sum.
ENDIF.
IF w_field-fieldname = 'SRNO'.
Hide this field so that it can display it's content i.e.
Total text in Subtotal level
w_field-tech = 'X'.
w_field-no_out = 'X'.
MODIFY fieldcat FROM w_field TRANSPORTING tech no_out.
ENDIF.
CLEAR w_field.
ENDLOOP.
ENDIF.
populate sort table with srno field so that we can display the total
text in it's subtotal level
wa_sort2-spos = 1.
wa_sort2-fieldname = 'SRNO'.
wa_sort2-up = 'X'.
wa_sort2-subtot = 'X'.
APPEND wa_sort2 TO i_sort2.* hide the total line
wa_layout-no_totline = 'X'.
display the alv grid
call method oref1->set_table_for_first_display
exporting
is_layout = wa_layout
changing
it_outtab = i_mara[]
it_fieldcatalog = fieldcat
it_sort = i_sort2
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
IF sy-subrc <> 0. ENDIF.
set the focus on the grid
call method cl_gui_alv_grid=>set_focus
exporting
control = oref1
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3.
IF sy-subrc <> 0.
ENDIF.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
Edited by: Pradeep Kumar Reddy on Jul 23, 2009 2:50 PM
‎2009 Jul 23 1:51 PM
in my alv i can write ls_fieldcat-do-sum = &3, how it will work
hi &3 is a parameter reference in Macro definition.
search in SCN before posting these type of questions.
Read the rules of engagement also !!!
‎2009 Jul 23 1:54 PM
Use as below in fieldcatalog. This will sum the column DMBTR(Amount).
WA_FIELDCAT-COL_POS = 1.
WA_FIELDCAT-FIELDNAME = 'DMBTR'.
WA_FIELDCAT-TABNAME = 'GT_FINAL'.
WA_FIELDCAT-SELTEXT_M = 'Amount'.
WA_FIELDCAT-DO_SUM = 'X'.
APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.