Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV SUBTOTAL

kesavadas_thekkillath
Active Contributor
0 Likes
936

How to get subtotal in ALV Based on conditions

Ex:in the below i want subtotal for only 101 type

TYPE Delivered

101 5

101 5

101 5

102 -8

301 -11

______________

101 15 <----ALV subtotal

7 REPLIES 7
Read only

Former Member
0 Likes
836

Hi,

Do it this way :

PERFORM fieldcat_init USING alv_fieldcat.

PERFORM sort_table.

alv_layout-colwidth_optimize = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = 'ZTEST' "Your report name

is_layout = alv_layout

it_fieldcat = alv_fieldcat

it_sort = it_sort[]

TABLES

t_outtab = wt_outtab

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.

    • Fieldcat perform

FORM fieldcat_init USING p_alv_fieldcat

TYPE slis_t_fieldcat_alv.

DATA : ls_fieldcol TYPE slis_fieldcat_alv.

CLEAR ls_fieldcol.

ls_fieldcol-reptext_ddic = text-001.

ls_fieldcol-fieldname = 'TYPE'.

ls_fieldcol-tabname = 'WT_OUTTAB'.

ls_fieldcol-col_pos = 1.

APPEND ls_fieldcol TO p_alv_fieldcat.

CLEAR ls_fieldcol.

ls_fieldcol-reptext_ddic = text-002.

ls_fieldcol-fieldname = 'DELIVERED'.

ls_fieldcol-tabname = 'WT_OUTTAB'.

ls_fieldcol-do_sum = 'X'.

ls_fieldcol-datatype = 'NUMC'.

ls_fieldcol-col_pos = 2.

In your sort perform write the below code :

wa_sort-fieldname = 'TYPE'.

wa_sort-tabname = 'WT_OUTPUT'.

wa_sort-spos = '1'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

wa_sort-fieldname = 'DELIVERED'.

wa_sort-tabname = 'WT_OUTPUT'.

wa_sort-spos = '2'.

wa_sort-up = 'X'.

APPEND wa_sort TO it_sort.

CLEAR wa_sort.

This should give you the required results.

Hope this helps!!

Regards,

Lalit Kabra

Read only

0 Likes
836

Ya i was aware of this...but i donot want the sub total of other types rather tha 101...i need only 101..

Is ths possible???

Any body there

Read only

0 Likes
836

classical report you can do some manipulation easily...

you can manipulate in ALV using ALV's event AFTER_LINE_OUTPUT here you can find some solution to do..

use the parameter P_RS_LINEINFO

http://www.saptechnical.com/Tutorials/ALV/Subtotals/Define.htm

Read only

0 Likes
836

Hi Keshu,

In ALV its not possible....

Read only

Former Member
0 Likes
836

HI,

as per ur requirement, after all the rows u need to display the subtotal of 101 type.

for that u need to manually calculate the total of the mov type and manually append a row into the final itab before ALV display. U can give color option also for highlighting it.

reply back...

With Rgds,

S.Bharani

Read only

Former Member
0 Likes
836

U can achieve it in ALV list. Try these steps:

Step 1

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

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.

CLEAR W_EVENT.

W_EVENT-FORM = SLIS_EV_AFTER_LINE_OUTPUT.

W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT.u201CAFTER_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 subtotalu2019s output is created using the WRITE and FORMAT statements.

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* << Replace it with ur own logic

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.

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.

Regards,

Joy.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
836

Thnx Jay and ghosh..

I got the concept...i guess it will only work in list display..

Kesav....:-)