This website is not affiliated with, sponsored by, or approved by SAP AG.

Calculating values for ALV total lines

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Calculating values for ALV total lines

Postby Guest » Fri Jan 16, 2004 7:18 am

I have a report that has (among others) the following columns:
A - Hours Worked
B - Hours billed to client
C - Utilization ( = B/A expressed as a percentage)

If the report had the following 3 columns:
A B C
10 5 50%
10 5 50%
20 2 10%

I would like the totals to be:
A B C
40 12 30%

Where the '30%' is calculated from 40/12 and not a total, average, or mean value (which all give misleading values)

Any help/advice/pointers to documentation/miracles greatfully received!

Cheers,
Gary
Guest
 

Postby Senior » Fri Jan 16, 2004 7:32 am

Use event BEFORE_LINE_OUTPUT and modify your data table as needed, if lineinfo-subtot or lineinfo-endsum is not initial.

Code: Select all
form alv_before_line_output using p_lineinfo type slis_lineinfo.
  if p_lineinfo-subtot ne space or                 
     p_lineinfo-endsum ne space.                   
    case p_lineinfo-tabname.                       
      when 'IBOLUM'.                               
        perform divide_by_1000_bolum.             
        if p_lineinfo-subtot ne space.             
          modify ibolum index p_lineinfo-sumindex.
        endif.                                     
Senior
 
Posts: 43
Joined: Wed Nov 20, 2002 8:41 am
Location: Istanbul, TURKEY

Postby Guest » Wed Jan 28, 2004 9:28 am

Thanks Senior.

I have used put in the code for the event, however I still have a problem:

p_lineinfo-tabname is always blank.

and

the line i want to edit is not in any table within the calling program as it is a total line. So I would not be able to edit it.


I have been able to read the totals trough the function 'REUSE_ALV_TABLES_GET' but cannot get the changed tables back into the ALV.


:(
Guest
 

Postby Guest » Wed Jan 28, 2004 1:02 pm

Sorry, just a little mistake..

If the line is a subtotal line, you must modify the table. Subtotals are inserted to the table during output. But if it's the bottom line, don't modify it, just leave the value at the header line.

Code: Select all
  case p_lineinfo-tabname.
    when 'IDATA'.
      if p_lineinfo-subtot ne space.
        idata-dmbtr = 1234567.
        idata-maktx = 'Hehe'.
        modify idata index p_lineinfo-sumindex.
      endif.
      if p_lineinfo-endsum ne space.
        idata-dmbtr = 9999999.
        idata-maktx = 'Ooo, great total'.
      endif.
  endcase.


You can change all fields that are printed at the sum line, including fields that are sorted and causes the subtotal. Changes to other fields are meaningless.

p_lineinfo-tabname should always be full, you're using an itab to display with ALV, right? 8)

I'm working on a 4.0B system, but I guess it's the same at higher releases.
Guest
 

Postby Pete123 » Fri Jan 30, 2004 11:42 am

If you got this working could you post the report.

Many thanks

Pete
Pete123
 

Postby Guest » Tue Feb 03, 2004 12:15 pm

What is IDATA. Is it the internal table passed to the ALV function.
Guest
 

Postby RosieBrent » Wed Feb 04, 2004 5:26 am

Anonymous wrote:What is IDATA. Is it the internal table passed to the ALV function.


Yes.
Kind Regards

Rosie Brent

Please remember to search the forum and check the FAQ before posting questions, thank you.

Tuly Idiot most of the time, part-time Guru Image
RosieBrent
 
Posts: 6197
Joined: Mon Oct 21, 2002 3:04 am
Location: Darlington

Postby Guest » Wed Feb 04, 2004 7:39 am

Finally I have it working.
Although for me, I don't know why, p_lineinfo-tabname is always '1'.
Anyway it works great.
I had some trouble because when passing the internal table with the values to display to the function 'REUSE_ALV_LIST_DISPLAY' I put i_table[]. Therefore the header was always empty and could not change.
Passing the internal table with the header made it perfect.

Thanks a lot Senior.

Alfredo Doforno
Guest
 

Postby adsz73 » Wed Mar 23, 2005 3:13 am

I had similar problem with percentage for subtotals.
It was solved using your tips - thank you guys !

Kind regards,
Adam
adsz73
 
Posts: 10
Joined: Mon Jul 19, 2004 3:13 am

Calculating values for ALV total lines

Postby sfi_abap » Wed Apr 27, 2005 2:19 am

:roll:
is there a similar event in cl_gui_alv_grid_object? help please.
sfi_abap
 

I have same problem of Dynamically subtotalling Pls. Help me

Postby priyank_sap » Tue Nov 22, 2005 7:21 am

Hi Dear Gary,

I have same problem of calculating of percentage on subtotaling fields.

But i can not go on to event. can u give me source code(Event + Calling Event) so that its being easy to understand me.

Awaiting your reply.

Regrds
Priyank Patel
There is no limit to fly.

Priyank Patel
priyank_sap
 
Posts: 28
Joined: Sat Sep 10, 2005 12:50 am
Location: +91-79

ITs Work NOw

Postby priyank_sap » Thu Nov 24, 2005 5:44 am

Now Its work for me . its too good logic. Nnnow no need for Source code as i want from you.Sorry.


Thanx.
There is no limit to fly.

Priyank Patel
priyank_sap
 
Posts: 28
Joined: Sat Sep 10, 2005 12:50 am
Location: +91-79

Source code for ALV percentage ?

Postby Abap_help1 » Wed Nov 30, 2005 12:26 am

Hi ABAPers
Can anybody send me the Source code for this ALV Percentage problem Please

Thanks in Advance
Abap_help1
 

Postby ocvantol » Wed Dec 07, 2005 3:51 am

I have been trying to get this working but I have a problem with the event stuff.
Code: Select all
REPORT ztest.

TYPE-POOLS:
  slis.

DATA:
  BEGIN OF lt_data OCCURS 0,
    buy  LIKE bseg-dmbtr,
    sell LIKE bseg-dmbtr,
    diff LIKE t5efi-prznt,
  END OF lt_data.
DATA:
  lt_fieldcat TYPE slis_t_fieldcat_alv,
  lt_events   TYPE slis_t_event.
DATA:
  ls_fieldcat TYPE slis_fieldcat_alv,
  ls_events   TYPE slis_alv_event.

* Fill data tab
lt_data-buy  = '100'.
lt_data-sell = '200'.
lt_data-diff = 100 * ( lt_data-sell - lt_data-buy ) / lt_data-buy.
APPEND lt_data.

lt_data-buy  = '200'.
lt_data-sell = '300'.
lt_data-diff = 100 * ( lt_data-sell - lt_data-buy ) / lt_data-buy.
APPEND lt_data.

lt_data-buy  = '300'.
lt_data-sell = '400'.
lt_data-diff = 100 * ( lt_data-sell - lt_data-buy ) / lt_data-buy.
APPEND lt_data.

* Build field catalog
ls_fieldcat-fieldname  = 'BUY'.
ls_fieldcat-tabname    = 'LT_DATA'.
ls_fieldcat-col_pos    = 1.
ls_fieldcat-do_sum     = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.
ls_fieldcat-fieldname  = 'SELL'.
ls_fieldcat-tabname    = 'LT_DATA'.
ls_fieldcat-col_pos    = 2.
ls_fieldcat-do_sum     = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.

CLEAR ls_fieldcat.
ls_fieldcat-fieldname  = 'DIFF'.
ls_fieldcat-tabname    = 'LT_DATA'.
ls_fieldcat-col_pos    = 3.
APPEND ls_fieldcat TO lt_fieldcat.

* Get events
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
     IMPORTING
          et_events = lt_events.
READ TABLE lt_events WITH KEY name = 'BEFORE_LINE_OUTPUT'
     INTO ls_events.

* Add Form for event BEFORE_LINE_OUTPUT
ls_events-form = 'UPDATE_TOTALS'.
MODIFY lt_events INDEX sy-tabix FROM ls_events.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
          i_callback_program      = 'ZTEST'
          it_fieldcat             = lt_fieldcat
          it_events               = lt_events
     TABLES
          t_outtab                = lt_data
     EXCEPTIONS
          program_error           = 1
          OTHERS                  = 2.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.


*---------------------------------------------------------------------*
*       FORM update_totals                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  IV_LINEINFO                                                   *
*---------------------------------------------------------------------*
FORM update_totals USING iv_lineinfo TYPE slis_lineinfo.
  BREAK-POINT.
ENDFORM.


The BREAK-POINT is never reached. Any ideas?
Oscar.
ocvantol
 
Posts: 929
Joined: Tue Oct 22, 2002 3:19 am
Location: The Hague

Postby Guest » Wed Dec 07, 2005 6:30 am

I have debugged my butt of and looked at Form PBO in LSLVC_FULLSCREENF01. It looks like event 'BEFORE_LINE_OUTPUT' is not handled at all.

That can't be right, so I am wrong. Anyone care to tell me what I am missing here?
Guest
 

Next

Return to ABAP

Who is online

Users browsing this forum: Google Adsense [Bot] and 9 guests





This website is not affiliated with, sponsored by, or approved by SAP AG.