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 - sub totals

Former Member
0 Likes
1,665

hi gurus

i have an alv display report of TAT for a month..

insp lot | Work center plant |....| TAT | ....

Above are some of my fields.

Now at the end of each work center , I have t display the TAT average in a row as a sub-total.

also at the end of the report for this month, i should display the total avg tat.

I started with this code.


*MOD
  DATA: l_i_sort TYPE slis_t_sortinfo_alv,
        l_wa_sort TYPE slis_sortinfo_alv.
  CONSTANTS:   l_c_int_1    TYPE int1 VALUE 1,
               l_c_int_2    TYPE int1 VALUE 2,
               l_c_arbpl    TYPE slis_fieldname  VALUE 'ARBPL'.

  l_wa_sort-spos = l_c_int_1.
  l_wa_sort-fieldname = l_c_arbpl.
  l_wa_sort-up = c_x.
  l_wa_sort-subtot = l_c_int_2.
  APPEND l_wa_sort TO l_i_sort.
*MOD

plz do the required modifications in my code for acheiving my result.

Thanks in advance..

chaitanya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,642

Hi,

Wherever you r filling the fieldcatalogue... just put the following logic if you have not.

wa_fieldcat-do_sum = 'X'.

Thanks.

Swati.

hi gurus

i have an alv display report of TAT for a month..

insp lot | Work center plant |....| TAT | ....

Above are some of my fields.

Now at the end of each work center , I have t display the TAT average in a row as a sub-total.

also at the end of the report for this month, i should display the total avg tat.

I started with this code.


*MOD
  DATA: l_i_sort TYPE slis_t_sortinfo_alv,
        l_wa_sort TYPE slis_sortinfo_alv.
  CONSTANTS:   l_c_int_1    TYPE int1 VALUE 1,
               l_c_int_2    TYPE int1 VALUE 2,
               l_c_arbpl    TYPE slis_fieldname  VALUE 'ARBPL'.

  l_wa_sort-spos = l_c_int_1.
  l_wa_sort-fieldname = l_c_arbpl.
  l_wa_sort-up = c_x.
  l_wa_sort-subtot = l_c_int_2.
  APPEND l_wa_sort TO l_i_sort.
*MOD

plz do the required modifications in my code for acheiving my result.

Thanks in advance..

chaitanya

12 REPLIES 12
Read only

Former Member
0 Likes
1,642

Hi Chaitanya ,

try this

*MOD

DATA: l_i_sort TYPE slis_t_sortinfo_alv,

l_wa_sort TYPE slis_sortinfo_alv.

CONSTANTS: l_c_int_1 TYPE int1 VALUE 1,

l_c_int_2 TYPE int1 VALUE 2,

l_c_arbpl TYPE slis_fieldname VALUE 'ARBPL'.

l_wa_sort-spos = l_c_int_1.

l_wa_sort-fieldname = l_c_arbpl.

l_wa_sort-up = c_x.

l_wa_sort-subtot =c_x. <----


changed to c_x

APPEND l_wa_sort TO l_i_sort.

*MOD

Read only

Former Member
0 Likes
1,642

Then how would the calculation of TAT being taken with my code.

Read only

0 Likes
1,642

Hi chaitanya,

you had mentioned the fieldname as ARBPL , work center

l_wa_sort-fieldname = l_c_arbpl.

So after every change in that field the subtotals will be calculated for the amount fields

so no need to mention TAT field

Read only

Former Member
0 Likes
1,643

Hi,

Wherever you r filling the fieldcatalogue... just put the following logic if you have not.

wa_fieldcat-do_sum = 'X'.

Thanks.

Swati.

Read only

Former Member
0 Likes
1,642

Hi,

Try this

data: i_layout type slis_layout_alv.

I_LAYOUT-totals_text = 'SUM TEXT'.

And pass the structure i_layout to the FM you are using.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = ws_program

is_layout = i_layout

Hope this helps you.

Also Go through the sample code for subtotal..

REPORT z_demo_alv_sort.

TYPES :

BEGIN OF ty_vbak,

vkorg TYPE vbak-vkorg, " Sales organization

kunnr TYPE vbak-kunnr, " Sold-to party

vbeln TYPE vbak-vbeln, " Sales document

netwr TYPE vbak-netwr, " Net Value of the Sales Order

waerk TYPE vbak-waerk, " Document currency

END OF ty_vbak.

DATA:

vbak TYPE vbak,

gt_vbak TYPE TABLE OF ty_vbak.

SELECT-OPTIONS :

s_vkorg FOR vbak-vkorg, " Sales organization

s_kunnr FOR vbak-kunnr, " Sold-to party

s_vbeln FOR vbak-vbeln. " Sales document

SELECTION-SCREEN :

SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.

PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

----


INITIALIZATION.

v_1 = 'Maximum of records to read'.

----


START-OF-SELECTION.

PERFORM f_read_data.

PERFORM f_display_data.

----


  • Form f_read_data

----


FORM f_read_data.

SELECT vkorg kunnr vbeln netwr waerk

UP TO p_max ROWS

INTO TABLE gt_vbak

FROM vbak

WHERE kunnr IN s_kunnr

AND vbeln IN s_vbeln

AND vkorg IN s_vkorg.

ENDFORM. " F_READ_DATA

----


  • Form f_display_data

----


FORM f_display_data.

TYPE-POOLS: slis. " ALV Global types

DEFINE m_fieldcat.

add 1 to ls_fieldcat-col_pos.

ls_fieldcat-fieldname = &1.

ls_fieldcat-ref_tabname = 'VBAK'.

ls_fieldcat-do_sum = &2.

ls_fieldcat-cfieldname = &3.

append ls_fieldcat to lt_fieldcat.

END-OF-DEFINITION.

DEFINE m_sort.

add 1 to ls_sort-spos.

ls_sort-fieldname = &1.

ls_sort-up = 'X'.

ls_sort-subtot = &2.

append ls_sort to lt_sort.

END-OF-DEFINITION.

DATA:

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv,

lt_sort TYPE slis_t_sortinfo_alv,

ls_sort TYPE slis_sortinfo_alv,

ls_layout TYPE slis_layout_alv.

m_fieldcat 'VKORG' '' ''.

m_fieldcat 'KUNNR' '' ''.

m_fieldcat 'VBELN' '' ''.

m_fieldcat 'NETWR' 'X' 'WAERK'.

m_fieldcat 'WAERK' '' ''.

m_sort 'VKORG' 'X'. " Sort by vkorg and subtotal

m_sort 'KUNNR' 'X'. " Sort by kunnr and subtotal

m_sort 'VBELN' ''. " Sort by vbeln

ls_layout-cell_merge = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = ls_layout

it_fieldcat = lt_fieldcat

it_sort = lt_sort

TABLES

t_outtab = gt_vbak.

ENDFORM. " F_DISPLAY_DATA

                                  • END OF PROGRAM Z_DEMO_ALV_SORT **********************

Regards,

Raj.

Read only

Former Member
0 Likes
1,642

Hello Chaitanya,

In the fieldcatalog of the work center plant , give sort = 'X'.

In the fieldcatalog of the TAT field , give the sub_tot = 'X'.

If u do the subtotal in the ALV, then it automatically display the total field at the end of the field.

Hope it is helpful.

Reward Points.

Read only

Former Member
0 Likes
1,642

Hi,

and one more thing is , have you passed the table l_i_sort to FM REUSE_ALV_GRID_DISPLAY

it_sort = l_i_sort

Read only

0 Likes
1,642

Thank u chandrasekhar.

iam solved, if any prob, i will ask u

Read only

0 Likes
1,642

HI,

I have got the sub totals.

But now i should give my text for that sub-total work center wise

and for the final report.

for ex: Sub- total for work center = ____

avg TAT for the month is = _____

how to go about this :

Read only

venkat_o
Active Contributor
0 Likes
1,642

Hi Chaitanya, Do u want to display TAT average for each Work Center or TAT subtotal for one Work Center ? If you build SORT table and pass through function module, it displays total TAT for that Work Center not Average value of TAT. If u want only subtotal then build SORT Table and pass that.

w_sort-fieldname = 'ARBPL'.
  w_sort-tabname   = 'ITAB'. "Which is displayed through function module REUSE*
  w_sort-up        = 'X'.  "Ascending order
  w_sort-subtot    = 'X'. "Subtotal
  APPEND w_sort TO i_sort.
  CLEAR  w_sort.
If you want to have subtotal text as well .Check this link. [http://www.saptechnical.com/Tutorials/ALV/Subtotals/text.htm|http://www.saptechnical.com/Tutorials/ALV/Subtotals/text.htm] Regards, Venkat.O

Read only

Former Member
0 Likes
1,642

I want to display the avg TAT., i.e.. Total TAT for workcenter/ no of entries for work center

Wat can i do.

Read only

Former Member
0 Likes
1,642

s