2006 Sep 22 7:44 PM
Hi Experts,
I have an alv report which should display the subtotals. I have gone through some of the topics in this forum and made changes accordingly.... but still I am not getting the totlas...
I am attaching the code below. Please tell me whats wrong in this one.... I have to get the sub toals and grand total for the field COUNT based on the field BUSAB.
DATA: int_fcat TYPE slis_t_fieldcat_alv,
w_layout TYPE slis_layout_alv,
i_repid LIKE sy-repid.
DATA: gt_sort TYPE slis_sortinfo_alv OCCURS 0 WITH HEADER LINE.
DATA: i_fcat TYPE slis_fieldcat_alv.
DATA: gs_sort TYPE slis_sortinfo_alv.
CLEAR i_fcat.
i_repid = sy-repid.
CLEAR i_fcat.
i_fcat-fieldname = 'BUSAB'.
i_fcat-seltext_l = 'Dunning Clerk'.
i_fcat-outputlen = '13'.
i_fcat-tabname = 'ITAB'.
APPEND i_fcat TO int_fcat.
CLEAR i_fcat.
i_fcat-fieldname = 'AUSDT'.
i_fcat-seltext_l = 'Dunning Date'.
i_fcat-outputlen = '13'.
i_fcat-tabname = 'ITAB'.
APPEND i_fcat TO int_fcat.
CLEAR i_fcat.
i_fcat-fieldname = 'BUKRS'.
i_fcat-seltext_l = 'Company Code'.
i_fcat-outputlen = '13'.
i_fcat-tabname = 'ITAB'.
APPEND i_fcat TO int_fcat.
CLEAR i_fcat.
i_fcat-fieldname = 'KUNNR'.
i_fcat-seltext_l = 'Customer'.
i_fcat-outputlen = '13'.
i_fcat-tabname = 'ITAB'.
APPEND i_fcat TO int_fcat.
CLEAR i_fcat.
i_fcat-fieldname = 'COUNT'.
i_fcat-seltext_l = 'Count'.
i_fcat-outputlen = '8'.
i_fcat-tabname = 'ITAB'.
i_fcat-do_sum = 'X'.
APPEND i_fcat TO int_fcat.
CLEAR gs_sort.
gs_sort-fieldname = 'BUSAB'.
gs_sort-spos = 1.
gs_sort-up = 'X'.
gs_sort-subtot = 'X'.
APPEND gs_sort TO gt_sort.
w_LAYOUT-TOTALS_TEXT = 'TOTAL'.
w_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
w_LAYOUT-SUBTOTALS_TEXT = 'SUB TOTAL'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = i_repid
I_STRUCTURE_NAME = 'ZFIDSSTRUCT'
IS_LAYOUT = w_layout
IT_FIELDCAT = int_fcat[]
it_sort = gt_sort[]
TABLES
t_outtab = itab
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.
2006 Sep 22 7:46 PM
Hi,
If the count is NUMC field..then PASS 'X' to the field
numc_sum in the layout structure..
Also the pass the internal table in the tabname field of the sort internal table..
Thanks,
Naren
2006 Sep 22 7:46 PM
Hi,
If the count is NUMC field..then PASS 'X' to the field
numc_sum in the layout structure..
Also the pass the internal table in the tabname field of the sort internal table..
Thanks,
Naren
2006 Sep 22 7:49 PM
Hi Naren,
i got it... thanks for your instant reply and good solution.
Regards
Asha
2006 Sep 22 8:01 PM
2006 Sep 22 8:05 PM
Hi Rich,
How did you find that whom the points are marked. The reaons for asking this question is ... becuase it will help me to determine the best possible answer. when going throught the post.
Pleas dont not ignore to reply this
Thanks in advance.
SDN
2006 Sep 22 8:13 PM
You can see that the blue star on my post means that my answer has solved the problem, but as you can see in the dialog, it appears that Naren's answer really solved the problem. I don't know for a fact that it did, but I know that my answer works also, but Naren's was first and Asha seems to be thanking him for the solution. So the blue star should really be next to Naren's answer, not mine.
Regards,
Rich Heilman
2006 Sep 22 7:49 PM
2006 Sep 22 7:51 PM
2006 Sep 22 7:51 PM
Hi,
See the Below example,
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
<b>FIELDCAT_LN-KEY = ' '. "SUBTOTAL KEY</b>
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.
<b>* DATA SORTING AND SUBTOTAL</b>
DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.
<b>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.</b>
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.
Regards
Sudheer