‎2008 Oct 27 3:46 PM
Hi Experts,
I must make negative a P type variable, how can I do it? I tried to multiplying by -1 but it doesn't work, when i run the program there is a runtime error.
Thankyou.
Cris.
‎2008 Oct 27 3:53 PM
I don't see the problem. Try this.
data: val type p VALUE '-2',
val2 type p VALUE -2.
res type p.
res = val2 - val.
write: res.
The result is 0 = -2 - (-2)
‎2008 Oct 27 3:50 PM
check this..
data: a type p decimals 2.
a = '10.00'.
a = a * -1.
write a .it is working for me.
‎2008 Oct 27 3:50 PM
I tried this code: it works fine
data: lv_p type p DECIMALS 2 value '3.44'.
lv_p = lv_p * ( -1 ). "space between ( and -
WRITE:/ 'lv_p:', lv_p.
‎2008 Oct 27 3:52 PM
Yep, that is how you would make it negative. You should be able to see this in debug mode. I guess you may be getting this error when your screen is thrown? If so, you need to make sure to modify your screen field to handle the - sign. So go to screen painter. Click on the "element list" tab, then click on the "Texts/ I/O Templates" Tab. FInd your field in the list, now in the column labeled as "Text or I/O Field, you should see underscores, simply add a "V" at the end of this. So you should have something like this _______________V in that field. Save and activate, and try your program again. The "V" is a placeholder for the sign.
Regards,
Rich Heilman
‎2008 Oct 27 3:52 PM
‎2008 Oct 27 3:53 PM
I don't see the problem. Try this.
data: val type p VALUE '-2',
val2 type p VALUE -2.
res type p.
res = val2 - val.
write: res.
The result is 0 = -2 - (-2)
‎2008 Oct 27 4:30 PM
Hi,
Firs of all, thank you for all your quick answers. Well, really I am working with BW, and I have a program to extract data from a table to another table making some transformations in the fields of the source table and save it in the fields of the target table. One of this transformations is to make negative a field with type QUAN that has a lenght of 17 and 3 decimals. I read somewhere that in a program the type QUAN is treated like the type P. I have this (more or less )
"Internal table and work area for the source table.
DATA: it_dm TYPE STANDARD TABLE /bic/ohcfm_r_dm,
wa_dm LIKE LINE OF it_dm.
"Internal table and work area for the target table
DATA: it_ext_dm TYPE STANDARD TABLE ycfm_t_dm,
wa_ext_dm LIKE LINE OF it_ext_dm
"select of the source table
SELECT * FROM /bic/ohcfm_r_dm into table it_dm.
"loop the internal table
LOOP AT it_dm INTO wa_dm.
wa_ext_dm-dias_decalaje = wa_dm-/dias_decalaje * ( -1 ).
...
ENDLOOP.
...
The field dias_decalaje has QUAN type.
Thank you.
Cris.
‎2008 Oct 27 4:41 PM
wa_ext_dm-dias_decalaje = wa_dm-/dias_decalaje * ( -1 ).create a temp variable and move the temp to final wa_ext_dm-dias_decalaje
data: lv_temp type p decimal 3.
lv_temp = wa_dm-/dias_decalaje * ( -1 )
move lv_temp to wa_ext_dm-dias_decalaje.
‎2008 Oct 27 4:43 PM
Hello,
I'd seen that the problem is the type of the field in the target table, it is a INT1, and the result of multiply the field by -1 is bigger than the type INT1, of course.
I must talk about this with my technical designer.
Thank you all.