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 Help

rahul2000
Contributor
0 Likes
903

Dear all,

In ALV Report ,can we add values immediately after sorting.We can add the values of a column entirely

but is it possible to do after sorting

eg:-i got 10 materials output in an alv report.this 10 materials can be used more than once in an year like used in jan

feb march...(this field is the quantity)

similary for other materials.

Now is it possible to summ up the quantity on the basis of material?

As in after one material it should show me the addition of its usage ,then for the other

material and so on.

plz help

6 REPLIES 6
Read only

former_member194152
Contributor
0 Likes
814

Hi,

In ALV ther is a tool in stndard tool bar name subtotal u can use this utility for use this first sor the ALV list and then click on desired column and press subtotal button it will give result of all arithmatic subtotal for selected col.

Regards

Gagan

Read only

Former Member
0 Likes
814

hai rahul when ur adding the data instead of append data: use collect for those material and final data u will ge the result exactly.ok..

Read only

rahul2000
Contributor
0 Likes
814

Dear Gagan,

How can i do the same through coding as the user would not want to do the above process

over and over again.so the moment the code is executed ,subtotal should be displayed

Read only

Former Member
0 Likes
814

You can first sort the internal table by material in the sort strture of alv, using slis_sortinfo_alv,

slis_t_sortinfo_alv.

And the if you need to find the subtoatlling of quantity then you must do this way..

wa_fieldcat-tabname = 'T_FINAL'.

wa_fieldcat-fieldname = quantity.

wa_fieldcat-col_pos = 3.

wa_fieldcat-seltext_l = qty.

wa_fieldcat-do_sum = 'X'.

wa_fieldcat-outputlen = 14.

APPEND wa_fieldcat TO t_fieldcat.

CLEAR wa_fieldcat.

The above changes needs to be done in the fieldcatalog.

The field do_dum would subtotal the quantity field that you pass here.

try the above method.

Reward if useful.

Reply back if you need further help!!

null

Read only

former_member386202
Active Contributor
0 Likes
814

Hi,

Refer this code

&----


*& Form sub_display_data

&----


  • text

----


FORM sub_display_data .

*--To sort the output through material number

DATA : lwa_sort TYPE slis_sortinfo_alv.

DATA : lit_sort TYPE slis_t_sortinfo_alv.

*--Pass the values to the table

lwa_sort-fieldname = 'PERNR'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '1'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = 'X'. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WORKDATE'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '2'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

*--Pass the values to the table

lwa_sort-fieldname = 'WEKLY'. "Field name in o/p inttable

lwa_sort-tabname = 'it_final2'. "Output Internal table

lwa_sort-spos = '3'. "Sort sequence

lwa_sort-up = 'X'. "Sort in ascending order

lwa_sort-down = ' '. "Sort in descending order

lwa_sort-subtot = ' '. "Subtotal

APPEND lwa_sort TO lit_sort.

wa_layout-colwidth_optimize = 'X'.

IF NOT it_final2[] IS INITIAL.

*--Call the function module to display the ALV report

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = wa_layout

i_callback_program = v_repid

it_fieldcat = it_fieldcat1[]

i_default = c_chk

i_save = c_save

it_sort = lit_sort

TABLES

t_outtab = it_final2

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.

ELSE.

*--Message No data found

MESSAGE i888 WITH text-017.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " sub_display_data

Regards,

Prashant

Read only

Former Member
0 Likes
814

Hi Rahul,

i will develop a small code for u.Actually i dont know what are the fields to be taken for ur question.Thats why i have to take some other fields ok. we have to change those fields and table ok.

Note : we have make subtotals for only 'QUAN' type fields only.keep this thing in ur mind.

observe the form 'FIELD_CATALOG' for filed netwr.(ur problem will solve)

If u r satisfy with this answer plz give me Reward points.

plz copy the below code and execute the code.

code:

-


----


  • Type Pools

----


TYPE-POOLS:slis.

----


  • Tables

----


TABLES: vbak,vbap.

----


  • Global Variable

----


data: w_var type i.

----


  • Global Data

----


DATA:it_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv,

it_sortcat TYPE slis_t_sortinfo_alv,

wa_sortcat LIKE LINE OF it_sortcat.

----


  • Internal Table

----


data: BEGIN OF it_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 it_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.

&----


*& 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

----


  • Start Of Selection

----


START-OF-SELECTION.

PERFORM field_catalog. "For Structure Creation

PERFORM fetch_data. "Get the Data From DB Table

PERFORM sorting USING it_sortcat.

----


  • End Of Selection

----


END-OF-SELECTION.

perform display_data.

&----


*& Form field_catalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form field_catalog .

wa_fieldcat-col_pos = w_var. " Column Position Variable

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

wa_fieldcat-fieldname = 'VBELN'. " Field Name

wa_fieldcat-key = 'X'. " Blue Color

wa_fieldcat-ref_tabname = 'VBAK'. " Table Name

wa_fieldcat-ref_fieldname = 'VBELN'. " Field Name

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

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ADD 1 TO w_var.

wa_fieldcat-col_pos = w_var. " Column Position Variable

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

wa_fieldcat-fieldname = 'POSNR'. " Field Name

wa_fieldcat-ref_tabname = 'VBAP'. " Table Name

wa_fieldcat-ref_fieldname = 'POSNR'. " Field Name

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

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ADD 1 TO w_var.

wa_fieldcat-col_pos = w_var. " Column Position Variable

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

wa_fieldcat-fieldname = 'NETWR'. " Field Name

wa_fieldcat-ref_tabname = 'VBAP'. " Table Name

wa_fieldcat-ref_fieldname = 'NETWR'. " Field Name

wa_fieldcat-do_sum = 'X'. " Sum

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

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ADD 1 TO w_var.

endform. " field_catalog

&----


*& Form sorting

&----


  • text

----


  • -->P_IT_SORTCAT text

----


form sorting using p_it_sortcat TYPE slis_t_sortinfo_alv.

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 = it_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = it_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 = it_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 .

select a~vbeln

posnr

b~netwr

from vbak as a

inner join vbap as b on avbeln = bvbeln

into table it_salesorder

where a~vbeln in s_vbeln.

endform. " fetch_data

-