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

SAP SCRIPTS - TOTALS

Former Member
0 Likes
1,360

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

13 REPLIES 13
Read only

Former Member
0 Likes
1,323

This usually indicates that something is not getting cleared. I think you need to clear value1, maybe in initialization?

Read only

0 Likes
1,323

You variable is defined as STATIC. You will have to clear it somewhere.

Read only

Former Member
0 Likes
1,323

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.

Read only

Former Member
0 Likes
1,323

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.

Read only

Former Member
0 Likes
1,323

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

Read only

Former Member
0 Likes
1,323

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

Read only

0 Likes
1,323

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

Read only

Former Member
0 Likes
1,323

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

Read only

Former Member
0 Likes
1,323

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

Read only

0 Likes
1,323

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

Read only

0 Likes
1,323

Syed,

Can you please paste the part of code where it calls the particular form.

It is an interesting situation...

Regards

anurag

Read only

Former Member
0 Likes
1,323

Hi Syed,

Have you tried SUMMING control command in script for subtotal.

Thanks

Read only

Former Member
0 Likes
1,323

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