Application Development 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: 

problem with alv subtotals

Former Member
0 Kudos

i have problem with subtotals display in AVL

actually my code is

FORM fill_field_catalog_table USING f d t s I.

DATA t_fld TYPE slis_fieldcat_alv.

STATICS pos LIKE sy-index VALUE 0.

pos = pos + 1.

CLEAR t_fld.

MOVE 1 TO t_fld-row_pos.

MOVE pos TO t_fld-col_pos.

MOVE f TO t_fld-fieldname.

MOVE d TO t_fld-seltext_m.

MOVE t TO t_fld-tabname.

MOVE s TO t_fld-do_sum.

MOVE I TO t_fld-NO_OUT.

if not t_fld-NO_OUT is initial. "based on a condition i am appendding the fieldcatlog

APPEND t_fld TO it_fieldcat.

endif.

if i remove "if not t_fld-NO_OUT is initial." this condition and append the fieldcat....

subtotals is getting dispalyed.

if i insert this code subtotals is not getting displayed...

can any body help me out in this fashion...

any input are required please fell free to contact me.

madan

5 REPLIES 5

Former Member
0 Kudos

hi madan

go through the following thread:

see if its of any help.

regards rajan.

0 Kudos

sorry to say this i was not able to understand or to my thinking i see no solution...

please can u help me out

0 Kudos

Hi Madan,

NO_OUT value range is 'SPACE' and 'X'

check if u have gone wrong there

SPACE is not same as INITIAL.

Also go through the following piece of code..

Execute it, u will understand it. At places comments will help u to understand better.

*&---------------------------------------------------------------------*
*& Report  ZRAJ_SUBTOTAL_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZRAJ_SUBTOTAL_ALV.



TYPE-POOLS: SLIS.

DATA: G_REPID LIKE SY-REPID,
      GT_SORT TYPE SLIS_T_SORTINFO_ALV,
      GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
      GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      FIELDCAT_LN LIKE LINE OF GT_FIELDCAT,
      COL_POS TYPE I.

DATA: BEGIN OF ITAB,
  FIELD1(5) TYPE C,
  FIELD2(5) TYPE C,
  FIELD3(5) TYPE P DECIMALS 2,
      END OF ITAB.

DATA: BEGIN OF ITAB1 OCCURS 0.
        INCLUDE STRUCTURE ITAB.
DATA: END OF ITAB1.

DATA: BEGIN OF ITAB_FIELDCAT OCCURS 0.
        INCLUDE STRUCTURE ITAB.
DATA: END OF ITAB_FIELDCAT.


INITIALIZATION.
  G_REPID = SY-REPID.

START-OF-SELECTION.
* TEST DATA
  MOVE 'TEST1' TO ITAB1-FIELD1.
  MOVE 'TEST1' TO ITAB1-FIELD2.
  MOVE '10.00' TO ITAB1-FIELD3.
  APPEND ITAB1.

  MOVE 'TEST2' TO ITAB1-FIELD1.
  MOVE 'TEST2' TO ITAB1-FIELD2.
  MOVE '20.00' TO ITAB1-FIELD3.
  APPEND ITAB1.

  DO 50 TIMES.
    APPEND ITAB1.
  ENDDO.

END-OF-SELECTION.

  PERFORM BUILD_CATALOG.
  PERFORM ALV_DISPLAY.

*&---------------------------------------------------------------------*
*&      Form  build_catalog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BUILD_CATALOG.
  DATA: FIELDCAT_IN TYPE SLIS_FIELDCAT_ALV.

  CLEAR FIELDCAT_IN.
  FIELDCAT_LN-FIELDNAME = 'FIELD1'.
  FIELDCAT_LN-TABNAME = 'ITAB1'.
*FIELDCAT_LN-NO_OUT = 'X'. "FIELD NOT DISPLAY, CHOOSE FROM LAYOUT
  FIELDCAT_LN-KEY = ' '. "SUBTOTAL KEY
  FIELDCAT_LN-NO_OUT = ' '.
  FIELDCAT_LN-SELTEXT_L = 'HEAD1'.
  APPEND FIELDCAT_LN TO GT_FIELDCAT.

  CLEAR FIELDCAT_IN.
  FIELDCAT_LN-FIELDNAME = 'FIELD2'.
  FIELDCAT_LN-TABNAME = 'ITAB1'.
  FIELDCAT_LN-NO_OUT = 'X'.
  FIELDCAT_LN-SELTEXT_L = 'HEAD2'.
  APPEND FIELDCAT_LN TO GT_FIELDCAT.

  CLEAR FIELDCAT_IN.
  FIELDCAT_LN-FIELDNAME = 'FIELD3'.
  FIELDCAT_LN-TABNAME = 'ITAB1'.
  FIELDCAT_LN-NO_OUT = ' '.
  FIELDCAT_LN-DO_SUM = 'X'. "SUM UPON DISPLAY
  APPEND FIELDCAT_LN TO GT_FIELDCAT.

* DATA SORTING AND SUBTOTAL
  DATA: GS_SORT TYPE SLIS_SORTINFO_ALV.

  CLEAR GS_SORT.
  GS_SORT-FIELDNAME = 'FIELD1'.
  GS_SORT-SPOS = 1.
  GS_SORT-UP = 'X'.
  GS_SORT-SUBTOT = 'X'. "This is an important statement
  APPEND GS_SORT TO GT_SORT.

  CLEAR GS_SORT.
  GS_SORT-FIELDNAME = 'FIELD2'.
  GS_SORT-SPOS = 2.
  GS_SORT-UP = 'X'.
*GS_SORT-SUBTOT = 'X'. "Note: This should be commented
  APPEND GS_SORT TO GT_SORT.

ENDFORM.                    "build_catalog

*&---------------------------------------------------------------------*
*&      Form  alv_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM ALV_DISPLAY.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
  I_CALLBACK_PROGRAM = G_REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
  I_STRUCTURE_NAME = 'ITAB1'
  IS_LAYOUT = GS_LAYOUT
  IT_FIELDCAT = GT_FIELDCAT[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
  IT_SORT = GT_SORT[]
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
*  IT_EVENTS =
* IT_EVENT_EXIT =
*  IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
  TABLES
  T_OUTTAB = ITAB1
  EXCEPTIONS
  PROGRAM_ERROR = 1
  OTHERS = 2.
ENDFORM.                    "alv_display

hope this will solve your problem

Regards Rajan.

Former Member
0 Kudos

Hi Madan,

Based on your posting, i feel that the sub-totals are being calculated based on the fields that is not displayed on the output. So, when you append field catalog based on that condition, the fields based on which sub-totals are calculated is not appended and hence sub-totals are not calculated in your output.

Actually you dont need that condition while apprnding field-catalog. You can remove that part of code, unless you have put that condition based on some requirement.

Best Regards,

Ram.

Former Member
0 Kudos

thanks for ur support