‎2007 Jan 08 10:39 AM
‎2007 Jan 08 10:41 AM
i don't think there is any command like sum in sapscript.
u have to write the logic of sum in driver program store value in a varaible and than print this variable to sapscript ex--&varablr&
‎2007 Jan 08 10:41 AM
Hi,
The SUMMING command is used for accumulating a total value for a program symbol. The command should be specified just once. Then, each time the specified program symbol is formatted, its current value is added into the total symbol. Several program symbols may all be added into a single total symbol.
Syntax:
/: SUMMING program_symbol INTO total_symbol
SAPscript cannot create the field for the total dynamically. The summing symbol used for totalling and the accompanying program symbol(s) must be declared with TABLES in the ABAP program. Otherwise, only zero is added. Declaring the symbol with the DATA statement is not sufficient (global data).
Chk the following link.
http://www.sap-img.com/sapscripts/sapscript-how-to-calculate-totals-and-subtotals.htm
‎2007 Jan 08 10:42 AM
To calculate totals and sub totals in sap scripts you have to use subroutines.
Say if you have to add the unit price (KOMVD-KBERT) then in the main window whereever tat value is picked write this routine
/: DEFINE &TOT_PRICE&
/: PERFORM F_GET_PRICE IN PROGRAM <subroutine prog name> /:USING &KOMVD-KBERT& /:CHANGING &TOT_PRICE& /:ENDPERFORM
Then write the variable where ever you want it to be printed (mostly it will be in footer window)
Then create subroutine pool program and you have to write the code.
FORM F_GET_PRICE tables int_cond structure itcsy
outt_cond structure itcsy. data : value type kbert.
statics value1 type kbert.
Read int_cond table index 1.
value = int_cond-value.
value1 = value1 + value.
Read outt_cond table index 1.
outt_cond-value = value1.
Modify outt_cond index 1.
ENDFORM.
<b> ( OR )</b>
You must place the carry forward amount on the current page into a window of type VAR. On the subsequent page, use a local text symbol to print the amount in the TOP area of the main window:
1. At the beginning of the form main text (before printing the first text element), define the amount variable and the total variable (both must be program symbols or Dictionary amount fields).
In the example below, we use the SUMMING command to determine that for each output of &SUMTAB-AMOUNT& the system automatically sums up the amount in the total variable &SUMTAB-TOTAL&. At the end of the page, &SUMTAB-TOTAL& contains the carry forward amount of the current page or the grand total, respectively.
In this example, we also define a local symbol &LASTPAGE& to print the grand total on the last page.
/: SUMMING &SUMTAB-AMOUNT& INTO &SUMTAB-TOTAL&
/: DEFINE &LASTPAGE& =
2. At the end of the form main text (when printing the last text element of the main window), set the local textsymbol &LASTPAGE& to a different value, such as X:
/: DEFINE &LASTPAGE& = X
3. To print the carry forward amount in the TOP area of the subsequent page including the pre-text 'Carry forward' and a tab, we use the local text symbol &CARRY. The corresponding text element is also defined in the main window:
/E CARRY
&Carry forward:,,CARRY&
(CALL FUNCTION WRITE_FORM EXPORTING ELEMENT = CARRY
TYPE = TOP)
4. Define the carry forward window on the current page as type VAR and position it at the end of the main window of the page. Print the carry forward amount there and define the local text symbol &CARRY& to print the amount again in the TOP area of the subsequent page. Use the local text symbol &LASTPAGE& to print the grand total on the last page. The carry forward window then contains the following text (define it as paragraph T1 with tab):
/: IF &LASTPAGE& = X
T1 <H>Grand total:,,&SUMTAB-TOTAL&</>
/: ELSE
T1 <H>Carry forward:,,&SUMTAB-TOTAL&</>
/: DEFINE &CARRY& = &SUMTAB-TOTAL&
/: ENDIF
‎2007 Jan 08 10:52 AM
HI,
hai
use --->summing &programsymbol& into &scriptsymbol&.
This <b>scriptsymbol</b> must be declared with TABLES in the ABAP Program, otherwise it will dispaly 0 in the total.
__________________________________________________________________
if you want to show independent values and the summation of those values then you need to code in your report program.
inside the loop.
loop at itab.
and for every individual value.
use start_form.
field_name.
end_form.
****for total value.
at end of field.
sum.
or
collect fieldname for summation.
store this total value in a global variable
and then pass it to your text element in script.
endat.
endloop.
Regards
Sudheer