ALV grid sub-totals
Hi All,
I have written a code to show sub totals in ALV.
But, is there any way by which I can show *Only the sub total
lines* and not the individual line items that form the sub total ?
e.g.:-
KeyField1 KeyField2 Field1 Field2
A 1 10 12
A 1 15 8
SUBTOTAL 25 20
B 2 15 12
SUBTOTAL 15 12
C 1 10 8
C 2 8 12
C 3 7 2
SUBTOTAL 25 22
Now I want only the SUBTOTAL rows to be visible in ALV not the individual rows as follows :-
KeyField1 KeyField2 Field1 Field2
SUBTOTAL 25 20
SUBTOTAL 15 12
SUBTOTAL 25 22
Regards,
Ashish
hi check this..in this only subtotals are shown if u click on the subtotal it will show the detailed list for that subtotal..
*& Report ZVG_ALV_SLIST2 *
report zvg_alv_slist2 .
ALV
type-pools: slis.
G L O B A L I N T E R N A L T A B L E S
data: gt_fieldcat type slis_t_fieldcat_alv,
gs_layout type slis_layout_alv,
gt_events type slis_t_event.
data: it_sort type slis_t_sortinfo_alv ,
wa_sort type slis_sortinfo_alv .
data: gs_print type slis_print_alv.
data: begin of it_sflight occurs 0,
carrid like sflight-carrid,
connid like sflight-connid,
fldate like sflight-fldate,
price like sflight-price,
planetype like sflight-planetype,
seatsmax like sflight-seatsmax,
seatsocc like sflight-seatsocc,
paymentsum like sflight-paymentsum,
end of it_sflight.
*DATA: GI_SFLIGHT LIKE STANDARD TABLE OF ST_SFLIGHT.
data: g_repid like sy-repid.
data: gt_list_top_of_page type slis_t_listheader.
data: v_total(5).
start-of-selection.
g_repid = sy-repid.
perform init_fieldcat using gt_fieldcat[].
perform build_eventtab using gt_events[].
perform build_comment using gt_list_top_of_page[].
perform get_data.
perform set_layout using gs_layout.
SORTING
clear wa_sort.
wa_sort-fieldname = 'CARRID'.
wa_sort-up = 'X'.
wa_sort-group = '*'.
wa_sort-subtot = 'X'.
append wa_sort to it_sort.
clear wa_sort.
wa_sort-fieldname = 'CONNID'.
wa_sort-up = 'X'.
wa_sort-group = 'UL'.
wa_sort-subtot = 'X'.
append wa_sort to it_sort.
DISPLAY LIST
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_interface_check = ' '
i_callback_program = g_repid
i_callback_user_command = 'USER_COMMAND'
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
it_sort = it_sort[]
it_events = gt_events
is_print = gs_print
tables
t_outtab = it_sflight
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.
*& Form INIT_FIELDCAT
form init_fieldcat using p_gt_fieldcat type slis_t_fieldcat_alv.
data: ls_fieldcat type slis_fieldcat_alv,
l_index type sy-tabix.
data :rep like sy-repid.
rep = sy-repid.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = rep
i_internal_tabname = 'IT_SFLIGHT'
i_inclname = rep
changing
ct_fieldcat = gt_fieldcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-subrc.
endif.
sort gt_fieldcat by col_pos.
loop at gt_fieldcat into ls_fieldcat.
l_index = sy-tabix.
if ls_fieldcat-fieldname = 'PRICE'.
ls_fieldcat-do_sum = 'X'.
ls_fieldcat-sp_group = 'X'.
modify gt_fieldcat from ls_fieldcat index l_index .
endif.
endloop.
endform. " INIT_FIELDCAT
*& Form BUILD_EVENTTAB
form build_eventtab using p_gt_events type slis_t_event.
data: ls_event type slis_alv_event.
clear ls_event.
ls_event-name = slis_ev_top_of_page.
ls_event-form = 'XTOP_OF_PAGE'.
append ls_event to p_gt_events.
clear ls_event.
ls_event-name = slis_ev_top_of_list.
ls_event-form = 'XTOP_OF_LIST'.
append ls_event to p_gt_events.
clear ls_event.
clear ls_event.
ls_event-name = slis_ev_end_of_page.
ls_event-form = 'XEND_OF_PAGE'.
append ls_event to p_gt_events.
ls_event-name = slis_ev_end_of_list.
ls_event-form = 'XEND_OF_LIST'.
append ls_event to p_gt_events.
clear ls_event.
endform. " BUILD_EVENTTAB
*& Form BUILD_COMMENT
form build_comment using p_gt_list_top_of_page type slis_t_listheader.
data: ls_line type slis_listheader.
ls_line-typ = 'H'." = Header, S = Selection, A = Action
ls_line-key = 'KEY'.
ls_line-info = 'INFO'.
append ls_line to p_gt_list_top_of_page.
endform. " BUILD_COMMENT
*& Form SELECTION
form get_data..
data: l_rows type i value 3.
Read data from table SFLIGHT
select carrid
connid
fldate
price
planetype
seatsmax
seatsocc
paymentsum
from sflight
into table it_sflight.
up to l_rows rows.
sort it_sflight.
endform. " SELECTION
*& Form SET_LAYOUT
form set_layout using p_gs_layout type slis_layout_alv.
* P_GS_LAYOUT-F2CODE = P_F2CODE.
p_gs_layout-zebra = 'X'.
p_gs_layout-colwidth_optimize = 'X'.
p_gs_layout-no_input = 'X'.
p_gs_layout-no_colhead = space.
p_gs_layout-totals_text = 'Total Price'.
p_gs_layout-subtotals_text = 'Sub Total'.
p_gs_layout-totals_only = 'X'.
p_gs_layout-key_hotspot = 'X'.
p_gs_layout-detail_popup = 'X'.
p_gs_layout-no_subtotals = space.
p_gs_layout-expand_all = 'X'.
p_gs_layout-group_buttons = 'X'."space.
endform. " SET_LAYOUT
FORM XTOP_OF_PAGE *
form xtop_of_page.
data : lv_page(5),
lv_text(20).
MOVE SY-PAGNO TO LV_PAGE.
write:/ 'X_TOP_OF_PAGE'.
endform. "xtop_of_page
FORM XTOP_OF_LIST *
form xtop_of_list.
write:/ 'X_TOP_OF_LIST'.
endform. "xtop_of_list
FORM XEND_OF_PAGE *
form xend_of_page.
write:/ 'X_END_OF_PAGE'.
endform. "xend_of_page
FORM XEND_OF_LIST *
form xend_of_list.
write:/ 'X_END_OF_LIST'.
data : lv_page(5),
lv_text(20).
data : l_lines type i,
l_line type i.
clear v_total.
write sy-pagno to v_total left-justified.
export v_total to memory id 'V_TOTAL'.
do sy-pagno times.
lv_page = sy-index.
concatenate 'Page' lv_page 'of' v_total
into lv_text separated by space.
if sy-index = 1.
read line 2 of page sy-index.
else.
read line 1 of page sy-index.
endif.
sy-lisel+60(20) = lv_text.
modify current line .
enddo.
endform. "xend_of_list
USER_COMMAND *
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when 'EXIT'.
leave to screen 0.
when '&IC1'.
data: text(256),text1(6),text2(5).
move rs_selfield-tabindex to text1.
move rs_selfield-sumindex to text2.
concatenate 'Double clicked on (field:'
rs_selfield-fieldname
'Value:'
rs_selfield-value
text1
text2
into text
separated by space.
call function 'POPUP_TO_DISPLAY_TEXT'
exporting
textline1 = text.
endcase.
endform. "user_command
regards,
venkat.
Similar Messages
-
Hi SAP Experts,
Currently I have ALV Grid table as below as example :
FIELD1
FIELD2
Account
Amount
1. Rev
1.Rev
Acct1
100.00
1. Rev
1.Rev
Acct2
50.00
Subtotal FIELD2 (1.Rev)
150.00
Subtotal FIELD1 (1.Rev)
150.00
2. Cost
2.1 Cost1
Acct3
100.00
2. Cost
2.1 Cost1
Acct4
75.00
Subtotal FIELD2 (2.1 Cost1)
175.00
2. Cost
2.2 Cost2
Acct5
25.00
Subtotal FIELD2 (2.2 Cost 2)
25.00
| Subtotal FIELD1 (2.Cost) | 200.00 |
I have 2 questions.
First, as you can see, I have 2 subtotal for 1.Rev eventhough 1.Rev actually only need one subtotal because there is no subgroup for 1.Rev. Is it possible to have only one subtotal for this 1.Rev but I still maintained 2 subtotal for 2.Cost because 2.Cost has subgroup?
My 2nd issue is I need to insert another row exactly below Subtotal FIELD1 (2.Cost) row like this:
Gross Margin
(Some formula)
This row does not come from any sub total. The problem is I can not just insert this column and put Gross Margin description in FIELD1 because I will have 3 row like below :
Gross Margin
(Formula)
Subtotal FIELD2 (blank)
(Formula) sub total
Subtotal FIELD1 (Gross Margin)
(Formula) sub total
Is there any way I can insert Gross Margin Row without creating new subtotal for it so it will only have one line in the ALV Grid table? Please help. Thank you.
Regards,
AbrahamHi Vijay.
I'm not posting this before I search everywhere and this is not the first time I post in this forum so I know what I should do before posting. If I miss something, maybe you can give me at least a hint whether it can be done or not.
This report that I am using is ALV Grid using REUSE_ALV_GRID_DISPLAY function module and not OOP using dialog module. I never said I need sample code because I only want to know is there a way to do that using ALV Grid which until now I will say that SAP ALV grid has this limitation where you can not insert row without including it in the subtotal.
So, I would be very thankful if someone can give me some clarity on this thing and Vijay, if you really don't know what is the answer, I really appreciate if you can hold your self from making that kind of reply. It does not need experienced ABAP Consultant to write such remarks. Thanks.
Regards,
Abraham -
Hi All
I am have done an object in alv grid where it is working fine but what i want i am giving a sample please do let tell me how to do
OUTPUT
DATE TIME-ENTRY ACM-NO CHARG SHIFT MACHINE-SPEED STANDARD-D ACTUALL-DIPS DOWNTIME-MINS DOWN-TIME-IN%
2009/08/23 00:45:41 ACMA01 910808 B 27.090 2,167 2,120 10 2.08
2009/08/23 08:38:45 ACMA01 910808 C 27.090 2,167 1,459 157 32.71
910808 4,334 3,579 167
2009/08/23 08:51:59 ACMA01 910809 C 27.090 2,167 141 449 93.54
2009/08/23 17:24:39 ACMA01 910809 A 27.090 2,167 2,113 12 2.50
910809 4,334 2,254 461
2009/08/23 00:48:56 ACMA02 920810 B 25.700 2,056 2,015 10 2.08
2009/08/23 09:07:02 ACMA02 920810 C 25.700 2,056 2,043 3 0.63
2009/08/23 17:27:04 ACMA02 920810 A 25.700 2,056 421 382 79.58
2009/08/23 17:27:12 ACMA02 920810 A 25.700 2,056 421 382 79.58
920810 8,224 4,900 777
2009/08/23 17:30:12 ACMA02 920811 A 25.700 2,056 1,335 168 35.00
920811 2,056 1,335 168
In Down time in % i want to do a bit of calculation
X = 3579(ACCTUALL DIPS)/4334(STANDARD DIPS)
X = .0852 * 100 = 82.5 - 100
X = -17.4%( This should display in DOWN-TIME-IN%)
This will be Similar Calculation only number of lines will reduce to make it clear i gave in this way
Waiting for Reply
Thank's In Advance
Sravya
Edited by: Sravya Ch on Aug 24, 2009 7:41 AMHi Rajihta
I think you did not under stand what I want clearly
DATE TIME-ENTRY ACM-NO CHARG SHIFT MACHINE-SPEED STANDARD-D ACTUALL-DIPS DOWNTIME-MINS DOWN-TIME-IN
2009/08/23 00:45:41 ACMA01 910808 B 27.090 2,167 2,120 10 2.08
2009/08/23 08:38:45 ACMA01 910808 C 27.090 2,167 1,459 157 32.71
* 910808 4,334 3,579 167 *17%*
So how to do for that 17% .i have just eneterd it now(every thing is from SAP other than that 17%) -
Web Dynpro ALV grid sub totals
Hi,
I have managed to get totals working with web dynpro ALV using code like this :
DATA: lr_field TYPE REF TO cl_salv_wd_field.
For total calculations...
lo_value->if_salv_wd_std_functions~set_aggregation_allowed( abap_true ).
lr_field = lo_value->if_salv_wd_field_settings~get_field( 'N_OF_DLRS' ).
lr_field->if_salv_wd_aggr~create_aggr_rule( aggregation_type = if_salv_wd_c_aggregation=>aggrtype_total ).
Please can someone advise how i can do subtotals also. Thanks
Edited by: Samir Vora on Jul 15, 2009 12:40 PMHi,
For creating subtotals, you can have a look at following article:
[Tutorial for Creation Subtotals using ALV|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/user-interface-technology/wd%20abap/tutorial%20for%20creating%20totals%20and%20subtotals%20using%20alv.pdf].
Hope this helps.
Regards
Manas Dua -
ALV GRID: Sub Total of a field
Hi All,
Currently I am getting O/P in the following format:
CURRENCY QUANTITY VALUE
GBP 1 10
GBP 2 15
INR 1 12
I want the output to be:
CURRENCY QUANTITY VALUE
GBP 1 10
GBP 2 15
GBP 25
INR 1 12
INR 12
I have already tried with:
wa_fieldcatalog-fieldname = 'VALUE'.
wa_fieldcatalog-do_sum = 'X'.
and,
clear wa_sort.
wa_sort-spos = 1.
wa_sort-fieldname = 'VALUE'.
wa_sort-expa = 'X'.
wa_sort-subtot = 'X'.
wa_sort-up = 'X'.
append wa_sort to t_sort
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = t_layout
it_fieldcat = wa_fieldcatalog[]
it_sort = t_sort[]
i_save = 'A'
it_events = t_events[]
TABLES
t_outtab = ts_final_output[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
It's still not working. Request u all to plz help
Edited by: Ajoy Chakraborty on Jan 23, 2009 11:43 AMHello Ajoy,
You can do like this..
wa_field-fieldname = 'MENGE'.
wa_field-tabname = 'IT_TAB'.
wa_field-outputlen = 20.
wa_field-seltext_l ='Quantity'.
wa_field-input = ' '.
wa_field-edit = ' '.
wa_field-col_pos = '4'.
wa_field-hotspot = 'X'.
wa_field-do_sum = 'X'. " In the field catalog suppose you want the subtotal of this field
APPEND wa_field TO it_field.
CLEAR wa_field.
wa_field-fieldname = 'WERKS'.
wa_field-tabname = 'IT_TAB'.
wa_field-outputlen = 20.
wa_field-col_pos = '5'.
wa_field-seltext_l ='Plant'.
wa_field-input = 'X'.
wa_field-edit = 'X'.
APPEND wa_field TO it_field.
CLEAR wa_field.
*Manintainig internal table for sorting
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELP'.
wa_sort-tabname = 'IT_tab'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'. " this works like an T New for this field that is on every new value of this field , Subtotal will get calculated through above field catalog.
APPEND wa_sort TO itab_sort.
CLEAR wa_sort.
Hope it helps you
Regards
Mansi -
hi gurus,
In my report program i have a monthly report displaying the data for that month.
1. Now in my ALV grid i want The SUB-TOTALS for the work center wise data for a field of the alv. there are many workcenters data in my report. So after the end of each work center , i want the subtotal of a calculated TAT field.
2. At the end of the report, I want the average TAT(field calculated by my report program) for that month.
So how can i make the coding for the above.
Iam a fresher to this field, so give me in detail.
regards,
chaitanyaHi
i am giving a sample example for subtotals of alv.
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' 'X' ' ' ' ',
'01' '03' 'MATNR1' 'I_EKPO' 'L' 'Material No'(005) ' ' ' ' ' ' ' ',
'01' '04' 'WERKS' 'I_EKPO' 'L' 'Plant'(006) 'X' '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
*& 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
*& 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
= 'Material level total'(009).
ENDIF.
Plant level sub total
IF P_SUBTOT_TEXT-CRITERIA = 'WERKS'.
P_SUBTOT_TEXT-DISPLAY_TEXT_FOR_SUBTOTAL = 'Plant level total'(010).
ENDIF. -
Issue in ALV Grid Grand Totals
Hi Friends,
Hwo can i display grand total text in ALV Grid? Eventhough i am using Totals_text parameter in layout i am unable to display. any one vcan help me out in this refgard.
if pos send the code
Regards,
Vijay<REMOVED BY MODERATOR>
SAMPLE PROGRAM:
REPORT ysalesorder_alv_subtotals.
* Type Pools
TYPE-POOLS:slis.
* Tables
TABLES: vbak, "Sales Document: Header Data
vbap. "Sales Document: Item Data
* Global Structures
DATA:gt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
gt_sortcat TYPE slis_t_sortinfo_alv,
wa_sortcat LIKE LINE OF gt_sortcat.
* Internal Table
DATA: BEGIN OF gt_salesorder OCCURS 0,
vbeln LIKE vbak-vbeln, " Sales Document Number
posnr LIKE vbap-posnr, " Sales Doc Item
netwr LIKE vbap-netwr, " Net Value
END OF gt_salesorder.
* SELECT OPTIONS
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME
TITLE text-001.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. " Sales Document
Number.
SELECTION-SCREEN END OF BLOCK b1.
* Initialization
INITIALIZATION.
PERFORM initialization.
* Start Of Selection
START-OF-SELECTION.
PERFORM field_catalog. "For Structure Creation
PERFORM fetch_data. "Get the Data From DB Table
PERFORM sorting USING gt_sortcat.
* End Of Selection
END-OF-SELECTION.
PERFORM display_data.
*& Form initialization
* text
* --> p1 text
* <-- p2 text
FORM initialization .
s_vbeln-sign = 'I'.
s_vbeln-option = 'BT'.
s_vbeln-low = '4969'.
s_vbeln-high = '5000'.
APPEND s_vbeln.
ENDFORM. " initialization
*& Form field_catalog
* text
* --> p1 text
* <-- p2 text
FORM field_catalog .
REFRESH : gt_fieldcat.
CLEAR : wa_fieldcat.
wa_fieldcat-col_pos = '1'. "Column Position
wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table
wa_fieldcat-fieldname = 'VBELN'. "Field Name
wa_fieldcat-key = 'X'. "Blue Color
wa_fieldcat-seltext_m = 'Sales Doc No'. "Display Text In Screen
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = '2'. "Column Position
wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table Name
wa_fieldcat-fieldname = 'POSNR'. "Field Name
wa_fieldcat-seltext_m = 'Sales Doc Item'."Display Text In Screen
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
*SubTotal on the Field NETWR
wa_fieldcat-col_pos = '3'. "Column Position
wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table
wa_fieldcat-fieldname = 'NETWR'. "Field Name
wa_fieldcat-do_sum = 'X'. "Sum
wa_fieldcat-seltext_m = 'Net Value'. "Display Text In Screen
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
ENDFORM. " field_catalog
*& Form sorting
* text
* -->P_IT_SORTCAT text
FORM sorting USING p_it_sortcat TYPE slis_t_sortinfo_alv.
CLEAR wa_sortcat.
wa_sortcat-fieldname = 'VBELN'.
wa_sortcat-up ='X'.
wa_sortcat-subtot = 'X'.
APPEND wa_sortcat TO p_it_sortcat.
ENDFORM. " sorting
*& Form display_data
* text
* --> p1 text
* <-- p2 text
FORM display_data .
CALL FUNCTION 'REUSE_ALV_GRID_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_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = gt_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
it_sort = gt_sortcat
* 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
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_salesorder
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_data
*& Form fetch_data
* text
* --> p1 text
* <-- p2 text
FORM fetch_data .
REFRESH : gt_salesorder.
CLEAR : gt_salesorder.
SELECT a~vbeln
posnr
b~netwr
FROM vbak AS a
INNER JOIN vbap AS b ON a~vbeln = b~vbeln
INTO TABLE gt_salesorder
WHERE a~vbeln IN s_vbeln.
ENDFORM. " fetch_data
Edited by: Alvaro Tejada Galindo on Apr 11, 2008 12:24 PM -
In ALV grid report, totals of columns display at end of report
Hi.....!
In ALV report i want to display grand totals in end of list and also i want to output display ALV report in page by pageHi,
this the code i am sending it may help you.
DATA : wa_sort TYPE slis_sortinfo_alv.
DATA : it_sort TYPE slis_t_sortinfo_alv. " for sorting
PERFORM sub_total USING '<field based on wich you want sort(say key field>>'.
FORM sub_total USING value(p_sortfld) .
wa_sort-fieldname = p_sortfld.
wa_sort-subtot = 'X'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort
and then is main function module for display grid or list.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = wa_pgm
i_callback_top_of_page
='TOP_OF_PAGE'
i_grid_title = text-016
it_fieldcat = it_fieldcat
<b> it_sort = it_sort</b>
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = it_final. -
ALV Grid - Subtotal & total to be shown at the top of the table
Hi,
I am using function module 'REUSE_ALV_GRID_DISPLAY' to display a table, and I count subtotals and total for some fields. The total is always shown at the bottom of the table, and subtotals are always shown after the rows that subtotals are calculated for. Is there a way to make it so that the total is always shown at the top of the table, and subtotals are shown before the rows that subtotals are calculated for?
Thank you,
Jake AlexanderGW_LAYOUT-TOTALS_BEFORE_ITEMS = 'X'.
Regards
Sreekanth -
ALV Sub total texts. displayed in list not in grid.
Hi,
I am displaying data using alv and sub-totals on a particular column.
i am getting the sub-totals but i am not getting the sub-total texts when i am displaying data in a grid.
'REUSE_ALV_GRID_DISPLAY'.
i am getting subtotals and subtotal texts when i am diSplAying in list.
'REUSE_ALV_LIST_DISPLAY'.
but i want to get subtotal texts using alv grid, is it possible, if so please send me the code.
Any help in this regard is highly appreciated.
Thanks in advance for your help.Hi,
Actually i have wriitten the same code, in the alv. I am using Function modules. for the same code the sub-total and total text is appearing in the list output. but not in the grid output.
code.
wa_layout-zebra = 'X'.
wa_layout-subtotals_text = 'Total'.
wa_layout-totals_text = 'Sum of Marks'.
alv statement.
is_layout = wa_layout
Declaration.
DATA : wa_layout type slis_layout_alv.
for the same declarations (Above) list is showing the texts but not the grid.
Any help in this regard is highly appreciated. -
Mix AVG and Total for the same column in ALV grid
Hi,
We are using CL_GUI_ALV_GRID=>SET_TABLE_FOR_FIRST_DISPLAY, and I'd like to know if the following situation is possible.
Let's say we have a column which contains a number of hours, and we set it up to subtotal by period, but as an average rather than a total (DO_SUM = "C"). This is not a problem so far.
The problem is that we'd like for the "Grand Total" at the bottom of the ALV grid to total all of the subtotal averages, instead of calculating an average.
Ex:
Period Hours
2010/01 6.0
2010/02 7.0
2010/03 2.0
5.0 (This is an average... 6.0 + 7.0 + 2.0 / 3)
2011/01 12.0
2011/02 5.0
2011/03 4.0
7.0 (This is an average... 12.0 + 5.0 + 4.0 / 3)
12.0 (We want this to be a total of 5.0 + 7.0)
So we want the "grand total" line to be 12.0 which is the sum, but it currently comes out as an average.
Therefore we're looking to average at the sub total level, but we want a total of the subtotal levels at the grand total level for the same column.
Thanks,
DenisRefer to the suggestion given by Naimesh here Can we modify a sub-total in ALV making use of function GET_GLOBALS_FROM_SLVC_FULLSCR and the method GET_SUBTOTALS. You can see the parameter ep_collect01 refered in case of subtotals. Can you please check ep_collect00 for grand total in your case.
As said about EP_COLLECT00,here goes a classic example Modify grand total in ALV GRID
BR
Keshav
Edited by: Keshav.T on Sep 21, 2011 9:39 AM -
hi,
I have a report on ALV with sub totals for some fields, it is working fine but my requirement is whether i can get only the sub totals of that report.
regards,
PrabhuHI
refer this code.
REPORT ZALV.
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'.
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'.
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.
*END OF ZALV PROGRAM
Reward all helpfull answers.
Regards.
Jay -
Manipulate Layout on ALV Grid with dynamic table
Dear all
i'm generating a dynamic table depending of a date selection. That means that I show columns for weeks and the quantity of weeky migh change.
Now the users wants to have a specific layout of the ALV grid with totals. When he saves the layout, only the weeks at this selection will show the next time he runs the programm with a larger selection.
a) Is it possible to modify the layout during runtime by programming?
b) Do you have any other ideas how to solve this problem?
Thank youYou don't know the names of your columns? hmm you do, because before you created dynamic table you had to create field catalog, so the structure and column names of newly (dynamically) created table will be the same like defined in the field catalog.
The last loop also does not look good, in my opinion should be something like:
LOOP AT lt_datatable +(my first table)+ ASSIGNING <ls_data4>.
AT NEW pernr.
APPEND initial line to <fs_1> assigning <fs_2>.
<fs_2>-pernr = <ls_data4>-pernr.
ENDAT.
ASSIGN COMPONENT <ls_data4>-wage_type OF STRUCTURE <fs_2> TO <fs_5>.
<fs_5> = <ls_data4>-amount.
ENDLOOP.
also keep in mind that number of calls of method cl_alv_table_create=>create_dynamic_table is limited to 36 (?) calls within one program session because it uses dynamic subroutine pool behind so you will have short dump if you will execute that 37 times. -
hi ,
i have done a report and the user wants to see only the subtotls calculted on a paticular filed
eg : in grid sub totals are calculated based on the month
now he matnr wants to see only sub totals on the for the materialsin the output grid.
can any help me out .Hi,
you can write logic like below.
1. Assume your internal table is like follows
DATA: BEGIN OF ITAB OCCURS 0
MATNR TYPE MATNR,
FIELD1 TYPE FIELD1,
QTY TYPE FIELD2,
END OF ITAB.
Field MATNR should be defined as a first field in the data definition.
2. Get the data from tables using SELECT statements
3. Print the subtotals only using the below logic.
LOOP AT ITAB.
AT END OF MATNR.
SUM.
WRITE:/ ITAB-MATNR, ITAB-QTY.
ENDAT.
ENDLOOP.
Thanks
Ramakrishna -
Totals and Sub-Totals in ALV GRID
Could anyone advice, how to display sub-totals and totals in ALV Grid(using FM).
Ex: value1 value2
100 50
200 50
subtotal 300 100
total 400
Thanks in advance...Refer below demo code and see perform Sort_list..
it wil serve ur purpose.
REPORT ZGILL_ALV message-id rp .
type-pools slis.
tables: zgill_main,zgill_details.
data z_fieldcat type slis_t_fieldcat_alv.
data begin of itab occurs 0.
DATA ICON TYPE ICON-ID.
include structure zgill_main.
data salary like zgill_details-salary.
data end of itab.
*data itab1 like table of itab with header line.
data : WA_SORT TYPE SLIS_SORTINFO_ALV,
IT_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_FIELDTAB TYPE SLIS_T_FIELDCAT_ALV,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
PARAMETERS: p_list radiobutton group A1,
P_GRID RADIOBUTTON GROUP A1.
SELECT-OPTIONS: S_PERNR FOR ZGILL_MAIN-PERNR.
start-of-selection.
perform fill_itab.
perform sort_list.
**************Start of scenario without container******************************************
*********Method 1***********
perform fill_fieldcat. " Manuallly Preparing Fiedl Catalog
*********Method 2***********
*perform fill_fieldcat1 changing z_fieldcat. "Preparing field catalog with merge function
perform display_alv.
*****************end of scenario without container*****************************************
*& Form fill_itab
text
--> p1 text
<-- p2 text
form fill_itab .
*select * from zgill_main up to 20 rows INTO CORRESPONDING FIELDS OF TABLE itab.
*ITAB1[] = ITAB[].
select apernr aname aorg adob b~salary INTO CORRESPONDING FIELDS OF TABLE itab
from zgill_main as a join zgill_details as b on apernr = bpernr
WHERE A~PERNR IN S_PERNR.
LOOP AT ITAB.
IF ITAB-PERNR < 1111.
ITAB-ICON = '@08@'.
ELSEIF ITAB-PERNR > 1111 AND ITAB-PERNR < 11111111.
ITAB-ICON = '@09@'.
ELSEIF ITAB-PERNR GE 11111111.
ITAB-ICON = '@0A@'.
ENDIF.
MODIFY ITAB INDEX SY-TABIX.
ENDLOOP.
endform. " fill_itab
*& Form display_alv
text
--> p1 text
<-- p2 text
form display_alv .
data repid like sy-repid.
REPID = SY-REPID.
WA_LAYOUT-ZEBRA = 'X'.
WA_LAYOUT-WINDOW_TITLEBAR = 'GRID DISPLAY'.
WA_LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL'.
WA_LAYOUT-TOTALS_TEXT = 'TOTAL'.
IF P_GRID = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = repid
IT_FIELDCAT = IT_FIELDTAB
IT_SORT = IT_SORT
IS_LAYOUT = WA_LAYOUT
TABLES
t_outtab = itab[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF sy-subrc <> 0.
message e016 with 'Error in Display'.
ENDIF.
ELSEIF P_LIST = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = repid
IT_FIELDCAT = IT_FIELDTAB
IT_SORT = IT_SORT
IS_LAYOUT = WA_LAYOUT
TABLES
t_outtab = itab[]
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF sy-subrc <> 0.
message e016 with 'Error in Display'.
ENDIF.
ENDIF.
endform. " display_alv
*& Form fill_fieldcat1
text
--> p1 text
<-- p2 text
form fill_fieldcat1 changing d_fcat type slis_t_fieldcat_alv.
data repid like sy-repid.
data d_fcat1 type slis_t_fieldcat_alv with header line.
REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = repid
I_INTERNAL_TABNAME = 'ITAB'
I_STRUCTURE_NAME = 'ZGILL_MAIN'
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME =
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = d_fcat[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF sy-subrc <> 0.
message e016 with 'Error in preparing fiedl catalog'.
ENDIF.
loop at d_fcat into d_fcat1.
case d_fcat1-fieldname.
when 'NAME'.
d_fcat1-reptext_ddic = 'Emp Name'.
MODIFY D_FCAT FROM D_FCAT1.
WHEN 'PERNR'.
d_fcat1-reptext_ddic = 'Emp Num'.
MODIFY D_FCAT FROM D_FCAT1.
WHEN 'ORG'.
d_fcat1-reptext_ddic = 'Org Unit'.
MODIFY D_FCAT FROM D_FCAT1.
endcase.
clear d_fcat1.
endloop.
endform. " fill_fieldcat1
*& Form sort_list
text
--> p1 text
<-- p2 text
form sort_list .
CLEAR WA_SORT.
WA_SORT-FIELDNAME = 'DOB'.
WA_SORT-SPOS = '1'.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
WA_SORT-FIELDNAME = 'NAME'.
WA_SORT-SPOS = '1'.
WA_SORT-UP = 'X'.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
endform. " sort_list
*& Form fill_fieldcat
text
--> p1 text
<-- p2 text
form fill_fieldcat .
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'ITAB'.
WA_FIELDCAT-FIELDNAME = 'ICON'.
WA_FIELDCAT-SELTEXT_L = 'TRAFFIC'.
WA_FIELDCAT-ICON = 'X'.
WA_FIELDCAT-ddictxt = 'l'.
WA_FIELDCAT-COL_POS = 1.
WA_FIELDCAT-OUTPUTLEN = 10.
APPEND WA_FIELDCAT TO IT_FIELDTAB.
CLEAR WA_FIELDCAT .
WA_FIELDCAT-TABNAME = 'ITAB'.
WA_FIELDCAT-FIELDNAME = 'PERNR'.
WA_FIELDCAT-SELTEXT_L = 'EMP NUMBER'.
WA_FIELDCAT-ddictxt = 'l'.
WA_FIELDCAT-COL_POS = 2.
WA_FIELDCAT-OUTPUTLEN = 10.
APPEND WA_FIELDCAT TO IT_FIELDTAB.
CLEAR WA_FIELDCAT .
when 'maktx'.
WA_FIELDCAT-TABNAME = 'ITAB'.
WA_FIELDCAT-FIELDNAME = 'NAME'.
WA_FIELDCAT-SELTEXT_L = 'EMP NAME'.
WA_FIELDCAT-ddictxt = 'l'.
WA_FIELDCAT-COL_POS = 3.
WA_FIELDCAT-OUTPUTLEN = 15.
APPEND WA_FIELDCAT TO IT_FIELDTAB.
CLEAR WA_FIELDCAT .
WA_FIELDCAT-TABNAME = 'ITAB'.
WA_FIELDCAT-FIELDNAME = 'ORG'.
WA_FIELDCAT-SELTEXT_L = 'ORG UNIT'.
WA_FIELDCAT-COL_POS = 4.
WA_FIELDCAT-OUTPUTLEN = 10.
APPEND WA_FIELDCAT TO IT_FIELDTAB.
CLEAR WA_FIELDCAT .
WA_FIELDCAT-TABNAME = 'ITAB'.
WA_FIELDCAT-FIELDNAME = 'DOB'.
WA_FIELDCAT-SELTEXT_L = 'BIRTH DATE'.
WA_FIELDCAT-COL_POS = 5.
WA_FIELDCAT-OUTPUTLEN = 12.
APPEND WA_FIELDCAT TO IT_FIELDTAB.
CLEAR WA_FIELDCAT .
WA_FIELDCAT-TABNAME = 'ITAB'.
WA_FIELDCAT-FIELDNAME = 'SALARY'.
WA_FIELDCAT-SELTEXT_L = 'SALARY'.
WA_FIELDCAT-COL_POS = 6.
WA_FIELDCAT-OUTPUTLEN = 25.
WA_FIELDCAT-do_sum = 'X'.
APPEND WA_FIELDCAT TO IT_FIELDTAB.
endform. " fill_fieldcat
Maybe you are looking for
-
Hi All i am trying to get a legitimate vendor Aging report from within SAP The 2 reports that I am currently looking at are: S_ALR_87012085 - Vendor Payment History with OI Sorted List S_ALR_87012084 - Open Items - Vendor Due Date Forecast But both t
-
Opening a video in Windows Media Player
How do you open a video in Windows Media Player? The video I'm trying to open in Windows Media Player is an avi file. I noticed that in the Authorware 7 book, it says to simply add a wmp after "avi". For ex: myvideo.avi.wmp It then says to place or i
-
How do I disable all HTML in incoming email messages?
I just switched from Thunderbird to Mail and discovered that I cannot disable HTML rendering in email. I don't want to turn off only images. I want all HTML commands to be ignored. Most HTML is an annoyance, esp. with all the bad web designers who pu
-
Macosx with a lot of disk activity
This is the console log which is full of entries. Is it normal? 3/20/13 12:28:28.457 PM Numbers[819] NameKeyHashSet and ObjectHashMap out of sync: object map entry for __NSDictionaryI 0x5659a70 references name "NSMutableDictionary-38" instead of "NSM
-
Edit in ... disabled?
I have tried today to edit an image but Photoshop, as well as other editor and all other choices, are greyed out in the Develop module under Photo. I've certainly often used this and don't know why it's not working today. I'm using 2.3 under Win XP P