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: 

Event

Former Member
0 Kudos
101

Hi Guru's,

Please check below program,

It is calculating total values for amount field but it is not calculating for number field. both i gave it in event itself (at end of name).

Please help me in solving this problem.

TYPES:BEGIN OF itab,

num TYPE i,

name(10) TYPE c,

amt type i,

END OF itab.

DATA : wa_itab TYPE itab,

it_itab TYPE STANDARD TABLE OF itab.

DATA : v_lines TYPE i.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 1000.

append wa_itab TO it_itab.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 2000.

append wa_itab TO it_itab.

wa_itab-num = 1.

wa_itab-name = 'nag'.

wa_itab-amt = 1500.

append wa_itab TO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 500.

append wa_itab tO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 600.

append wa_itab TO it_itab.

wa_itab-num = 2.

wa_itab-name = 'sri'.

wa_itab-amt = 700.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1200.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1300.

append wa_itab TO it_itab.

wa_itab-num = 3.

wa_itab-name = 'ganesh'.

wa_itab-amt = 1400.

append wa_itab TO it_itab.

wa_itab-num = 4.

wa_itab-name = 'suresh'.

wa_itab-amt = 900.

append wa_itab TO it_itab.

wa_itab-num = 4.

wa_itab-name = 'suresh'.

wa_itab-amt = 300.

append wa_itab TO it_itab.

sort it_itab by name.

LOOP AT it_itab INTO wa_itab.

at first.

write 😕 'details of sales order:'.

uline.

endat.

at new num.

write 😕 'serial num:', wa_itab-num.

uline.

endat.

WRITE 😕 wa_itab-num , wa_itab-name , wa_itab-amt.

at end of name.

uline.

sum.

write 😕 'total amount:',wa_itab-amt.

write 😕 'serial num:', wa_itab-num.

uline.

endat.

*

at last.

sum.

uline.

write:/ 'grand total:',wa_itab-amt.

endat.

ENDLOOP.

Thanks & Regards

Priyalatha

1 ACCEPTED SOLUTION

asik_shameem
Active Contributor
0 Kudos
76

Hi,

just change the position of num in itab as follow

TYPES:BEGIN OF itab,

<b>name(10) TYPE c,

num TYPE i,

amt type i,</b>

END OF itab.

it will work.

6 REPLIES 6

Former Member
0 Kudos
76

Hi

check with tis code

&----


*& Report ZALV_SUM

*&

&----


*&

*&

&----


REPORT ZNNR_ALV_SUM.

TABLES: ekko.

type-pools: slis. "ALV Declarations

*Data Declaration

*----


TYPES: BEGIN OF t_vbap,

vbeln TYPE vbap-vbeln,

matnr TYPE vbap-matnr,

netwr TYPE vbap-netwr,

waerk TYPE vbap-waerk,

END OF t_vbap.

DATA: it_vbap TYPE STANDARD TABLE OF t_vbap INITIAL SIZE 0,

wa_vbap TYPE t_vbap.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

perform display_alv_report.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

fieldcatalog-fieldname = 'VBELN'.

fieldcatalog-seltext_m = 'Sales Order'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'X'.

fieldcatalog-key = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material Number'.

fieldcatalog-col_pos = 4.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NETWR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-do_sum = 'X'. "Display column total

fieldcatalog-cfieldname = 'WAERK'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'WAERK'.

fieldcatalog-seltext_m = 'Price Curr'.

fieldcatalog-col_pos = 8.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

endform. " BUILD_LAYOUT

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

  • i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

  • i_callback_user_command = 'USER_COMMAND'

  • i_grid_title = outtext

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

  • it_special_groups = gd_tabgroup

  • IT_EVENTS = GT_XEVENTS

i_save = 'X'

  • is_variant = z_template

tables

t_outtab = it_vbap

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_ALV_REPORT

&----


*& Form DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

select vbeln matnr netwr waerk

up to 50 rows

from vbap

into table it_vbap.

endform. " DATA_RETRIEVAL

Reward if usefull

0 Kudos
76

Hi naresh,

can u tel me with respect to my prog?

Regards,

Priya

Former Member
0 Kudos
76

Hi,

It won't sum the number field. The smount field is summing as the number is changing. The number is a unique field, it won't sum up.

Ex:

1 Ram 1000

1 Ram 2000

2 tej 1000

Number 1 is unique to Ram only .(1+1 = 2 is wrong ). Eventhough any one of 1's and 2's be there, a unique entry will be there are all similar records.

like

1 Ram 3000.

2 Tej 1000.

Regards,

Vani

0 Kudos
76

Hi vani,

Please see the code once again,it is adding amount field when name gets changes,

so

at end of name. "plz check this.

uline.

sum.

write 😕 'total amount:',wa_itab-amt."its adding the values for this field

write 😕 'serial num:', wa_itab-num. "it shd work for this field also.

uline.

endat.

Thanks & regards

Priyalatha

asik_shameem
Active Contributor
0 Kudos
77

Hi,

just change the position of num in itab as follow

TYPES:BEGIN OF itab,

<b>name(10) TYPE c,

num TYPE i,

amt type i,</b>

END OF itab.

it will work.

0 Kudos
76

Thank you very much shameen,