Application Development and Automation 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: 
Read only

ALV Subtotal

Former Member
0 Likes
1,913

Hi experts,

attached is a picture of my report.

Can i put the value of the subtotal into a variable? Because i need to put the subtotal into another ALV by year.

Here is my code in getting the subtotal in alv.

   x_fieldcat-fieldname = 'GRADUATES'.

   x_fieldcat-seltext_l = 'Graduates'.

   x_fieldcat-tabname = 'it_detailed'.

   x_fieldcat-col_pos = 5.

   x_fieldcat-outputlen = '17'.

   x_fieldcat-do_sum = 'X'.

   APPEND x_fieldcat TO it_fieldcat.

   CLEAR x_fieldcat.

Like, gv_subtot = x_fieldcat-do_sum = 'X'.

is there any way that i can do that?

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,735

Hii calix,

you can't assign like

gv_subtot = x_fieldcat-do_sum = 'X'.

It will give u a dump.

To get subtotal u have to called the method get_subtotals of class cl_gui_alv_grid.

Do like below

Data: obj_grid type ref to cl_gui_alv_grid,

           subtotal type ref to data.

field-symbol <subtotal> like <internal table> which u r displaying in alv

CALL METHOD obj_grid->get_subtotals
  IMPORTING
    ep_collect00   = subtotal.              ---------this will hold the subtotal value.

    
assign subtotal->* to  <subtotal>.

now proceed according to requirement

regards

Syed

Hi experts,

attached is a picture of my report.

Can i put the value of the subtotal into a variable? Because i need to put the subtotal into another ALV by year.

Here is my code in getting the subtotal in alv.

   x_fieldcat-fieldname = 'GRADUATES'.

   x_fieldcat-seltext_l = 'Graduates'.

   x_fieldcat-tabname = 'it_detailed'.

   x_fieldcat-col_pos = 5.

   x_fieldcat-outputlen = '17'.

   x_fieldcat-do_sum = 'X'.

   APPEND x_fieldcat TO it_fieldcat.

   CLEAR x_fieldcat.

Like, gv_subtot = x_fieldcat-do_sum = 'X'.

is there any way that i can do that?

Thanks.

9 REPLIES 9
Read only

Former Member
0 Likes
1,735
Read only

anubhab
Active Participant
0 Likes
1,735

Hi Jepoy,

Please check the below link, it might be helpful...

http://scn.sap.com/thread/519906

Regards,

Anubhab

Read only

Former Member
0 Likes
1,735

Hi Jepoy,

You can use the method of the alv grid object given below:

CALL METHOD  <ref. var. to CL_GUI_ALV_GRID > ->get_subtotals.

Read only

Former Member
0 Likes
1,735

Hi,

I am using the OOPS and alv grid. The code i used is

 

CALL METHOD obj->fieldcatalog    (Calling a method)
    EXPORTING
      fieldname   = 'ROM_NO'
      tablename   = 'T_ROOM_BOOK'
      length      = '12'
      text        = 'Room Num'(004)
      hotspot     = 'X'
      do_sum      = ' '
      emphasize   = 'X'
    IMPORTING
      t_fieldcat = t_fieldcat.

Where t_fieldcat in an internal table for fieldcatalog.

Try this way,may it works. It works fine with mine.

Pass t_fieldcat to the grid function module calling ot through the grid object

set_table_for_first_display

    it_fieldcatalog               = t_fieldcat

Regards

Read only

0 Likes
1,735

Hi Amar,

    Here you are using fieldcatalog method.Can you please give me the SAP Class name?. I searched in CL_GUI_ALV_GRID.It is not exist. Please give me details.                                                                                                                                                                      

Thanks

Satya

Read only

0 Likes
1,735

Hi

Fieldcatalog is not a standard method.I said i am using OOPS and gird view. This is what i coded.

Class C1 Implementation.

Method

fieldcatalog IMPORTING   tablename   TYPE lvc_tname   

                                        fieldname   TYPE lvc_fname
                                        length      TYPE lvc_outlen
                                        text        TYPE lvc_txt
                                        hotspot     TYPE lvc_hotspt
                                        emphasize    TYPE lvc_emphsz
                             EXPORTING  t_fieldcat TYPE lvc_t_fcat,

Endmethod.

Endclass

DATA obj_c1 TYPE REF TO c1.

START-OF-SELECTION.
CREATE OBJECT obj_c1

CALL METHOD obj->fieldcatalog    (Calling a method)
    EXPORTING
      fieldname   = 'ROM_NO'                     "Field Name
      tablename   = 'T_ROOM_BOOK'        " Internal Table
      length      = '12'
      text        = 'Room Num'
      hotspot     = 'X'
      do_sum      = ' '
      emphasize   = 'X'
    IMPORTING
      t_fieldcat = t_fieldcat.

I think the case with you is because of the way you are passing the variables to the fieldcatalog table fields. See that you provide the inverted commas properly. Sometime that can be an issue

Hope this time it works fine as it worked for mine.

Regards.

Read only

0 Likes
1,735

Thanks for your quick response and good solution..

Read only

Former Member
Read only

Former Member
0 Likes
1,736

Hii calix,

you can't assign like

gv_subtot = x_fieldcat-do_sum = 'X'.

It will give u a dump.

To get subtotal u have to called the method get_subtotals of class cl_gui_alv_grid.

Do like below

Data: obj_grid type ref to cl_gui_alv_grid,

           subtotal type ref to data.

field-symbol <subtotal> like <internal table> which u r displaying in alv

CALL METHOD obj_grid->get_subtotals
  IMPORTING
    ep_collect00   = subtotal.              ---------this will hold the subtotal value.

    
assign subtotal->* to  <subtotal>.

now proceed according to requirement

regards

Syed