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

problem with alv total & subtotal

Former Member
0 Likes
860

hi gurus,

i have problem with alv total & subtotal as below.

example:

column A column B column C

at row subtotal or total, system will display total for column A & B but in column C, system should use formula A/B. Izzit possible to do that for ALV report?

THANK YOU IN ADVANCE

hi gurus,

i have problem with alv total & subtotal as below.

example:

column A column B column C

at row subtotal or total, system will display total for column A & B but in column C, system should use formula A/B. Izzit possible to do that for ALV report?

THANK YOU IN ADVANCE

6 REPLIES 6
Read only

SantoshKallem
Active Contributor
0 Likes
803

SAMPLE PROGRAM:

REPORT ysalesorder_alv_subtotals.

-


  • Type Pools

-


TYPE-POOLS:slis.

-


  • Tables

-


TABLES: vbak, "Sales Document: Header Data

vbap. "Sales Document: Item Data

-


  • Global Structures

-


DATA:gt_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv,

gt_sortcat TYPE slis_t_sortinfo_alv,

wa_sortcat LIKE LINE OF gt_sortcat.

-


  • Internal Table

-


DATA: BEGIN OF gt_salesorder OCCURS 0,

vbeln LIKE vbak-vbeln, " Sales Document Number

posnr LIKE vbap-posnr, " Sales Doc Item

netwr LIKE vbap-netwr, " Net Value

END OF gt_salesorder.

-


  • SELECT OPTIONS

-


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME

TITLE text-001.

SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. " Sales Document

Number.

SELECTION-SCREEN END OF BLOCK b1.

-


  • Initialization

-


INITIALIZATION.

PERFORM initialization.

-


  • Start Of Selection

-


START-OF-SELECTION.

PERFORM field_catalog. "For Structure Creation

PERFORM fetch_data. "Get the Data From DB Table

PERFORM sorting USING gt_sortcat.

-


  • End Of Selection

-


END-OF-SELECTION.

PERFORM display_data.

&----


*& Form initialization

&----


  • text

-


  • --> p1 text

  • <-- p2 text

-


FORM initialization .

s_vbeln-sign = 'I'.

s_vbeln-option = 'BT'.

s_vbeln-low = '4969'.

s_vbeln-high = '5000'.

APPEND s_vbeln.

ENDFORM. " initialization

&----


*& Form field_catalog

&----


  • text

-


  • --> p1 text

  • <-- p2 text

-


FORM field_catalog .

REFRESH : gt_fieldcat.

CLEAR : wa_fieldcat.

wa_fieldcat-col_pos = '1'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table

wa_fieldcat-fieldname = 'VBELN'. "Field Name

wa_fieldcat-key = 'X'. "Blue Color

wa_fieldcat-seltext_m = 'Sales Doc No'. "Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = '2'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table Name

wa_fieldcat-fieldname = 'POSNR'. "Field Name

wa_fieldcat-seltext_m = 'Sales Doc Item'."Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

*SubTotal on the Field NETWR

wa_fieldcat-col_pos = '3'. "Column Position

wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table

wa_fieldcat-fieldname = 'NETWR'. "Field Name

wa_fieldcat-do_sum = 'X'. "Sum

wa_fieldcat-seltext_m = 'Net Value'. "Display Text In Screen

APPEND wa_fieldcat TO gt_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " field_catalog

&----


*& Form sorting

&----


  • text

-


  • -->P_IT_SORTCAT text

-


FORM sorting USING p_it_sortcat TYPE slis_t_sortinfo_alv.

CLEAR wa_sortcat.

wa_sortcat-fieldname = 'VBELN'.

wa_sortcat-up ='X'.

wa_sortcat-subtot = 'X'.

APPEND wa_sortcat TO p_it_sortcat.

ENDFORM. " sorting

&----


*& Form display_data

&----


  • text

-


  • --> p1 text

  • <-- p2 text

-


FORM display_data .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = sy-repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

  • IS_LAYOUT =

it_fieldcat = gt_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

it_sort = gt_sortcat

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = gt_salesorder

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.

ENDFORM. " display_data

&----


*& Form fetch_data

&----


  • text

-


  • --> p1 text

  • <-- p2 text

-


FORM fetch_data .

REFRESH : gt_salesorder.

CLEAR : gt_salesorder.

SELECT a~vbeln

posnr

b~netwr

FROM vbak AS a

INNER JOIN vbap AS b ON avbeln = bvbeln

INTO TABLE gt_salesorder

WHERE a~vbeln IN s_vbeln.

ENDFORM. " fetch_data

regards.

santhosh reddy

reward if useful

Read only

0 Likes
803

hi santosh,

i am quite new to abap especially in alv format report, can explain how the program works?

Read only

0 Likes
803

hi,

I have copied and paste your prog and found that the system only sum up all value for net value. My problem is the value in 3rd column total should be based on below formula.

3rd column = 2nd column total / 1st column total

Read only

0 Likes
803

Hi,

This can't be achieved in ALV. You need to do the calculations beforehand in internal table only.

Regards,

Atish

Read only

Former Member
0 Likes
803

I've just faced this issue yesterday.

u can try to use event before_line_output . i've got the solution from www.sapfans.com

the code below might solve you problem.


  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = gtt_events
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.

  LOOP AT gtt_events INTO gwa_events.
    CASE gwa_events-name.
      WHEN slis_ev_before_line_output.
        gwa_events-form = slis_ev_before_line_output.
    ENDCASE.
    MODIFY gtt_events FROM gwa_events TRANSPORTING form.
  ENDLOOP.


FORM before_line_output USING rs_lineinfo TYPE slis_lineinfo..


       .......your calculation.......



ENDFORM."BEFORE_LINE_OUTPUT

please reward if it work.

Read only

Former Member
0 Likes
803

one thing that i forget to mention u.

the output internal table in alv_list should use variable with header line for example gt_alv .... with header line

and in the FORM before_line_output just only use gt_alv and no need to modify the internal table (actually i've tried to modify the internal table but got short dump.)