cancel
Showing results for 
Search instead for 
Did you mean: 

Calculation in SAPscript

Former Member
0 Kudos

Hello ppl,

Currently the MAIN window of my SAPscript is coded as below:

/: IF condition = 'L'

/* Qty = &RESBD-MENGE(C)&

/: ENDIF

now i want to print it as

Qty = &RESBD-MENGE& minus &RESBD-DENMNG&.

Both the values are present in the sapscript at runtime.

How do i calculate this in sapscript and print the result?

Pls help.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hello David,

Add the code accordingly

/: DEFINE &TOTAL&

/: PERFORM GET_TOTAL IN PROGRAM Z101812_SCRIPT

/: USING &RESBD-MENGE&

/: USING &RESBD-DENMNG&.

/: CHANGING &TOTAL&

ENDPERFORM -


Add this in script

/*Total = &TOTAL&. -


delete this

ST &TOTAL&---ST is standard paragraph here

in report:

FORM get_total TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

data: MENGE type MENGE,

DENMNG type DENMNG,

total type total. "Give according types

loop at in_tab.

case in_tab-name

when 'MENGE'.

menge = in_tab-value.

when 'DENMNG'.

DENMNG = in_tab-value.

endcase.

endloop.

total = menge - DENMNG. " U can do any calculation

loop at out_tab.

case in_tab-name

when 'TOTAL'.

out_tab-value = TOTAL.

modify out_tab.

endcase.

endloop

ENDFORM. "get_total

Regards,

Subbu

Former Member
0 Kudos

Hi,

Use perform statement with using menge and denmng and changing qty as using and changing parameters respectively

declare qty field in your script using DEFINE

eg.

perform <performname> in program <prgname>

using &RESBD-MENGE&

using &RESBD-DENMNG&

changing &QTY&

in your form -- endform.

form <perform name> tables in_tab structure itcsy

out_tab structure itcsy

read table in_tab index 1.

w_menge = in_tab-value.

read table in_tab index 2.

w_denmng = in_tab-value.

w_qty = w_menge - w_denmng.

read table out_tab index 1.

move w_qty to out_tab-value.

modify out_tab.

endform.

display the qty field in your script.

regards

padma

Former Member
0 Kudos

Hello Padmavathi,

Thanks for the response.

When i declare the qty variable in sapscript using DEFINE, do we give any data type?

Thanks.

Former Member
0 Kudos

Hi,

No you dont give datatype...

check the syntax....

/: Define <&QTY&> ( = value )

you can give initial value or you can leave it.

regards

padma

Former Member
0 Kudos

Hi Padmavathi,

For the test purpose, i have written as below:

in sapscript:

/: DEFINE &TOTAL&

/: PERFORM GET_TOTAL IN PROGRAM Z101812_SCRIPT

/: USING &WA_EKPO-NETPR&

/: CHANGING &TOTAL&

  • Total = &TOTAL&.

in report:

FORM get_total TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

data: price type vbap-netwr,

total type vbap-netwr.

read table in_tab index 1.

price = in_tab-value.

total = price + 10.

read table out_tab index 1.

move total to out_tab-value.

modify out_tab.

ENDFORM. "get_total

But, the total is not being printed.

Can you pls help me find out the reason?

Thanks.

Former Member
0 Kudos

Hi,

the code is correct

I assume that the variable you are passing in the using parameter is in the workarea....

Did you display the &total& field in your text editor?

if yes then check if the program and script are activated or not and check

regards

padma

JozsefSzikszai
Active Contributor
0 Kudos

hi David,

the calculation has to be done in the Print Program, you cannot do that in the SAPScript!

hope this helps

ec

Former Member
0 Kudos

Hi,

In the same window, Assign the dynamci values to another fields, after that do the calculation, after display result.

regards

jana