‎2006 Aug 10 7:17 PM
Hi Everyone i am using this logic to write the subtotal and total in the script, i am doing the total for the quantity field and writing the perform in main window.
The problem is the first time iam getting correct values but once i go back(not to the transaction but to select the ouptut type and again see the print preview its adding the previous total as well), if i run the transaction from the start thier is no problem.
i am giving the code as well.
FORM GET_TOTAL TABLES INPAR STRUCTURE ITCSY
OUTPAR STRUCTURE ITCSY.
DATA : P_EBELN2 LIKE EKKO-EBELN,
P_TOTAL LIKE EKPO-KTMNG,
P_TOT(13),
value type ktmng.
STATICS VALUE1 TYPE KTMNG.
CLEAR INPAR.
clear value1.
CLEAR VALUE.
READ TABLE INPAR INDEX 1.
MOVE INPAR-VALUE TO value.
value1 = value1 + value.
move value1 to p_tot.
*clear value1.
CLEAR OUTPAR.
READ TABLE OUTPAR INDEX 1.
MOVE p_tot TO OUTPAR-VALUE.
MODIFY OUTPAR INDEX SY-TABIX.
CLEAR P_TOT.
ENDFORM.
Thanks & Regards
Syed
‎2006 Aug 10 7:19 PM
This usually indicates that something is not getting cleared. I think you need to clear value1, maybe in initialization?
‎2006 Aug 10 7:21 PM
You variable is defined as STATIC. You will have to clear it somewhere.
‎2006 Aug 10 7:23 PM
hi syed,
just try im not sure...
comment these 2 lines.
FORM GET_TOTAL TABLES INPAR STRUCTURE ITCSY
OUTPAR STRUCTURE ITCSY.
DATA : P_EBELN2 LIKE EKKO-EBELN,
P_TOTAL LIKE EKPO-KTMNG,
P_TOT(13),
value type ktmng.
STATICS VALUE1 TYPE KTMNG.
<b>*CLEAR INPAR.</b>
clear value1.
CLEAR VALUE.
READ TABLE INPAR INDEX 1.
MOVE INPAR-VALUE TO value.
value1 = value1 + value.
move value1 to p_tot.
*clear value1.
<b>*CLEAR OUTPAR.</b>
READ TABLE OUTPAR INDEX 1.
MOVE p_tot TO OUTPAR-VALUE.
MODIFY OUTPAR INDEX SY-TABIX.
CLEAR P_TOT.
ENDFORM.
‎2006 Aug 10 7:25 PM
Hi syed,
the value stored in value1 is getting added to value when the perform is called for the secons time.
clear value1 and also value.
clear value1.
clear value.
in the subroutine.
regards,
keerthi.
‎2006 Aug 10 7:27 PM
Hi Syed,
STATIC values will preseve the value so you are getting the preserved value and this value to is again calculated so clear this value before processing for the next time.
For this just add a CLEAR VALUE1 statement in your code.
CLEAR INPAR.
clear value1.
CLEAR VALUE.
<b>CLEAR VALUE1.</b>
READ TABLE INPAR INDEX 1.
MOVE INPAR-VALUE TO value.
value1 = value1 + value.
Thanks,
Vinay
‎2006 Aug 11 11:32 AM
HI EVERYONE THANKS ALL OF U FOR YOUR ADVICE , BUT STILL THE PROBLEM IS NOT SOLVED . I CANNOT CLEAR VALUE1 IN THE SUBROUTINE AS IT WILL NOT ADD THE OTHER VALUES. IS THEIR ANY OTHER LOGIC FOR THIS ONE.
THANKS & REGARDS SYED
‎2006 Aug 11 12:53 PM
Hello Syed.
I would you to please try the below logic
CLEAR INPAR.
CLEAR VALUE.
READ TABLE INPAR INDEX 1.
MOVE INPAR-VALUE TO value.
CLEAR OUTPAR.
READ TABLE OUTPAR INDEX 1.
MOVE OUTPAR-VALUE to p_tot.
p_tot = p_tot + value.
CLEAR OUTPAR.
READ TABLE OUTPAR INDEX 1.
MOVE p_tot TO OUTPAR-VALUE.
MODIFY OUTPAR INDEX SY-TABIX.
CLEAR P_TOT.
Regards
Anurag
‎2006 Aug 11 11:39 AM
Hi Syed,
Chk the following link.It might solve your problem.
http://www.sap-img.com/sapscripts/sapscript-how-to-calculate-totals-and-subtotals.htm
Reward points,if helpful.
Regards,
Harini.S
‎2006 Aug 11 6:20 PM
Hi , Anurag n others
thanks for ur valuable advice but the code is not working , do u have any other logic for this as i don't have access to the print program and i can't clear the value in the subroutine.
thanks & regards
Syed
‎2006 Aug 11 7:21 PM
HI Syed,
I think the static variables can change the values within a routine. when u r out of routine then the variable has the initial value what u have assignned.
so when the select statement for second time then it uses the previous value also.
remove the keyword static... and try...
otherwise place a select statement in routine.
hope this helps
Regards
‎2006 Aug 11 7:59 PM
Syed,
Can you please paste the part of code where it calls the particular form.
It is an interesting situation...
Regards
anurag
‎2006 Aug 11 8:31 PM
Hi Syed,
Have you tried SUMMING control command in script for subtotal.
Thanks
‎2006 Aug 11 9:30 PM
IH &EKPO-EBELP&,,&EKPO-MATNR&,,&EKPO-TXZ01&,,&EKPO-KTMNG&,,&EKPO-MEINS&,,
= &XDAT&
/* DEFINE &XEBEL& = &EKPO-EBELN&
/: DEFINE &XTOT& = &EKPO-KTMNG&
/: DEFINE &XTOTAL& = &EKPO-KTMNG&
/: PERFORM GET_TOTAL IN PROGRAM ZRMLONG1
/: USING &XTOT&
/: CHANGING &XTOTAL&
/: ENDPERFORM THIS IS THE CODE IN THE MAIN WINDOW AND IN THE THREAD U CAN SEE THE CODE FOR THE SUBROUTINE
THANKS & REGARDS
SYED