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 grid - displaying average value

Former Member
0 Likes
2,286

Please use a more informative subject in future. This time I've changed it for you.

Hi,

i want to get the average value in a field using ALV GRID.can anybody help me on this.

Edited by: Matt on Mar 30, 2009 9:45 AM

11 REPLIES 11
Read only

GauthamV
Active Contributor
1,816

Use this.

Fieldcatelog-do_sum = 'C'.

Read only

Former Member
0 Likes
1,816

Hi Gautham,

thank u i got the output.

Read only

GauthamV
Active Contributor
0 Likes
1,816

Plz close the thread once your issue is resolved.

Read only

Former Member
0 Likes
1,816

im not getting the options to give the points

Read only

GauthamV
Active Contributor
0 Likes
1,816

I think you didnt mark your thread as question that is why you are not getting that option.

Below the question check the check box for mark as question then you can see that.

Read only

anuj_srivastava
Active Participant
0 Likes
1,816

Hi ,

Could u be more precise with ur requirement ??

Regards,

Anuj

Read only

Former Member
0 Likes
1,816

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

Read only

I355602
Product and Topic Expert
Product and Topic Expert
1,816

Hi,

Refer:-


*FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv,
       wa_field TYPE slis_fieldcat_alv.

START-OF-SELECTION.

  PERFORM get_data. "<--get data into internal table

  PERFORM field_catalog. "<--create field catalog

END-OF-SELECTION.

  PERFORM alv_display. "<--call FM to display ALV

*&---------------------------------------------------------------------
*&      Form  FIELD_CATALOG
*&---------------------------------------------------------------------
*
FORM field_catalog .

  "create field catalog for other fields

  wa_field-fieldname = 'MENGE'.
  wa_field-tabname = 'IT_FINAL'.
  wa_field-edit = 'X'.
  wa_field-do_sum = 'C'. "<--for average of the column
  append wa_field to it_field.
  clear wa_field.

  "pass it_field in ALV FM

ENDFORM.                    " FIELD_CATALOG

Regards,

Tarun

Read only

Former Member
1,816

Hi,



Fieldcatelog-do_sum = 'C'

use this statement with the field catalog of that field for which you want to calculate AVG

Thanks

Arun

Read only

Former Member
0 Likes
1,816

Hi,

You can Calculate the values in your ABAP,put them into an internal table, and

populate the ALV grid from that.

Hope it will solve your problem.

with best regards,

Pulak

Read only

matt
Active Contributor
0 Likes
1,816

Please use a more informative subject in future. This time I've changed it for you.