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: 

ALV sums using REUSE_ALV_LIST_DISPLAY

Former Member
0 Kudos

I am working in an old 4.0 system so I am using the function REUSE_ALV_LIST_DISPLAY to output my data, but I can't get teh ALV grid to include the totals button or indeed sum my values despite populating the field cat with 'Do_sum'.

Andy idead


    ls_fieldcat-fieldname = 'KWMENG'.                         
    ls_fieldcat-col_pos = '9'.                                
    ls_fieldcat-ref_fieldname  = 'KWMENG'.                    
    ls_fieldcat-ref_tabname    = 'GIT_DETAIL'.                
    ls_fieldcat-tabname        = 'GIT_DETAIL'.                
    "ls_fieldcat-ddictxt = 'L'.                               
    ls_fieldcat-outputlen = '14'.                             
    ls_fieldcat-seltext_l = 'Order Qty'.                      
    ls_fieldcat-do_sum    = 'X'.                              
    append ls_fieldcat to lit_fieldcat. clear ls_fieldcat.

* Displays the ALV grid                                       
      call function 'REUSE_ALV_LIST_DISPLAY'                  
        exporting                                             
          i_callback_program       = w_repid                  
          it_fieldcat              = lit_fieldcat[]           
          is_layout                = x_layout                 
          it_sort                  = lit_sort[]               
          i_callback_pf_status_set = w_status                 
          i_callback_user_command  = w_comm                   
          i_save                   = 'X'                      
          it_events                = lit_event[]              
          i_grid_title             = w_title                  
        tables                                                
          t_outtab                 = git_detail[]             
        exceptions                                            
          program_error            = 1                        
          others                   = 2.                       



5 REPLIES 5

Former Member
0 Kudos

Try using a different function module:

REUSE_ALV_GRID_DISPLAY

Former Member
0 Kudos

To display text for subtotal, declare a separate column in ALV output table and make this column hidden in the output. In SORT, set the SUBTOT field for this column. Then fill the event u2018SUBTOTAL_TEXTu2019 with the required text. At run time, this event will be triggered and the text will be displayed in ALV output.

Similarly, to display text for grand total, declare a separate column in ALV output table and pass the required text while populating data in ALV output table and make this column hidden in the output. In SORT, set the SUBTOT field for this column.

Hope it helps you.

Former Member
0 Kudos

To display the totals in the grid display add the following logic where you are populating the field catalog.

IF fldname = 'AMOUNT'.

wa_fcat-do_sum = 'X'.

ENDIF.

APPEND wa_fcat TO i_fieldcat.

CLEAR wa_fcat.

To display the subtotals in the grid display.

FORM populate_sort .

  • Sort on material

wa_sort-spos = '01' .

wa_sort-fieldname = 'MATNR'.

wa_sort-tabname = 'T_MAT'.

wa_sort-up = 'X'.

wa_sort-subtot = 'X'.

APPEND wa_sort TO it_sort .

CLEAR wa_sort.

ENDFORM. " populate_sort

Get the ALV grid event and pass the form name to subtotal_text event.

FORM get_events .

CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE

'SUBTOTAL_TEXT'.

DATA: ls_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it event

EXCEPTIONS

list_type_wrong = 0

OTHERS = 0.

  • Subtotal

READ TABLE it_event INTO ls_event

WITH KEY name = slis_ev_subtotal_text.

IF sy-subrc = 0.

MOVE c_formname_subtotal_text TO ls_event-form.

MODIFY it_event FROM ls_event INDEX sy-tabix.

ENDIF.

ENDFORM.

FORM subtotal_text CHANGING

p_total TYPE any

p_subtot_text TYPE slis_subtot_text.

  • Material level sub total

IF p_subtot_text-criteria = 'MATNR'.

p_subtot_text-display_text_for_subtotal

= 'Material level total'(009).

ENDIF.

ENDFORM. "subtotal_text

After this just pass it_event and it_sort to the ALV grid display.

Hope this helps you.

Former Member
0 Kudos

Hi,

REUSE_ALV_GRID_DISPLAY does not work in 4.0

Solution given by Harsh Bhalla seems workable , check it out.

Alternatively you can calculate and populate the totals as the last line in the internal table , append first field last line value as "TOTALS' . this will give meaning to the values. Try this

TC

Sajimon Chandran

Former Member
0 Kudos

The totals appear once I extend the field cat to include the data type settings..

gs_fieldcat-do_sum = 'X'.

gs_fieldcat-datatype = 'QUAN'.

"gs_fieldcat-inttype = 'P'.

gs_fieldcat-ddic_outputlen = '9'.