08-04-2009 1:11 PM
HI All,
How to display subtotal text in ALV using OO ALV?
My output of ALV should be as follows
COL1 COL2 COL3
ABC 900 M1
PQR 100 M1
M1 Subtotal 1000
XYZ 2100 M2
M2 Subtotal 2100
I could put the subtotal, but couldnu2019t add subtotal text.
My code
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = g_alv
CHANGING
t_table = gt_report
.
CATCH cx_salv_msg .
ENDTRY.
u2026u2026
*Display the table.
g_alv->display( ).
08-04-2009 1:17 PM
WELCOME TO SDN.
Plz SEARCH in SCN before posting, you will get lot of information.
08-04-2009 1:18 PM
HI,
Only numeric values are added ..Non numeric values cannot be added.
Regards,
Nagaraj
08-04-2009 1:20 PM
fine. but how display subtotal text based in coloumn value ..e.g. M1 Subtotal < > .
08-04-2009 1:28 PM
Hi,
Please check the code to display subtotal text for normal ALV grid
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-no_out = 'X'.
fieldcatalog-tech = 'X'.----
>check whether this option is present in OO ALV
fieldcatalog-tabname = 'IT_OUTPUT'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
Thanks & Regards,
Sateesh.
08-04-2009 1:32 PM
Hii vimal,
jst have a look to the links.hope it will serve the purpose.
http://www.allinterview.com/showanswers/28893.html
http://www.allinterview.com/showanswers/28893.html
Regards,
Shweta
08-04-2009 1:35 PM
08-04-2009 1:45 PM
Hii viren,
You search on the google with key word display subtotal text in alv oops you will get links of sap technical that will surely serve your purpose i cant post the link here acc to sdn guidelines.
Regards,
Shweta
08-04-2009 1:57 PM
Hi
REPORT z_alv_demo_total_text.
Type declaration for final table to display the output
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.
Work area for temp. table
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
These will defintely help in u displaying subtotal text check it
thanks