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: 

getting percentage in grid display

Former Member
0 Kudos

Hi all,

Requrement is that we have three columnsin a grid display using containers,

we got the total by do_sum = 'X' ,for first two colums and the third one is

percentage of the second in first.

ex : o/p is

5 2.5 50

10 2.5 25

15 5 33

how to get 33 there and we got 15 and 5 by option do_sum.

by using do_sum= 'C' for the third column

We are getting mean of that colum but we need % by adjacent subtotals.

please help me out....

Regards ,

Anil.

8 REPLIES 8

0 Kudos

Hi,

If you want the output in ALV report then you have to do caluculations in the report before displaying.

Before populataing into final internal take the totals into temp. variables.

Use loop endloop. In between loop and endloop. use sum or collect statement and move the totals into temp variables and do the percentages.At end of the list display the percentage.

If you want display in the normal report it's little bit easy same procedure as above.

Regards,

Surendar Reddy.

Edited by: suredarreddy pulimamidi on Mar 3, 2009 4:40 PM

0 Kudos

Hi Surender,

can u put in a more feasible manner.

how to collect the system generated subtotals and how to diaplay at the end of the column.

Former Member
0 Kudos

can anyone please help me out.

Former Member
0 Kudos

based on your requirement, u have to maintain all calcultion data in the internal table body before. after that u can pass the internal table data using alv grid.

better u try to use control break events for the internal table.

i think no need to write do_sum for percentage.

i hope it will help u.

Former Member
0 Kudos

Hi,

Rather then calcualting in grid do the mathmatical functions in internal table and assign it to grid after doin cum and percentage in table.

Or

You can use the method get_subtotals, since this method returns a reference you can use it to change the values displayed as subtotals to what ever you want, not just percentages - ratios, powers, logarithms, anything you want. I havenu2019t still tested whether the values youu2019ve changed are changed back, when you hide columns (or do something with the ALV grid) in the ALV grid after itu2019s been displayed.

CREATE OBJECT gr_alvcon

EXPORTING container_name = u2018ABCu2019. u201CName of the custom container

CREATE OBJECT gr_alvgrid

EXPORTING i_parent = gr_alvcon.

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

is_layout = ps_layout

CHANGING

it_fieldcatalog = fieldcat

it_sort = it_sort

it_outtab = it_delsm[].

DATA : total TYPE REF TO data,

subto TYPE REF TO data.

FIELD-SYMBOLS <ftotal> TYPE STANDARD TABLE.

FIELD-SYMBOLS <fsubto> TYPE STANDARD TABLE.

DATA wa_tot TYPE t_delsm.

CALL METHOD gr_alvgrid->get_subtotals

IMPORTING ep_collect00 = total

ep_collect01 = subto.

ASSIGN total->* TO <ftotal>.

ASSIGN subto->* TO <fsubto>.

LOOP AT <ftotal> INTO wa_tot.

wa_tot-delpc = wa_tot-delpr * 100 / wa_tot-totpr. " Set any value for this

MODIFY <ftotal> FROM wa_tot INDEX sy-tabix.

ENDLOOP.

CALL METHOD gr_alvgrid->set_ready_for_input

EXPORTING i_ready_for_input = 1.

Kindly hav a look on below link .This link can solve ur problem

http://www.xvpj.net/tag/sap/

Thanks,

Smita

Edited by: Smita Gupta on Mar 5, 2009 9:27 AM

0 Kudos

Hi Smita,

My code is same as of that of in the link.

Iam able to manipulate by that but it is not reflecting in the output.

I got stucked in minor issue i think but can u suggest by verifying my code,

DATA : total TYPE REF TO data.
 
FIELD-SYMBOLS <ftotal> TYPE STANDARD TABLE.
 
DATA :  wa_tot TYPE ty_dcocd.    "intenal table type
 
CALL METHOD cl_alv_grid->get_subtotals
    IMPORTING ep_collect00 = total.  " getting the last row having totals
 
ASSIGN total->* TO <ftotal>.          
  LOOP AT <ftotal> INTO wa_tot.
 wa_tot-prcnt = wa_tot-sum_ol / wa_tot-sum * 100 . " calculating percentage from first two colums 
  MODIFY <ftotal> FROM wa_tot INDEX sy-tabix . "changing thefield symbol
endloop.
 
  CALL METHOD cl_alv_grid->refresh_table_display
    EXPORTING
      i_soft_refresh = 'X'.

if I check in <ftotal> ,Iam getting the changed last row with percentage but it is not reflecting in the output.what we need to do for that.

Regards,

Anil

former_member198275
Active Contributor
0 Kudos
DATA : IS_LAYOUT TYPE LVC_S_LAYO.


CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.

    METHODS HANDLE_AFTER_USER_COMMAND
      FOR EVENT AFTER_USER_COMMAND OF CL_GUI_ALV_GRID
      IMPORTING E_UCOMM.

  PRIVATE SECTION.
ENDCLASS.                    "lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_AFTER_USER_COMMAND.
  ENDMETHOD.                    "handle_after_user_command
ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION




FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.

    DATA: GR_EVENTS TYPE REF TO LCL_EVENT_RECEIVER.
  DATA : LS_SEL_HIDE            TYPE SLIS_SEL_HIDE_ALV.
  DATA REF1 TYPE REF TO CL_GUI_ALV_GRID.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      ES_SEL_HIDE = LS_SEL_HIDE
      E_GRID      = REF1.


  CREATE OBJECT GR_EVENTS.
  SET HANDLER GR_EVENTS->HANDLE_AFTER_USER_COMMAND FOR REF1.

  SET PF-STATUS 'ZPF_SALES_R'.

  PERFORM SUBTOTAL.
ENDFORM. "set_pf_status




FORM SUBTOTAL .
  DATA: LREF_DATA  TYPE REF TO DATA.
  DATA REF1 TYPE REF TO CL_GUI_ALV_GRID.

  FIELD-SYMBOLS: <L_SUM_TAB> TYPE TABLE,
                 <L_SUM> TYPE TT_FINAL.

  DATA : LS_SEL_HIDE  TYPE SLIS_SEL_HIDE_ALV.

  DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT,
         WA_FIELDCATALOG TYPE LVC_S_FCAT.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      ES_SEL_HIDE = LS_SEL_HIDE
      E_GRID      = REF1.

  CALL METHOD REF1->GET_FRONTEND_FIELDCATALOG
    IMPORTING
      ET_FIELDCATALOG = IT_FIELDCATALOG.
******************************************************
  CALL METHOD REF1->GET_FRONTEND_LAYOUT
    IMPORTING
      ES_LAYOUT = IS_LAYOUT.

  CALL METHOD REF1->SET_FRONTEND_FIELDCATALOG
    EXPORTING
      IT_FIELDCATALOG = IT_FIELDCATALOG.

  CALL METHOD REF1->REFRESH_TABLE_DISPLAY
    EXPORTING
      I_SOFT_REFRESH = ''.

  CALL METHOD REF1->GET_SUBTOTALS
    IMPORTING
      EP_COLLECT00 = LREF_DATA.
*******************************************
  ASSIGN LREF_DATA->* TO <L_SUM_TAB>.
  LOOP AT  <L_SUM_TAB> ASSIGNING <L_SUM>.
    IF <L_SUM>-OP_PICS NE 0.
      COMPUTE : <L_SUM>-AVG = <L_SUM>-TINV_OP / <L_SUM>-OP_PICS. "put your logic here
    ENDIF.
  ENDLOOP.
*******************************************
  CALL METHOD REF1->GET_FRONTEND_LAYOUT
    IMPORTING
      ES_LAYOUT = IS_LAYOUT.
  CALL METHOD REF1->SET_FRONTEND_FIELDCATALOG
    EXPORTING
      IT_FIELDCATALOG = IT_FIELDCATALOG.

  CALL METHOD REF1->REFRESH_TABLE_DISPLAY
    EXPORTING
      I_SOFT_REFRESH = 'X'.
ENDFORM.                    " SUBTOTAL

0 Kudos

Hi there,

one hint that I can give is that setting do_sum prperty to 'C' will cause that the user-calculated values are overwritten again with the averages calculated by the ALV grid.

So you must set do_sum = 'X' for this approach to work.

After I did that it all worked fine with an event handler for 'END_OF_PAGE' (using slis, i.e. REUSE_ALV functions) consisting of 4 steps:

1. get ALV reference via 'GET_GLOBALS_FROM_SLVC_FULLSCR'

2. get the subtotals tables via 'get_subtotals' method

3. modify the subtotals tables as required

4. refreshing ALV by refresh_table_display-method (soft refresh)

Hope this helps anyone.

Greetings!

R.