Skip to Content
0
Former Member
Jul 13, 2006 at 02:16 PM

totas and sub totals in ALV grid display

33 Views

Hi all,

how can I get the total for an integer field in internal table. I am using the following code, but unable to display the total. Can anyone give the reason for the same.

Thank you,

Usha

REPORT ZTEST_SUB .

TABLES : vbak.

TYPE-POOLS: slis.

SELECT-OPTIONS : s_vkorg FOR vbak-vkorg,

s_kunnr FOR vbak-kunnr,

s_vbeln FOR vbak-vbeln.

SELECTION-SCREEN : SKIP,

BEGIN OF LINE,

COMMENT 5(27) v_1 FOR FIELD p_max.

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

SELECTION-SCREEN END OF LINE.

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.

DATA: BEGIN OF gt_vbak OCCURS 0,

vkorg LIKE vbak-vkorg,

kunnr LIKE vbak-kunnr,

vbeln LIKE vbak-vbeln,

test type I,

END OF gt_vbak.

START-OF-SELECTION.

PERFORM f_read_data.

loop at gt_vbak.

gt_vbak-test = 1.

modify gt_vbak.

endloop.

PERFORM f_display_data.

FORM f_read_data.

SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak

FROM vbak UP TO p_max ROWS WHERE

kunnr IN s_kunnr AND

vbeln IN s_vbeln AND

vkorg IN s_vkorg.

ENDFORM.

FORM f_display_data.

DEFINE m_fieldcat.

add 1 to ls_fieldcat-col_pos.

ls_fieldcat-fieldname = &1.

ls_fieldcat-ref_tabname = 'VBAK'.

ls_fieldcat-ref_FIELDname = &2.

ls_fieldcat-do_sum = &3.

ls_fieldcat-cfieldname = &4.

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.

ls_sort-group = '*'.

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' 'VKORG' '' ''.

m_fieldcat 'KUNNR' '' '' ''.

m_fieldcat 'VBELN' '' '' ''.

m_fieldcat 'TEST' '' 'X' ''.

  • m_sort 'VKORG' ''.

  • m_sort 'KUNNR' ''.

  • m_sort 'VBELN' ''.

m_sort 'TEST' 'X'.

ls_layout-cell_merge = 'X'.

LS_LAYOUT-WINDOW_TITLEBAR = 'test window'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IS_LAYOUT = ls_layout

IT_FIELDCAT = lt_fieldcat

IT_SORT = lt_sort

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = gt_vbak

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.

endform.