2005 Apr 28 11:27 AM
Hi,
I need to know how to display subtotals in hieral ALV.
Suppose I have a Hierical report layout like this
Matnr Makt Plant(werks)
Unrestricted Qty(labst)
I need to calculate the subtotal for labst and display it.
tables used are MARA, MAKT, MARD
link MATNR.
My report oupt shld be like this
Matnr Makt Werks ( Header)
labst1 (Item)
labst2
labst3
subtotal -
Matnr Makt Werks
labst1
labst2
labst3
subtotal----
2005 Apr 28 2:25 PM
Hi Santosh,
I hope the following code will be useful for you. Its woriking fine for Simple ALV. You just try with your Hierarchical ALV.
Declare Sorting Internal Table with SLIS Type.
i_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
i_sort-tabname = 'DATATAB' " Internal Table Name
i_sort-fieldname = 'MATNR'. " Give Fieldname
i_sort-up = 'X'. " For Ascending Order
i_sort-subtot = 'X'. " This is for subtotal
APPEND i_sort.
CLEAR i_sort.
Before using this you must have give Total for any for * the column in ALV
While passing this I_SORT use [] bracket. Because I have declared i_sort with Header Line.
Ex:
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
. . . .
it_sort = i_sort[]
. . . .
I have given simple list ALV. Please try this for Hierarchy.
Regards,
Jeyakumar
2005 Apr 28 11:45 AM
Hi,
To do the subtotal, do sum at the end of each labst.
eg.
START OF SELECTION.
Then retrieve date and store it in outputtable.
SORT outputtable ASCENDING BY key fields.
LOOP AT outputtable.
AT END OF labst.
SUM.
APPEND outputtable TO outputtable_duplicate.
ENDAT.
ENDLOOP.
Then move outputtable_duplicate to outputtable for display.
Then CALL SCREEN.
END OF SELECTION.
Hope this helps.
Thanks & Regards,
Judith
2005 Apr 28 12:11 PM
hi,
Thank u for the help.But i shld be using hierarchical ALV for display. As I mentioned before.
I have 2 output tables IT_HEADER and IT_ITEM. IT_ITEM Contains labst.
If i use the following code as u mentioned Im not getting the required output.
The code is
loop at IT_ITEM.
AT END OF LABST.
SUM.
APPEND IT_ITEM TO IT_ITEM1.
ENDAT.
ENDLOOP.
MOVE IT_ITEM1[] TO IT_ITEM[].
endform.
IT_ITEM AND IT_HEADER are declared with hearderlines. I hope Im clear. Also please correct my understanding of your help.
2005 Apr 28 2:25 PM
Hi Santosh,
I hope the following code will be useful for you. Its woriking fine for Simple ALV. You just try with your Hierarchical ALV.
Declare Sorting Internal Table with SLIS Type.
i_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
i_sort-tabname = 'DATATAB' " Internal Table Name
i_sort-fieldname = 'MATNR'. " Give Fieldname
i_sort-up = 'X'. " For Ascending Order
i_sort-subtot = 'X'. " This is for subtotal
APPEND i_sort.
CLEAR i_sort.
Before using this you must have give Total for any for * the column in ALV
While passing this I_SORT use [] bracket. Because I have declared i_sort with Header Line.
Ex:
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
. . . .
it_sort = i_sort[]
. . . .
I have given simple list ALV. Please try this for Hierarchy.
Regards,
Jeyakumar
2005 May 02 10:37 AM
Hi,
Thank u 4 u hlp. But it is giving grand total instead of subtotal.
Here with I have included the code.Please help me with the corrections, to get the subtotals for Unrestricted Qty.
report ZSALV03
no standard page heading
line-size 256
line-count 70(4) " 4 lines reserved for footer
message-id ZSANT." Messages used in the Report are Stored
*********************Type Declaration
type-pools:SLIS." Container for AlV types
********************Table Declaration
tables : MARA,"General Material Data
MARD,"Storage Location Data for Material
MAKT."Material Descriptions
*****************Data Declaration
DATA: BEGIN OF it_header OCCURS 0,
MATNR LIKE MARA-MATNR,
MAKTX LIKE MAKT-MAKTX,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
END OF it_header.
DATA: BEGIN OF it_item OCCURS 0,
MATNR LIKE MARD-MATNR,
LABST LIKE MARD-LABST,
WERKS LIKE MARD-WERKS,
LGORT LIKE MARD-LGORT,
END OF it_item.
DATA: repid LIKE sy-repid,
i_layout TYPE slis_layout_alv,
i_fieldcat TYPE slis_t_fieldcat_alv,
ws_title TYPE lvc_title VALUE 'SALES ORDER',
i_header TYPE slis_t_listheader,
i_events TYPE slis_t_event,
keyinfo TYPE slis_keyinfo_alv,
SORT TYPE SLIS_T_SORTINFO_ALV.
****************Selection Screen
select-options: S_MATNR for MARA-MATNR."ENTER MATERIAL NUMBER
*****************SELECTION-SCREEN PROCESSING
at selection-screen.
if S_MATNR is initial.
message E001.
endif.
**************END OF SELECTION-SCREEN PROCESSING
*******************START OF SELECTION
start-of-selection.
perform FILLDATA.
perform FIELDCAT_INIT using :
'MATNR' 'IT_HEADER' 'Material No.' ,
'MAKTX' 'IT_HEADER' 'DESCRIPTION' ,
'WERKS' 'IT_HEADER' 'PLANT' ,
'LGORT' 'IT_HEADER' 'LOCATION' ,
'LABST' 'IT_ITEM' 'UNRESTRICTED'.
perform LAYOUT_INIT changing I_LAYOUT.
perform SORT.
perform HEADER changing I_HEADER.
perform FILLKEYINFO.
perform EVENT changing I_EVENTS.
perform LISTDISPLAY.
end-of-selection.
****************END OF SELECTION
&----
*& Form listdispplay
&----
text
----
form LISTDISPLAY.
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = I_LAYOUT
IT_FIELDCAT = I_FIELDCAT
IT_SORT = SORT
IT_EVENTS = I_EVENTS
I_TABNAME_HEADER = 'IT_HEADER'
I_TABNAME_ITEM = 'IT_ITEM'
IS_KEYINFO = KEYINFO
tables
T_OUTTAB_HEADER = IT_HEADER
T_OUTTAB_ITEM = IT_ITEM.
endform. "listdispplay
&----
*& Form FILLDATA
&----
text
----
form FILLDATA.
select * into corresponding fields of table IT_HEADER
from MARA as A inner join MAKT as B on A~MATNR = B~MATNR
inner join MARD as C on A~MATNR = C~MATNR
where A~MATNR in S_MATNR
and B~SPRAS = SY-LANGU.
select * from MARD into corresponding fields of table IT_ITEM
for all entries in IT_HEADER
where MATNR = IT_HEADER-MATNR.
endform. "FILLDATA
&----
*& Form FIELDCAT_INIT
&----
text
----
-->F text
-->T text
-->D text
----
form FIELDCAT_INIT using F T D .
data LINE_FIELDCAT type SLIS_FIELDCAT_ALV.
clear LINE_FIELDCAT.
move F to LINE_FIELDCAT-FIELDNAME.
move T to LINE_FIELDCAT-TABNAME .
move D to LINE_FIELDCAT-SELTEXT_L.
append LINE_FIELDCAT to I_FIELDCAT.
endform. " FIELDCAT_INIT
&----
*& Form FILLKEYINFO
&----
text
----
form FILLKEYINFO.
clear KEYINFO.
KEYINFO-HEADER01 = 'MATNR'.
KEYINFO-ITEM01 = 'MATNR'.
KEYINFO-HEADER02 = 'WERKS'.
KEYINFO-ITEM02 = 'WERKS'.
KEYINFO-HEADER03 = 'LGORT'.
KEYINFO-ITEM03 = 'LGORT'.
endform. "FILLKEYINFO
&----
*& Form layout_init
&----
text
----
<--P_I_LAYOUT text
----
form LAYOUT_INIT changing P_LAYOUT.
clear I_LAYOUT.
I_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
I_LAYOUT-F2CODE = '&ETA'.
I_LAYOUT-ZEBRA = 'X'.
I_LAYOUT-DETAIL_POPUP = 'X'.
I_LAYOUT-DETAIL_TITLEBAR = 'DETAILS OF THE SELECTED LINE'.
I_LAYOUT-CONFIRMATION_PROMPT = 'X'.
endform. " layout_init
&----
*& Form header
&----
text
----
<--P_I_header text
----
form HEADER using I_HEADER type SLIS_T_LISTHEADER.
data : LINE type SLIS_LISTHEADER.
clear LINE.
LINE-TYP = 'H'.
LINE-INFO = 'MATERIAL DETAILS PLANTWISE' .
append LINE to I_HEADER.
clear LINE.
LINE-TYP = 'S'.
LINE-KEY = 'Company Name'.
LINE-INFO = 'Unisoft Infotech Pvt Ltd.'.
append LINE to I_HEADER.
clear LINE.
LINE-TYP = 'S'.
LINE-KEY = 'Branch'.
LINE-INFO = 'Bangalore, India.'.
append LINE to I_HEADER.
endform. " header
&----
text
----
<--P_I_event text
----
form EVENT changing I_EVENT type SLIS_T_EVENT.
data : EVENT type SLIS_ALV_EVENT.
clear EVENT.
EVENT-NAME = 'TOP_OF_PAGE'.
EVENT-FORM = 'TOP_OF_PAGE'.
append EVENT to I_EVENTS.
clear EVENT.
EVENT-NAME = 'END_OF_LIST'.
EVENT-FORM = 'END-OF-LIST'.
append EVENT to I_EVENTS.
endform. " event
&----
*& Form top_of_page
&----
text
----
form TOP_OF_PAGE.
.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
IT_LIST_COMMENTARY = I_HEADER
I_LOGO = 'ENJOYSAP_LOGO'.
I_END_OF_LIST_GRID =
endform. "top_of_page
&----
*& Form END-OF-LIST
&----
text
----
form END-OF-LIST.
write:/ 'END OF REPORT'.
endform. "END-OF-LIST
&----
*& Form SORT
&----
text
----
form SORT.
data: S_SORT type SLIS_SORTINFO_ALV.
clear S_SORT.
S_SORT-FIELDNAME = 'LABST'.
S_SORT-TABNAME = 'IT_ITEM'.
S_SORT-SUBTOT = 'X'.
append S_SORT to SORT.
clear S_SORT.
endform. "SORT