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

format change for amount in sapscript

Former Member
0 Likes
2,321

i've written a perform statement in sapscript to calculate:

1.) substraction of two amount values .

But in the perform statement the amount is in format 20.000,00 (for 20 thousand)

and hence it doesnot allow me to substract the two amounts and gives a dump stating not a number.

please tell me how can i convert the amount, substract the values and again send it back to sapscript for display.

also how can i print the sl. No. (Serial Number) which should get incremented everytime the line items r printed.

i can't change the program as it is standard so i've to do it through the sapscript only.

please help.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,354

Hi,

Do all the computation in the Zprogram you have associated to your script using Perform statement.

Convert characters to packed values using Unpack and Pack statements.

Use this sample code for reference


data: v_char1(13) type c value '1.613,000',
      v_char2(13) type c value '8.240,000'.
 
data: v_res type p decimals 0,
      v_flag1 type p decimals 0,
      v_flag2 type p decimals 0.
 
translate v_char1 using '. '.
translate v_char1 using ',.'.
condense v_char1 no-gaps.
 
translate v_char2 using '. '.
translate v_char2 using ',.'.
condense v_char2 no-gaps.
 
pack v_char1 to v_flag1.
pack v_char2 to v_flag2.
 
v_res = v_char1 + v_char2.
 
write v_res. "This contains packed value

You can unpack the packed value to character format again.

Regards,

Sailaja.

Message was edited by:

Sailaja N.L.

i've written a perform statement in sapscript to calculate:

1.) substraction of two amount values .

But in the perform statement the amount is in format 20.000,00 (for 20 thousand)

and hence it doesnot allow me to substract the two amounts and gives a dump stating not a number.

please tell me how can i convert the amount, substract the values and again send it back to sapscript for display.

also how can i print the sl. No. (Serial Number) which should get incremented everytime the line items r printed.

i can't change the program as it is standard so i've to do it through the sapscript only.

please help.

7 REPLIES 7
Read only

Former Member
0 Likes
1,355

Hi,

Do all the computation in the Zprogram you have associated to your script using Perform statement.

Convert characters to packed values using Unpack and Pack statements.

Use this sample code for reference


data: v_char1(13) type c value '1.613,000',
      v_char2(13) type c value '8.240,000'.
 
data: v_res type p decimals 0,
      v_flag1 type p decimals 0,
      v_flag2 type p decimals 0.
 
translate v_char1 using '. '.
translate v_char1 using ',.'.
condense v_char1 no-gaps.
 
translate v_char2 using '. '.
translate v_char2 using ',.'.
condense v_char2 no-gaps.
 
pack v_char1 to v_flag1.
pack v_char2 to v_flag2.
 
v_res = v_char1 + v_char2.
 
write v_res. "This contains packed value

You can unpack the packed value to character format again.

Regards,

Sailaja.

Message was edited by:

Sailaja N.L.

Read only

Former Member
0 Likes
1,354

i have one doubt that is print format it is not at all related to processing

please give ur script here i can solve ur problem

send ur subroutine code.

i hope that u are not converting it into integer format .

if u send any thing to perform it come in to character format.

you move in to integer format and do calculations and sent to script.

Message was edited by:

sunil kumar

Read only

Former Member
0 Likes
1,354

my code in sapscript is :

/: DEFINE &V1& = &REGUP-WRBTR&

/: DEFINE &V2& = &REGUP-WSKTO&

/: DEFINE &V3& = ''

/: PERFORM GET_DEDUCTION_VAL IN PROGRAM ZT_CHK

/: USING &V1&

/: USING &V2&

/: CHANGING &V3&

/: ENDPERFORM.

and the code that i've written in program zt_chk is:

Tables: REGUP.

FORM get_deduction_val TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

DATA : w_amt1 LIKE REGUP-WRBTR,

w_amt2 LIKE REGUP-WSKTO,

w_total LIKE REGUP-DMBTR.

READ TABLE in_tab WITH KEY 'V1'.

w_amt1 = in_tab-value.

READ TABLE in_tab WITH KEY 'V2'.

w_amt2 = in_tab-value.

w_total = w_amt1 - w_amt2. " -


>Gives Dump Here

READ TABLE out_tab WITH KEY 'V3'.

out_tab-value = w_amt1.

MODIFY out_tab INDEX sy-tabix.

ENDFORM.

Also i wld like to know how to print serial Number? is it possible through this perform. this perform gets called in loop and the next statement in sapscript prints the values.

Read only

0 Likes
1,354

Try to use

pack in_tab-value to w_amt1.

instead of

w_amt1 = in_tab-value.

Regards

Read only

learnsap
Active Participant
0 Likes
1,354

Hi Annie,

Change your User profile settings and see....

From any screen in SAP...

Click on Menu System->User Profile->Own Data, In that go to tab Own Data and change the decimal notation and save.

Now execute your script and see.

Correct me if I am wrong.

Regards,

Ramesh S

*Award points if reply is helpful

Read only

Former Member
0 Likes
1,354

Hello,

May be this might solve your problem. Move the variables in which you have the amounts to be computed to new variables declared as type compatible to amounts (i.e. BSEG-WRBTR o VBAP-NETWR). You have to use the 'MOVE' command with the extension 'Currency' i guess. This will automatically change the decimal notations of the amount variables in compatible to that of User settings. Then you can compute the values as you required and can use the same to display in the form / Script.

In this way you will not have to change the user settings all the time.

Hope this solves your issue.

Thanks and Regards,

Pavan

Read only

Former Member
0 Likes
1,354

i've tried all your suggestion but it doesnot work and every time a dump comes. in my user setting already the format 1,234,567.89 is maintained.

And i didn't find any move command with currency extension

please help.