Skip to Content
0
Former Member
Feb 04, 2010 at 11:20 AM

Sum a column in a alv

30 Views

Hi guys,

I have an ALV (CL_GUI_ALV_GRID) and when I push the 'SUM' button it doesn't work , only put a symbol sum in the field but I can't see the line with a total sum./

I don't know if I have to refresh the ALV or call to another method .

CALL METHOD GR_ALVGRID->SET_TABLE_FOR_FIRST_DISPLAY
     EXPORTING
* I_BUFFER_ACTIVE =
* I_CONSISTENCY_CHECK =
*    I_STRUCTURE_NAME = 'ST_ALV'
     IS_VARIANT = MY_VARIANT
     I_SAVE = 'A'
     I_DEFAULT = 'X'
     IS_LAYOUT = GS_LAYOUT
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
     CHANGING
     IT_OUTTAB = LT_ALV[]
     IT_FIELDCATALOG = GT_FIELDCAT
*     IT_SORT = GT_SORT
* IT_FILTER =
.

The field catalog is

FORM PREPARE_FIELD_CATALOG CHANGING PGT_FIELDCAT TYPE LVC_T_FCAT.
  DATA LS_FCAT TYPE LVC_S_FCAT .
[...]
  LS_FCAT-COL_POS = '10'.
  LS_FCAT-FIELDNAME = 'SALDO' .
  LS_FCAT-REF_TABLE = 'GLT3'.
  LS_FCAT-INTTYPE = 'I' .
  LS_FCAT-OUTPUTLEN = '21' .
  LS_FCAT-COLTEXT = 'Saldo en BSIS/BSAS' .
  LS_FCAT-SELTEXT = 'Saldo en BSIS/BSAS ' .
*  LS_FCAT-DO_SUM = 'X'.
  CLEAR LS_FCAT-NO_SUM.
  APPEND LS_FCAT TO PGT_FIELDCAT .
  CLEAR LS_FCAT.
  LS_FCAT-COL_POS = '11'.
  LS_FCAT-FIELDNAME = 'TMLOC ' .
  LS_FCAT-REF_TABLE = 'GLT3'.
  LS_FCAT-INTTYPE = 'I' .
  LS_FCAT-OUTPUTLEN = '21' .
  LS_FCAT-COLTEXT = 'Saldo en GLT3' .
  LS_FCAT-SELTEXT = 'Saldo en GLT3' .
*  LS_FCAT-DO_SUM = 'X'.
  CLEAR LS_FCAT-NO_SUM.
  APPEND LS_FCAT TO PGT_FIELDCAT .
  CLEAR LS_FCAT.
  LS_FCAT-COL_POS = '12'.
  LS_FCAT-FIELDNAME = 'DIF' .
  LS_FCAT-REF_TABLE = 'GLT3'.
  LS_FCAT-INTTYPE = 'I' .
  LS_FCAT-OUTPUTLEN = '21' .
  LS_FCAT-COLTEXT = 'Diferencia' .
  LS_FCAT-SELTEXT = 'Diferencia' .
*  LS_FCAT-DO_SUM = 'X'.
  CLEAR LS_FCAT-NO_SUM.
  APPEND LS_FCAT TO PGT_FIELDCAT .
  CLEAR LS_FCAT.

ENDFORM.                    "PREPARE_FIELD_CATALOG

The layout is:

FORM  PREPARE_LAYOUT  CHANGING PGS_LAYOUT STRUCTURE GS_LAYOUT.
  DATA: TEXTO TYPE STRING,
        CONT0 TYPE I,
        CONT1 TYPE I.
  CLEAR: CONT0, CONT1, NUM_REG.
  LOOP AT LT_ALV INTO WA_ALV WHERE BUKRS EQ 0 AND TC EQ 'Total cuenta'.
    ADD 1 TO CONT0.
  ENDLOOP.
  DESCRIBE TABLE LT_ALV LINES CONT1.
*  DELETE LT_ALV WHERE TC EQ 'Total cuenta'.
  NUM_REG = CONT1 - CONT0.
  CONCATENATE 'El número de registros es:' NUM_REG INTO TEXTO.
  PGS_LAYOUT-GRID_TITLE = TEXTO.
*Excel
  PGS_LAYOUT-FRONTEND = 'X'.
*Totales
  PGS_LAYOUT-NUMC_TOTAL = 'X'.
  PGS_LAYOUT-NO_UTSPLIT = 'X'.
  PGS_LAYOUT-TOTALS_BEF = 'X'.
  PGS_LAYOUT-NO_TOTLINE = 0.
  PGS_LAYOUT-CTAB_FNAME = 'IT_FIELD_COLORS'.
ENDFORM.                    "PREPARE_LAYOUT

Thanks a lot.

Best regards

Ana 😉

Edited by: Ana Marí on Feb 4, 2010 12:23 PM