2007 Mar 14 6:11 AM
Hi Experts
I need a subtotal on a field(Unit of measuer field not quantity) field .
Can you please let me know the procedure.
Points are awarded for correct answers.
Regards,
Sreeram Kumar.M
2007 Mar 14 6:36 AM
GT_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
GT_SORT-FIELDNAME = 'UOM'.
GT_SORT-TABNAME = '1'.
GT_SORT-SPOS = 1.
GT_SORT-UP = 'X'.
GT_SORT-SUBTOT = 'X'.
Then in FCAT use parameter do_sum = 'X' for the totalisable fields.
Hi Experts
I need a subtotal on a field(Unit of measuer field not quantity) field .
Can you please let me know the procedure.
Points are awarded for correct answers.
Regards,
Sreeram Kumar.M
2007 Mar 14 6:16 AM
Have a look at code given in below link.
http://www.sap-basis-abap.com/sapalv.htm
You can go through sap documentation for details.
http://help.sap.com/saphelp_nw04/helpdata/en/ee/b99d37e188a049e10000009b38f8cf/content.htm
regards,
G@urav.
2007 Mar 14 6:18 AM
in your fieldcat for qty
ifieldcat-do_sum = 'X'.
build the sort table.
wsort-fieldname = 'MEINS'.
wsort-up = 'X'.
wsort-subtot = 'X'.
wsort-group = 'UL'.
append wsort to isort.
now pass the isort in your alv fn module call IT_SORT = isort.
it will give you uom wise subtotal for qty.
regards
shiba dutta
2007 Mar 14 6:18 AM
2007 Mar 14 6:20 AM
2007 Mar 14 6:22 AM
Hi,
This is the sample report for subtotal in ALV LIST report.
&----
*& Report YMS_SUBHEADINGALV2 *
*& *
&----
*& *
*& *
&----
REPORT YMS_SUBHEADINGALV2.
TYPE-POOLS : SLIS.
TYPES : BEGIN OF YVBRK_LIST,
VBELN LIKE VBRK-VBELN,
FKART LIKE VBRK-FKART,
BELNR LIKE VBRK-BELNR,
END OF YVBRK_LIST.
TYPES : BEGIN OF YVBRP_LIST,
VBELN LIKE VBRP-VBELN,
POSNR LIKE VBRP-POSNR,
NETWR LIKE VBRP-NETWR,
END OF YVBRP_LIST.
DATA: I_VBRK TYPE STANDARD TABLE OF YVBRK_LIST
INITIAL SIZE 0 WITH HEADER LINE.
DATA: I_VBRP TYPE STANDARD TABLE OF YVBRP_LIST
INITIAL SIZE 0 WITH HEADER LINE.
DATA: KEY_INFO TYPE SLIS_KEYINFO_ALV,
REPORT_ID LIKE SY-REPID,
TABLE_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
GT_EVENTS TYPE SLIS_T_EVENT,
GT_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
G_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
G_TOP_OF_LIST TYPE SLIS_FORMNAME VALUE 'TOP_OF_LIST'.
INITIALIZATION.
REPORT_ID = SY-REPID.
KEY_INFO-HEADER01 = 'VBELN'.
KEY_INFO-ITEM01 = 'VBELN'.
KEY_INFO-HEADER02 = SPACE.
KEY_INFO-ITEM02 = 'NETWR'.
GS_LAYOUT-GROUP_CHANGE_EDIT = 'X'.
GT_SORT-FIELDNAME = 'VBELN'.
GT_SORT-TABNAME = '1'.
GT_SORT-SPOS = 1.
GT_SORT-UP = 'X'.
GT_SORT-SUBTOT = 'X'.
GT_SORT-GROUP = '*'.
APPEND GT_SORT.
GT_SORT-FIELDNAME = 'POSNR'.
GT_SORT-TABNAME = '2'.
GT_SORT-SPOS = 2.
GT_SORT-UP = 'X'.
GT_SORT-SUBTOT = 'X'.
GT_SORT-GROUP = ''.
APPEND GT_SORT.
TABLE_FIELDCAT-FIELDNAME = 'VBELN'.
TABLE_FIELDCAT-seltext_m = 'Sales Document'.
TABLE_FIELDCAT-TABNAME = '1'.
TABLE_FIELDCAT-COL_POS = '1'.
TABLE_FIELDCAT-OUTPUTLEN = 17.
TABLE_FIELDCAT-DO_SUM = ' '.
APPEND TABLE_FIELDCAT.
TABLE_FIELDCAT-FIELDNAME = 'POSNR'.
TABLE_FIELDCAT-seltext_m = 'Sales Document Item'.
TABLE_FIELDCAT-TABNAME = '2'.
TABLE_FIELDCAT-COL_POS = '1'.
TABLE_FIELDCAT-OUTPUTLEN = 14.
TABLE_FIELDCAT-DO_SUM = ' '.
APPEND TABLE_FIELDCAT.
TABLE_FIELDCAT-FIELDNAME = 'NETWR'.
TABLE_FIELDCAT-seltext_m = 'Net value'.
TABLE_FIELDCAT-TABNAME = '2'.
TABLE_FIELDCAT-COL_POS = '2'.
TABLE_FIELDCAT-OUTPUTLEN = 15.
TABLE_FIELDCAT-DO_SUM = 'X'.
APPEND TABLE_FIELDCAT.
PERFORM EVENTTAB_BUILD USING GT_EVENTS[].
START-OF-SELECTION.
SELECT VBELN
FKART
BELNR
INTO CORRESPONDING FIELDS OF TABLE I_VBRK
FROM VBRK
WHERE VBELN > '0090000121' AND VBELN < '0090000135'.
SELECT VBELN
POSNR
NETWR
INTO CORRESPONDING FIELDS OF TABLE I_VBRP
FROM VBRP
FOR ALL ENTRIES IN I_VBRK
WHERE VBELN = I_VBRK-VBELN.
PERFORM WRITE_REPORT.
*&----
*& Form EVENTTAB_BUILD
*&----
text
*----
-->RT_EVENTS text
*----
FORM EVENTTAB_BUILD USING RT_EVENTS TYPE SLIS_T_EVENT.
"Registration of events to happen during list display
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = RT_EVENTS.
READ TABLE RT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE G_TOP_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO RT_EVENTS.
ENDIF.
ENDFORM. "EVENTTAB_BUILD
*&----
*& Form TOP_OF_PAGE
*&----
text
*----
FORM TOP_OF_PAGE.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
Header Data
REFRESH GT_LIST_TOP_OF_PAGE.
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
LS_LINE-INFO = 'Hierarchical Lists'.
APPEND LS_LINE TO GT_LIST_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
ENDFORM. "TOP_OF_PAGE
*&----
*& Form write_report
*&----
text
*----
FORM WRITE_REPORT.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPORT_ID
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = TABLE_FIELDCAT[]
IT_SORT = GT_SORT[]
IT_EVENTS = GT_EVENTS[]
I_TABNAME_HEADER = '1'
I_TABNAME_ITEM = '2'
I_STRUCTURE_NAME_HEADER = 'YVBRK_LIST'
I_STRUCTURE_NAME_ITEM = 'YVBRP_LIST'
IS_KEYINFO = KEY_INFO
TABLES
T_OUTTAB_HEADER = I_VBRK
T_OUTTAB_ITEM = I_VBRP.
ENDFORM. "write_report
Thanks,
Shankar
2007 Mar 14 6:22 AM
Hi,
For sub total you have to declare two variables for sorting as following,
DATA : w_sort TYPE slis_sortinfo_alv.
DATA : it_sort TYPE slis_t_sortinfo_alv.
Also add the following routine for the sort sequence,
&----
*& Form add_sortseq
&----
TO SORT AND GET THE TOTAL AND SUB TOTAL
----
-->P_SPOS text
-->P_FIELDNAME text
-->P_TABNAME text
-->P_SORT text
-->P_SUBTOTAL text
----
FORM add_sortseq USING p_spos LIKE alvdynp-sortpos
p_fieldname TYPE slis_fieldname
p_tabname TYPE slis_tabname
p_sort LIKE alvdynp-sortup
p_subtotal LIKE alvdynp-subtotals.
w_sort-spos = p_spos. " Sort order
w_sort-fieldname = p_fieldname.
w_sort-tabname = p_tabname.
w_sort-up = p_sort.
w_sort-subtot = p_subtotal. " Sub total allowed
w_sort-comp = 'X'.
w_sort-expa = ''.
APPEND w_sort TO it_sort.
CLEAR w_sort.
ENDFORM. "add_sortseq
Then finally call the routine inside the field catalogue for the particular field for which u have to do the sub total as follows,
PERFORM add_sortseq USING (sort position) (field) (internal table) (sort up) (subtotal)
(eg)
PERFORM add_sortseq USING '1' REPORT' 'ITAB1' 'X' 'X'.
Call the function module for the ALV grid or list according to your requirement and pass the sort variable as follows:
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IT_FIELDCAT = gt_fieldcat
IT_SORT = it_sort
TABLES
T_OUTTAB = itab1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
Regards,
Sathya
2007 Mar 14 6:29 AM
Hi!
On the ALV list there is an icon for sub-totals.
just click on the required field and press that icon.
If that icon is not present , then just click on any of the numeric fields and press the icon for total. The sub-total icon will appear.
Just check n Reply.
Regards,
Neha Bansal.
2007 Mar 14 6:36 AM
GT_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
GT_SORT-FIELDNAME = 'UOM'.
GT_SORT-TABNAME = '1'.
GT_SORT-SPOS = 1.
GT_SORT-UP = 'X'.
GT_SORT-SUBTOT = 'X'.
Then in FCAT use parameter do_sum = 'X' for the totalisable fields.
2007 Mar 14 12:16 PM