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: 

ITAB - sub totals?

Former Member
0 Kudos
66

Hi Experts,

For some reasons, I need to calculate the subtotals as well as grand total in an

INTERNAL TABLE.

So, am using AT NEW / AT END and SUM operations and inserting the record by catching sy-tabix. Some how working well, but taking lengthy coding!

So,

Do, We hv any ready-made feature to get the sub totals in ITAB?

thanq.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
40

See the simple example about totals and sub totals

&----


*& Report ZTEST_IEVENTS

*&

&----


*&

*&

&----


REPORT ZTEST_IEVENTS no standard page heading

line-count 40(2).

tables : vbap.

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

data wa_vbap like line of i_vbap.

data v_flag type c.

select-options s_vbeln for vbap-vbeln obligatory.

start-of-selection.

select vbeln

posnr

matnr

kwmeng

netpr from vbap

into table i_vbap

where vbeln in s_vbeln.

sort i_vbap by vbeln posnr.

end-of-selection.

loop at i_vbap.

move i_vbap to wa_vbap.

at first.

write:/2 'Order #',15 'Item #',28 'Material #',50 'Qty', 70 'Net value'.

skip 1.

endat.

at new vbeln.

write:/2 wa_vbap-vbeln,15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

v_flag = 'X'.

endat.

if v_flag ne 'X'.

write:/15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

endif.

at end of vbeln.

sum.

skip 1.

write:/5 'Sub totals', 47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

endat.

at last .

skip 1.

sum.

write:/5 'Grand Totals',47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

write:/ 'end of page', 'Footer'.

endat.

clear v_flag.

endloop.

Thanks

Seshu

4 REPLIES 4

Former Member
0 Kudos
41

See the simple example about totals and sub totals

&----


*& Report ZTEST_IEVENTS

*&

&----


*&

*&

&----


REPORT ZTEST_IEVENTS no standard page heading

line-count 40(2).

tables : vbap.

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

data wa_vbap like line of i_vbap.

data v_flag type c.

select-options s_vbeln for vbap-vbeln obligatory.

start-of-selection.

select vbeln

posnr

matnr

kwmeng

netpr from vbap

into table i_vbap

where vbeln in s_vbeln.

sort i_vbap by vbeln posnr.

end-of-selection.

loop at i_vbap.

move i_vbap to wa_vbap.

at first.

write:/2 'Order #',15 'Item #',28 'Material #',50 'Qty', 70 'Net value'.

skip 1.

endat.

at new vbeln.

write:/2 wa_vbap-vbeln,15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

v_flag = 'X'.

endat.

if v_flag ne 'X'.

write:/15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

endif.

at end of vbeln.

sum.

skip 1.

write:/5 'Sub totals', 47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

endat.

at last .

skip 1.

sum.

write:/5 'Grand Totals',47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

write:/ 'end of page', 'Footer'.

endat.

clear v_flag.

endloop.

Thanks

Seshu

Former Member
0 Kudos
40

If you use ALV to display the itab contents, this is provided to you with minimal coding.

Former Member
0 Kudos
40

Hi Srikhar,

What kind of program you are developing?

If this is classical report then the approach you have taken is correct, and we don't have any readymade fetaure.

if this is an ALV then no need to do anything. It has standard functionality by which you can calculate total.

Regards,

Atish

0 Kudos
40

ThanQ Sarda,

OK; am talking abt classical report.

thanq.