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

Sapscript multiply two fields

Former Member
0 Likes
1,219

Hello,

Someone could help me please, someones knows how to multiply two fields in sapscript, what's the sintax?

thanks for your help,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
905

Hello Enrique,

You need Call Perform block for calculation purpose by making use of parameters.

example:

If you want multiply qty and price then you pass Qty and Price value and along with storage variable for the output to the program.

syntax:

v_qty for Qty

v_price for price

v_temp for storage the output

ztest is the calling program where you will your logic 

PERFORM GET_PRODUCT IN PROGRAM ZTEST using &v_qty& using &price& changing &v_temp&

endperform

in the program  ZTEST

ITCSY is the structure which contains the name field and value field.

form GET_PRODUCT TABLES IN_PAR STRUCTURE ITCSY

                                                  OUT_PAR STRUCTURE ITCSY.

declare the variable for qty  price and temp variable for storing the product inside the subroutine.

READ TABLE IN_PAR WITH KEY 'V_QTY'.

if sy-subrc eq 0

qty = IN_PAR-VALUE

endif

READ TABLE IN_PAR WITH KEY 'V_PRICE'.

if sy-subrc eq 0

price = IN_PAR-VALUE

endif

temp = price * qty.

READ TABLE OUT_PAR WITH KEY 'V_temp'.

if sy-subrc eq 0

OUT_PAR-VALUE = temp.

modify OUT_PAR index sy-tabix.

endif

endform.

If you have any queries please let me know.

5 REPLIES 5
Read only

siva_subramanian2
Participant
0 Likes
905

Hi Enrique,

Use Perform ....Endperform statement and try to multiply it in a subroutine program and then pass it to script by changing parameters and use that in your Script.

Thanks,

Siva.A

Read only

Former Member
0 Likes
906

Hello Enrique,

You need Call Perform block for calculation purpose by making use of parameters.

example:

If you want multiply qty and price then you pass Qty and Price value and along with storage variable for the output to the program.

syntax:

v_qty for Qty

v_price for price

v_temp for storage the output

ztest is the calling program where you will your logic 

PERFORM GET_PRODUCT IN PROGRAM ZTEST using &v_qty& using &price& changing &v_temp&

endperform

in the program  ZTEST

ITCSY is the structure which contains the name field and value field.

form GET_PRODUCT TABLES IN_PAR STRUCTURE ITCSY

                                                  OUT_PAR STRUCTURE ITCSY.

declare the variable for qty  price and temp variable for storing the product inside the subroutine.

READ TABLE IN_PAR WITH KEY 'V_QTY'.

if sy-subrc eq 0

qty = IN_PAR-VALUE

endif

READ TABLE IN_PAR WITH KEY 'V_PRICE'.

if sy-subrc eq 0

price = IN_PAR-VALUE

endif

temp = price * qty.

READ TABLE OUT_PAR WITH KEY 'V_temp'.

if sy-subrc eq 0

OUT_PAR-VALUE = temp.

modify OUT_PAR index sy-tabix.

endif

endform.

If you have any queries please let me know.

Read only

0 Likes
905

Madhu, Excellent help, It Works, thanks so much for sharing.

Read only

Former Member
0 Likes
905

This message was moderated.

Read only

Private_Member_7726
Active Contributor
0 Likes
905

Hi,

suppose i found a way to mount and format a disc "in SapScript" - would it still be a sensible idea to try to do so..? Calculations are of course entirely different "animals", but still - why does the driver programm need to go to SapScript to perform a calculation (or even perform it itself), why can't the data preparation logic be independent of SapScript and the driver programm (ideally built in such a way, that it can easily be reused in a Print Workbench Form Class)? That way, should somebody someday wish to replace SapScripts with something else, you have one less concern...

cheers,

Janis