This website is not affiliated with, sponsored by, or approved by SAP AG.

SUbTotal in ALV GRID

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

SUbTotal in ALV GRID

Postby saabnawab » Tue Dec 30, 2003 4:02 am

Hi abapers,

In ALV Grid we can calculate the Grand total for any column from the Tool bar Option . But if we want to sub total for any particular column to display .
Like i want subtotal of Employee SALRAY with respect to each Department . it shows the subtotal of salray for each department .

Please help , if code is available better for me .

Thanks in Advance .
Nawab Ahmed siddiqui
Sun Certified Java Programer.
saabnawab
 
Posts: 20
Joined: Mon Mar 10, 2003 3:03 pm

Postby nonik » Tue Dec 30, 2003 4:13 am

try :

LS_FIELDCAT-DO_SUM = 'X'.

best regards,
nonik
nonik
 
Posts: 46
Joined: Tue Jul 08, 2003 9:12 pm

Not Resolved

Postby saabnawab » Wed Dec 31, 2003 4:41 am

Hi

nonik,
problem is not resolved as i donot understand .
please u elobrate it with a code exapmle .

i call the cl_gui_alv_grid class function,

<refrence of cl_gui_alv_grid class> -> SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING
<> = MY Own Structre from DDIC
Changing

<> = Internal table name for out put .

Now how can i get sub total of my desired field . As i want sub total of salray of Employees per department (each Department ) in ALV GRID.

please reply intime , Kindly Elobrate it with code is better for me .

Thanks in Advance
Nawab Ahmed siddiqui
Sun Certified Java Programer.
saabnawab
 
Posts: 20
Joined: Mon Mar 10, 2003 3:03 pm

solution with code

Postby deepakb » Fri Jan 02, 2004 6:30 am

i think i have got the solution for ur prob.

the code below produces alv display with 2 columns: field1 & field2.

field1 is character based & the int. table passed to the alv is sorted on this field.

field2 is numeric, whose subtotals are desired.

so while populating the gt_sort table the option gs_sort-subtot is set for field1 bcoz the subtotals are to be based on the groups existing in this column.whereas the same option is NOT set for field2, even though the subtotal appears in that column.i have marked these 2 statements in the code for your convenience.

execute the code below & you will surely understand what i said above.

bye!!


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.
deepakb
 
Posts: 3
Joined: Mon Nov 17, 2003 3:18 am
Location: Mumbai

Thanks deepakb

Postby saabnawab » Mon Jan 05, 2004 6:15 am

Thanks for the reply ,

My problem is Resolved . as u reply in detail with a example .


Thanks deepakb once again.
Nawab Ahmed siddiqui
Sun Certified Java Programer.
saabnawab
 
Posts: 20
Joined: Mon Mar 10, 2003 3:03 pm

Re: SUbTotal in ALV GRID

Postby joyiemaceda » Thu Apr 10, 2008 1:10 am

Hi deepakb/guys,

I'd like to know, if you print this alv report out, will the whole report be printed? will it include the drill down details?
Can you please give me details on how you can just print the main report (without the drilldown details)?

Thanks :D
joyiemaceda
 
Posts: 1
Joined: Thu Apr 10, 2008 1:02 am

Re: SUbTotal in ALV GRID

Postby abap_doctor » Thu Apr 10, 2008 2:42 am

They may have lost interest in the last four years... :shock:

If you have a specific problem, please start a new thread...

Topic locked.
The Doc
Tuly Idiot Magna Grand Docot Image
abap_doctor
 
Posts: 6955
Joined: Thu Mar 25, 2004 11:29 am
Location: Airstrip One


Return to ABAP

Who is online

Users browsing this forum: No registered users and 6 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.