Page tree
Skip to end of metadata
Go to start of metadata

Introduction:

The normal ALV list functionality provides for subtotals within the list and one grand total at the end of the report. If it is required to display the subtotals not within the list, but at the end of report the standard ALV functionality does not provide any way to do this. The tip described here caters to this special requirement.

Detail Steps:


Step 1 Define an internal table of type SLIS_T_EVENT, and a work area of type SLIS_ALV_EVENT.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA:	T_EVENT TYPE SLIS_T_EVENT,
	W_EVENT TYPE SLIS_ALV_EVENT.

Step 2

Append  AFTER-LINE-OUTPUT event to the internal table T_EVENT.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CLEAR W_EVENT.
W_EVENT-FORM = SLIS_EV_AFTER_LINE_OUTPUT.
W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT."AFTER_LINE_OUTPUT event
APPEND W_EVENT TO T_EVENT.

Step 3

The subtotals are calculated and displayed in the list from the subroutine AFTER_LINE_OUTPUT, which corresponds to the event AFTER_LINE_OUTPUT. This subroutine uses the parameter P_RS_LINEINFO, which contains settings for each line displayed in the list. The actual subtotal's output is created using the WRITE and FORMAT statements.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
FORM AFTER_LINE_OUTPUT
  USING P_RS_LINEINFO TYPE SLIS_LINEINFO.

* Declaration of local variables
  DATA: L_SUCCESS TYPE WRBTR,     "Total For Successful Entries
        L_ERROR   TYPE WRBTR,     "Total For Unsuccessful Entries
        L_COUNT   TYPE I.         "No. Of lines in table T_OUTPUT

* Getting No. of Lines in the table T_OUTPUT
  DESCRIBE TABLE T_OUTPUT LINES L_COUNT.

* Displaying the totals after the last record of the internal
* table T_OUTPUT
  IF P_RS_LINEINFO-TABINDEX = L_COUNT.

*   Loop At the internal table T_OUTPUT
    LOOP AT T_OUTPUT INTO W_OUTPUT.

      IF W_OUTPUT-SFLAG = C_CHECKED.
                             "Flag: Indicates error record

*       Calculate total for unsuccessful entries
        L_ERROR = L_ERROR + W_OUTPUT-WRBTR.

      ELSE.

*       Calculate total for successful entries
        L_SUCCESS = L_SUCCESS + W_OUTPUT-WRBTR.

      ENDIF.

*     Clear workarea W_OUTPUT
      CLEAR W_OUTPUT.

    ENDLOOP.

*   Set format for the total line display
    ULINE AT (P_RS_LINEINFO-LINSZ).        "Dynamic Line Size

    FORMAT INTENSIFIED COLOR COL_TOTAL ON. "Setting the color
                                           "For the total row
                                           "As Yellow

    WRITE : /    SY-VLINE,                 "Vertical Line
                 TEXT-017,                 "Caption For Total
"Sum of Successful
"Entries
              33 L_SUCCESS,                "Total Of Successful
                                           "Entries
                 C_USD.                    "Currency Type USD

    POSITION     P_RS_LINEINFO-LINSZ.      "Dynamic Line Size

    WRITE :      SY-VLINE.                 "Vertical Line

    ULINE AT     (P_RS_LINEINFO-LINSZ).    "Dynamic Line Size

    WRITE : /    SY-VLINE ,                "Vertical Line
                 TEXT-018,                 "Caption For Total
                                           "Sum of Successful
                                           "Entries
              33 L_ERROR,                  "Total Of Unsuccessful
                                           "Entries
                 C_USD.                    "Currency Type USD

    POSITION     P_RS_LINEINFO-LINSZ.      "Dynamic Line Size

    WRITE :      SY-VLINE.                 "Vertical Line

    FORMAT COLOR OFF.                      "Color Setting Off

  ENDIF.

ENDFORM.                                   "AFTER_LINE_OUTPUT

Step 4

The table T_EVENT is passed to the function 'REUSE_ALV_LIST_DISPLAY' while displaying the ALV Report.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
      I_CALLBACK_PROGRAM = L_REPID    "Program Name
      IS_LAYOUT          = W_LAYOUT   "Layout of the Report
      IT_FIELDCAT        = T_FIELDCAT "Field Catalog for Report
      IT_EVENTS          = T_EVENT    "For setting the events
   TABLES
      T_OUTTAB           = T_OUTPUT   "Report data Internal Table
   EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.

Result:

The rows 'Sum of Successful Entries' and 'Sum of Unsuccessful Entries', showing total of all the successful (green) entries and total of all the unsuccessful (red) entries respectively, have been added using this method.


 

Limitations:

1.      The subtotals to be displayed are not calculated by the normal functionality of the ALV, need to be calculated manually.

2.      If we download the list, the subtotals will not get downloaded.

1 Comment

  1. Unknown User (104tr4vwt)

    Hi Joyjit Ghosh,

    I have read few wikis of your on ALV. I learnt a lot.

    Right now, am doing an Hierarchial ALV whose display will be of standard format:

    1 Header data

    1.1.1 Item data

    1.1.1 item data

     1.2.1 Subtotals like no.of items

    1.2.2 Subtotals on quantities

    2. Header data

    2.1.1 Item data

    2.1.2 item data

    2.1.3 item data

    2.2.1 subtotals on no.of items

    2.2.2 subtotals on quantities

    3.1 Grand Total No of Purchase requestions at this purchasing group level

    3.2 Grand total of no of items at this purchasing group level

    3.3 Grand total of open qty at this purchasing group level.

    Next page, I should have a similar kind of data for the next new purchasing group.

    Can you please send me good links or materials or sample codes. Your help is highly appreciated.

    Thanks,

    Kiran