Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

SUM OF THE COLOMNS SHOULD BE PASSED TO FOOTER IN ALV

Hi,

I have to pass the sum of 3 colomns in ALV report to a footer in the alv.

Could you please give me some hint.

my report is regarding car counts...the report goes like this

CARTYPE MARUTHI TATA HUNDAI

small 4 2 1

medium 3 1 0

large 1 0 0

very large 0 1 1

total 8 4 2

footer

total cars : 14 (i.e 842)

for service : some value (count of some more fields)

out of service some value (count of some more fields)

for footer i have used class cl_dd_document

this is the code ...for this how do i pass the count

FORM end_of_list_html USING end TYPE REF TO cl_dd_document.

DATA: ls_text TYPE sdydo_text_element,

l_grid TYPE REF TO cl_gui_alv_grid,

f(14) TYPE c VALUE 'SET_ROW_HEIGHT'.

ls_text = 'Total Cars'.

CALL METHOD end->add_text

EXPORTING

text = ls_text

sap_emphasis = 'strong'.

CALL METHOD end->new_line.

CALL METHOD end->new_line.

CALL METHOD end->add_text

EXPORTING

text = 'Out Of Service'

sap_emphasis = 'strong'.

CALL METHOD end->new_line.

CALL METHOD end->new_line.

CALL METHOD end->add_text

EXPORTING

text = 'Available For Service'

sap_emphasis = 'strong'.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

e_grid = l_grid.

CALL METHOD l_grid->parent->parent->(f)

EXPORTING

id = 3

height = 14.

ENDFORM. "end_of_list_html.

please help

Thnaks

Sujeer

Tags:
Former Member
Former Member replied

check this example , in this i am using the method get_subtotals using grid object, based on that i calculated the totals check it once.

REPORT  ZTEST_ALV_001.
TYPE-POOLS: SLIS.
data: it_sort type  SLIS_T_SORTINFO_ALV,
      wa_sort like line of it_sort.

data: it_flight type standard table of sflight.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT LIKE LINE OF IT_FIELDCAT.

start-of-selection.

select * from sflight
into table it_flight
up to 20 rows.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
 EXPORTING
   I_PROGRAM_NAME               = SY-REPID
   I_STRUCTURE_NAME             = 'SFLIGHT'
  CHANGING
    ct_fieldcat                  = IT_FIELDCAT
 EXCEPTIONS
   INCONSISTENT_INTERFACE       = 1
   PROGRAM_ERROR                = 2
   OTHERS                       = 3
          .
IF sy-subrc NE 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WA_FCAT-do_sum = 'X'.
MODIFY IT_FIELDCAT FROM WA_FCAT TRANSPORTING do_sum
 WHERE FIELDNAME = 'SEATSOCC' or
       fieldname = 'SEATSOCC_B' or
       fieldname = 'SEATSOCC_F'.

wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
wa_sort-fieldname = 'CONNID'.
append wa_sort to it_sort.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                = SY-REPID
*   I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
   I_CALLBACK_HTML_END_OF_LIST       = 'END_OF_LIST'
   I_STRUCTURE_NAME                  = 'SFLIGHT'
   it_sort                           = it_sort
   IT_FIELDCAT                       = IT_FIELDCAT
  TABLES
    t_outtab                          = IT_FLIGHT
 EXCEPTIONS
   PROGRAM_ERROR                     = 1
   OTHERS                            = 2
          .
IF sy-subrc NE 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


FORM end_of_list USING end TYPE REF TO cl_dd_document.
DATA: ls_text TYPE sdydo_text_element,
l_grid TYPE REF TO cl_gui_alv_grid,

f(14) TYPE c VALUE 'SET_ROW_HEIGHT'.
data: tot type S_SMAX_B,
      wa_fl type sflight,
      text type sdydo_text_element.

field-symbols: <fs1> type standard table,
               <fs> type sflight.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.

CALL METHOD l_grid->parent->parent->(f)
EXPORTING
id = 3
height = 14.
data: total type ref to data.
call method l_grid->GET_SUBTOTALS
 importing
  EP_COLLECT00 = total.

assign total->* to <fs1>.
assign wa_fl to <fs>.

loop at <fs1> into <fs>.
endloop.

tot = <fs>-seatsocc + <fs>-seatsocc_b + <fs>-seatsocc_f.
write tot to text.
break-point.

ls_text = 'Total flights:'.

CALL METHOD end->add_text
EXPORTING
text = ls_text
sap_emphasis = 'strong'.

CALL METHOD end->add_text
EXPORTING
text = text
sap_emphasis = 'strong'.

CALL METHOD end->new_line.
CALL METHOD end->new_line.


CALL METHOD end->add_text
EXPORTING
text = 'Total economy class'
sap_emphasis = 'strong'.

write <fs>-seatsocc to text.

CALL METHOD end->add_text
EXPORTING
text = text
sap_emphasis = 'strong'.

CALL METHOD end->new_line.
CALL METHOD end->new_line.


CALL METHOD end->add_text
EXPORTING
text = 'Total Business class'
sap_emphasis = 'strong'.

write <fs>-seatsocc_b to text.

CALL METHOD end->add_text
EXPORTING
text = text
sap_emphasis = 'strong'.

CALL METHOD end->new_line.
CALL METHOD end->new_line.


CALL METHOD end->add_text
EXPORTING
text = 'Total First class'
sap_emphasis = 'strong'.

write <fs>-seatsocc_f to text.

CALL METHOD end->add_text
EXPORTING
text = text
sap_emphasis = 'strong'.

break-point.
ENDFORM. "end_of_list_html.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question