cancel
Showing results for 
Search instead for 
Did you mean: 

Sum up a field in SAPScript

Former Member
0 Kudos

Hi,

I need to sum up a field - Gross Weight VBRP-BRGEW in SAPscript.

SELECT SINGLE * FROM vbrp WHERE vbeln = st_vbeln

AND posnr = konv-kposn.

MOVE VBRP-BRGEW TO V_TOTBRGEW.

V_GTOTBRGEW = V_GTOTBRGEW + V_TOTBRGEW.

MOVE 'V_GTOTBRGEW' TO output-name.

MOVE v_gtotbrgew TO output-value.

CONDENSE output-value.

APPEND output.

I have tried the above mention code for it in the driver program but not getting the output correctly.

Please help.

Thanks

Nishant Bhargava

Accepted Solutions (1)

Accepted Solutions (1)

former_member186055
Active Participant
0 Kudos

Hi Nishant,

In SAP-Script for every KONV-KPOSN you are calling Subroutinue pool program via Perform, when you call the program via perform value of V_GTOTBRGEW will be initial, only last value is there in V_GTOTBRGEW it is displaying last value instead of sum. To over come this you again need to pass V_GTOTBRGEW value for every KONV-KPOSN form SAP-Script to your program. This may solve your problem

Regards,

Surya

Former Member
0 Kudos

Please clarify more on this,

How to do this?

Thanks for ur reply

Regards,

Nishant

Edited by: Nishantbhargava on Nov 28, 2011 10:57 AM

former_member186055
Active Participant
0 Kudos

Nishant,

In your SAP-Script please post your code to call progranm via PERFORM so that i can able to help you.

/: PERFORM <SubroutinueName> IN PROGRAM <Program>
/: USING <var>
.
.
/: CHANGING <var>
/: ENDPERFORM

Regards,

Surya

Former Member
0 Kudos

Hi,

I have written the code in the sapscript form

PERFORM Z_TOT_WEIGHT IN PROGRAM ZVRINC01

USING &ST_VBELN&

USING &ST_KPOSN&

CHANGING &V_GTOTBRGEW&

ENDPERFORM

ANd written the following code in driver program ZVRINC01

FORM Z_TOT_WEIGHT

TABLES input STRUCTURE itcsy

output STRUCTURE itcsy.

*

DATA: st_vbeln LIKE vbrp-vbeln,

st_kposn LIKE konv-kposn VALUE 0,

v_gtotbrgew LIKE vbrp-brgew value 0.

REFRESH output.

CLEAR output.

READ TABLE input INDEX 1.

MOVE input-value TO st_vbeln.

REFRESH output.

CLEAR output.

READ TABLE input INDEX 2.

MOVE input-value TO st_kposn.

endform.

Regards,

Nishant

Edited by: Nishantbhargava on Nov 28, 2011 11:29 AM

former_member186055
Active Participant
0 Kudos

Nishant,

Please try as mentioned below,

/: PERFORM Z_TOT_WEIGHT IN PROGRAM ZVRINC01
/: USING &ST_VBELN&
/: USING &ST_KPOSN&
/: USING &V_GTOTBRGEW&
/: CHANGING &V_GTOTBRGEW&
/: ENDPERFORM

Add below statement in your program,

READ TABLE INPUT INTO INPUT WITH KEY NAME = 'V_GTOTBRGEW'.
MOVE INPUT-VALUE to V_GTOTBRGEW.

MOVE VBRP-BRGEW TO V_TOTBRGEW.
V_GTOTBRGEW = V_GTOTBRGEW + V_TOTBRGEW.

This may solve your problem.

Regards,

Surya

Former Member
0 Kudos

Still not working

SELECT SINGLE * FROM vbrp WHERE vbeln = st_vbeln

AND posnr = konv-kposn.

MOVE VBRP-BRGEW TO V_TOTBRGEW.

READ TABLE INPUT INTO INPUT WITH KEY NAME = 'V_GTOTBRGEW'.

MOVE INPUT-VALUE to V_GTOTBRGEW.

V_GTOTBRGEW = V_GTOTBRGEW + V_TOTBRGEW.

MOVE 'V_GTOTBRGEW' TO output-name.

MOVE v_gtotbrgew TO output-value.

CONDENSE output-value.

APPEND output.

Regards,

Nishant

Edited by: Nishantbhargava on Nov 28, 2011 11:48 AM

Edited by: Nishantbhargava on Nov 28, 2011 11:50 AM

former_member186055
Active Participant
0 Kudos

Nishant,

Use your same form Z_TOT_WEIGHT as below,

/: PERFORM Z_TOT_WEIGHT IN PROGRAM ZVRINC01
/: USING &ST_VBELN&
/: USING &ST_KPOSN&
/: USING &V_GTOTBRGEW&      " Add this line of code in SAP-Script
/: CHANGING &V_GTOTBRGEW&
/: ENDPERFORM

REFRESH output.
 CLEAR output.
 READ TABLE input INDEX 1.
 MOVE input-value TO st_vbeln.
 

REFRESH output.
 CLEAR output.
 READ TABLE input INDEX 2.
 MOVE input-value TO st_kposn.

REFRESH output.
 CLEAR output.
READ TABLE INPUT INTO INPUT WITH KEY NAME = 'V_GTOTBRGEW'. " This line of code in program
MOVE INPUT-VALUE to V_GTOTBRGEW.                          " This line of code also
 

endform.

MOVE VBRP-BRGEW TO V_TOTBRGEW.
 V_GTOTBRGEW = V_GTOTBRGEW + V_TOTBRGEW.

MOVE 'V_GTOTBRGEW' TO output-name.
 MOVE v_gtotbrgew TO output-value.
 CONDENSE output-value.
 APPEND output.

Regards,

Surya

Former Member
0 Kudos

its coming blank - no value in V_GTOTBRGEW

former_member186055
Active Participant
0 Kudos

Nishant,

SELECT SINGLE * FROM vbrp WHERE vbeln = st_vbeln
 AND posnr = konv-kposn.
 
MOVE VBRP-BRGEW TO V_TOTBRGEW.
 V_GTOTBRGEW = V_GTOTBRGEW + V_TOTBRGEW.
 
MOVE 'V_GTOTBRGEW' TO output-name.
 MOVE v_gtotbrgew TO output-value.
 CONDENSE output-value.
 APPEND output.

Add this code also in form same form Z_TOT_WEIGHT.

Regards,

Surya

Former Member
0 Kudos

Value is coming but not the correct value, its coming 613.400

while my values are :-

13.600

16.000

13.600

6.800

16.000

3.200

10.00

1.800

5.400

15.600

0.200

sum should be - 102.200

former_member186055
Active Participant
0 Kudos

Nishant,

Comment below line of code and let me know.

MOVE INPUT-VALUE to V_GTOTBRGEW.

Regards,

Surya

Former Member
0 Kudos

Now its showing the last value only i.e 0.200

former_member186055
Active Participant
0 Kudos

Nishant,

Uncomment that line, and place a Static break point "BREAK-POINT" before summing up

and try to dedug, you can identify what is happening...

MOVE VBRP-BRGEW TO V_TOTBRGEW.
BREAK-POINT.
V_GTOTBRGEW = V_GTOTBRGEW + V_TOTBRGEW.

Regards,

Surya

Former Member
0 Kudos

on setting up breakpoint

vbrp-brgew value is 0.200

V_GTOTBRGEW value is 613.200

former_member186055
Active Participant
0 Kudos

Nishant,

Break-point will trigger for each time ( for every EBELN & POSNR), you identified only the last value. Please check for all the values how it is summing.

Regards,

Surya

Former Member
0 Kudos

its not going into any loop,

please send me your email id will send you the complete driver program, since it is little big.

regards,

Nishant

former_member186055
Active Participant
0 Kudos

Nishant,

http://openid.sap.com/SuryaPraveen

Regards,

Surya

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks Surya for your help.