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

Report general

Former Member
0 Likes
618

Hi experts,

I have a requirement that i have to display sum of all the fields of a database table into report. There is a database table zstock1 which contains all the data of Yarn and chemical. It shows montly stock of both yarn and chemical. it was my earlier requiment to insert internal table values into database table so i hv done it and inserted all the internal table values it_totstk1 into ZStock1. ( This format is 1st format showing company address and all the internal table data)

Now i have requiement that i have to show another format in the same report by selection radiobuttons if i select 1st radio button it should show all the internal table records. If i select 2nd radio button the values which are inserted in the Zstock1 which is database table i should display their sum in the second format with different company address.

I have taken one internal table in which i hv written the select stament but the prob is it is not taking any of the values in the intrenal table... i am unable to understand whr is the problem below is my source code which i hav written.... please help me ...

IF R2 = 'X'.

SELECT MATNR SUM( sexbas ) SUM( sexbed ) SUM( sexaddtax1 )

SUM( pmenge ) SUM( sfkimg ) SUM( defkimg ) SUM( cpimenge )

SUM( brwtr ) SUM( cpiexbas )

into CORRESPONDING FIELDS OF TABLE IT_SUM

FROM zstock1

WHERE MATNR EQ S_MATNR

GROUP BY MATNR.

LOOP AT IT_SUM.

write:/ 14 IT_SUM-matnr,

45 IT_SUM-pmenge,

70 IT_SUM-sfkimg,

120 IT_SUM-sexbas,

130 IT_SUM-sexbed,

145 it_SUM-sexaddtax1.

endloop.

ENDIF.

S_matnr is my selection sceen input field . And i need to display other fields rather than it_sum. like j_1imtchid-j_1ichid, UOQ ( units of quantity ) in between the fields.

<b>useful answers rewarded</b>

regards,

sunil kumar.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
575

Hi

Use the Control break statements like AT NEW and AT END OF to get this sums

take the data into ITAB first

then SORT it by MATNR then use these events

SELECT MATNR

sexbas sexbed sexaddtax1 pmenge sfkimg defkimg cpimenge

brwtr cpiexbas

into CORRESPONDING FIELDS OF TABLE IT_SUM

FROM zstock1

WHERE MATNR EQ S_MATNR.

sort it_sum by MATNR.

LOOP AT IT_SUM.

at end of matnr.

SUM.

read table it_sum index sy-tabix.

write:/ 14 IT_SUM-matnr,

45 IT_SUM-pmenge,

70 IT_SUM-sfkimg,

120 IT_SUM-sexbas,

130 IT_SUM-sexbed,

145 it_SUM-sexaddtax1.

ENDAT.

endloop.

see the doc

All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

Some time you will get * when moving data from this int table to other table using these commands

so you have to use

READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

sort sflight by carrid connid.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

Reward if useful

Anji

3 REPLIES 3
Read only

Former Member
0 Likes
576

Hi

Use the Control break statements like AT NEW and AT END OF to get this sums

take the data into ITAB first

then SORT it by MATNR then use these events

SELECT MATNR

sexbas sexbed sexaddtax1 pmenge sfkimg defkimg cpimenge

brwtr cpiexbas

into CORRESPONDING FIELDS OF TABLE IT_SUM

FROM zstock1

WHERE MATNR EQ S_MATNR.

sort it_sum by MATNR.

LOOP AT IT_SUM.

at end of matnr.

SUM.

read table it_sum index sy-tabix.

write:/ 14 IT_SUM-matnr,

45 IT_SUM-pmenge,

70 IT_SUM-sfkimg,

120 IT_SUM-sexbas,

130 IT_SUM-sexbed,

145 it_SUM-sexaddtax1.

ENDAT.

endloop.

see the doc

All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

Some time you will get * when moving data from this int table to other table using these commands

so you have to use

READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

sort sflight by carrid connid.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

Reward if useful

Anji

Read only

0 Likes
575

Hi anji,

Thankx for your fast reply. I have understood your answer but I never used control break statements earlier. I have some dbt please clear it…

WRITE: /'|', 'CETSH ' LEFT-JUSTIFIED,

<b>14 'Description of ',</b>

36 'UOQ',

<b> 45 'QTY ',</b>

55' QTY CLR ',

70 'QTY',

<b> 85 'ASSESSABLE VALUE',</b>

105 'Notfn ',

120 'sr',

130 'Rate of Duty',

<b> 145 'CENVAT',</b>

<b>160 'E.CESS '</b>,

<b> 175 'SH CESS',</b>

<b> 190 'TOTAL',</b>

210 'PROVASSMT',219'|'.

WRITE: / '|', 5 'NO',

<b> 20'Goods',</b>

45'MFG.',

58 'Type',

70'CLEARED',

93'Rs.',

105'Availed',

120'nofn',

<b> 134' %',

148'Rs.',

160'Rs.(2%)',

175'Rs. (1%)',

193'Rs.',</b> 217 '.',219'|'.

Above is my header of the table in which the heading in bold are form Zstock1. Remaining are from different tables.

There is already data in the Zstock1 and I need to take some fields and do the sum of that fields and display that the fields are are in my earlier posted question.

So in Zstock1

I am taking some fields such as… sexbas

sexbed

sexaddtax1

pmenge

sfkimg

defkimg

cpimenge

brwtr

cpiexbas . For this fields only I need sum. How to use Control break statement for this and hw to display in the output? And I want other fields to display in between hw to do that…. Please help me.. pleae give me syntax i ll work it out............

thanks & Regards,

sunil kumar.

Read only

0 Likes
575

Hi Anji,

I have written the code as u said . first i have taken all the values in the internal table it_sum using the statment

select matnr sexbas sexbed sexaddtax1 pmenge sfkimg defkimg cpimenge

brwtr cpiexbas from zstock1 into corresponding fields of table it_sum

where matnr in s_matnr.

then written the following code after it.

sort it_sum by MATNR.

LOOP AT IT_SUM.

At end of matnr.

SUM.

read table it_sum index sy-tabix.

write:/14 IT_SUM-matnr,

45 IT_SUM-pmenge,

70 IT_SUM-sfkimg,

120 IT_SUM-sexbas,

130 IT_SUM-sexbed,

145 it_SUM-sexaddtax1.

ENDAT.

endloop.

But the problem is it is showing only one record i.e last record in the internal table it is not getting added. What may be the problem??

Regards,

Sunil kumar.